-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5886 from marmelab/reference-array-input-list-con…
…text Add ListContext to ReferenceArrayInput
- Loading branch information
Showing
13 changed files
with
877 additions
and
306 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
29 changes: 29 additions & 0 deletions
29
packages/ra-core/src/controller/input/ReferenceArrayInputContext.ts
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,29 @@ | ||
import { createContext } from 'react'; | ||
import { PaginationPayload, Record, SortPayload } from '../../types'; | ||
|
||
/** | ||
* Context which provides access to the useReferenceArrayInput features. | ||
* | ||
* @example | ||
* const ReferenceArrayInput = ({ children }) => { | ||
* const controllerProps = useReferenceArrayInputController(); | ||
* return ( | ||
* <ReferenceArrayInputContextProvider value={controllerProps}> | ||
* {children} | ||
* </ReferenceArrayInputContextProvider> | ||
* ) | ||
* } | ||
*/ | ||
export const ReferenceArrayInputContext = createContext(undefined); | ||
|
||
export interface ReferenceArrayInputContextValue { | ||
choices: Record[]; | ||
error?: any; | ||
warning?: any; | ||
loading: boolean; | ||
loaded: boolean; | ||
setFilter: (filter: any) => void; | ||
setPagination: (pagination: PaginationPayload) => void; | ||
setSort: (sort: SortPayload) => void; | ||
setSortForList: (sort: string, order?: string) => void; | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/ra-core/src/controller/input/ReferenceArrayInputContextProvider.tsx
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,31 @@ | ||
import * as React from 'react'; | ||
import { ReactNode } from 'react'; | ||
import { | ||
ReferenceArrayInputContext, | ||
ReferenceArrayInputContextValue, | ||
} from './ReferenceArrayInputContext'; | ||
|
||
/** | ||
* Provider for the context which provides access to the useReferenceArrayInput features. | ||
* | ||
* @example | ||
* const ReferenceArrayInput = ({ children }) => { | ||
* const controllerProps = useReferenceArrayInputController(); | ||
* return ( | ||
* <ReferenceArrayInputContextProvider value={controllerProps}> | ||
* {children} | ||
* </ReferenceArrayInputContextProvider> | ||
* ) | ||
* } | ||
*/ | ||
export const ReferenceArrayInputContextProvider = ({ | ||
children, | ||
value, | ||
}: { | ||
children: ReactNode; | ||
value: ReferenceArrayInputContextValue; | ||
}) => ( | ||
<ReferenceArrayInputContext.Provider value={value}> | ||
{children} | ||
</ReferenceArrayInputContext.Provider> | ||
); |
Oops, something went wrong.