-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Controlled filters from labels picking
- Loading branch information
1 parent
bf7b634
commit be2a91e
Showing
6 changed files
with
91 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from "react"; | ||
import ContributionsTable from "@/components/contributions-table/table"; | ||
import Toolbar from "@/components/filters/toolbar"; | ||
import { FiltersProvider } from "@/contexts/filters"; | ||
import { containerStyle } from "@/styles"; | ||
import { PaginatedCustomDataResponse } from "@/types"; | ||
import { Contribution } from "@/types/contribution"; | ||
import { SearchParams } from "@/types/filters"; | ||
|
||
interface IControlledTableProps { | ||
filter: any; | ||
items: PaginatedCustomDataResponse<Contribution>; | ||
searchParams: SearchParams; | ||
} | ||
const ControlledTable = ({ | ||
filter, | ||
items, | ||
searchParams, | ||
}: IControlledTableProps) => { | ||
return ( | ||
<FiltersProvider initialParams={searchParams}> | ||
<div className="flex flex-col"> | ||
<Toolbar searchParams={searchParams} /> | ||
<section className={containerStyle}> | ||
<ContributionsTable | ||
items={items} | ||
queries={{ | ||
page_size: 10, | ||
filter, | ||
}} | ||
/> | ||
</section> | ||
</div> | ||
</FiltersProvider> | ||
); | ||
}; | ||
|
||
export default ControlledTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use client"; | ||
|
||
import { | ||
IConfigProps, | ||
IFiltersContext, | ||
useFilters as filtersHook, | ||
} from "@/hooks/useFilters"; | ||
import { provideContext } from "@/utils/providers"; | ||
|
||
export const [FiltersProvider, useFilters] = provideContext< | ||
IConfigProps, | ||
IFiltersContext | ||
>(filtersHook); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { FC, ReactNode } from "react"; | ||
import { createContext, useContext } from "react"; | ||
|
||
// This utility generates a context provider from a react hook passed as argument | ||
// Returns an array containing the provider and the consumer hook | ||
export const provideContext = <P, T>(useProviderContext: (props: P) => T) => { | ||
// automatic typing based on our hook's return type | ||
type ContextType = ReturnType<typeof useProviderContext>; | ||
type ProviderProps = P & { children?: ReactNode }; | ||
type ProviderType = FC<ProviderProps>; | ||
|
||
const Context = createContext({} as ContextType); | ||
|
||
const Provider: ProviderType = ({ children, ...props }: ProviderProps) => { | ||
const ctx = useProviderContext(props as P); | ||
|
||
return <Context.Provider value={ctx}>{children}</Context.Provider>; | ||
}; | ||
|
||
const useProvidedContext = () => useContext(Context); | ||
|
||
return [Provider, useProvidedContext] as [ProviderType, () => ContextType]; | ||
}; |