-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RJST (React JSON Schema Table) component
Change-type: minor
- Loading branch information
Showing
71 changed files
with
8,902 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,39 @@ | ||
import type { CheckedState } from '../components/Table/utils'; | ||
import type { RJSTAction } from '../schemaOps'; | ||
import { useQuery } from 'react-query'; | ||
|
||
export const LOADING_DISABLED_REASON = 'Loading'; | ||
|
||
interface ActionContentProps<T> { | ||
action: RJSTAction<T>; | ||
affectedEntries: T[] | undefined; | ||
checkedState?: CheckedState; | ||
getDisabledReason: RJSTAction<T>['isDisabled']; | ||
onDisabledReady: (arg: string | null) => void; | ||
} | ||
|
||
// This component sole purpose is to have the useQuery being called exactly once per item, | ||
// so that it satisfies React hooks assumption that the number of hook calls inside each component | ||
// stays the same across renders. | ||
export const ActionContent = <T extends object>({ | ||
action, | ||
children, | ||
affectedEntries, | ||
checkedState, | ||
getDisabledReason, | ||
onDisabledReady, | ||
}: React.PropsWithChildren<ActionContentProps<T>>) => { | ||
useQuery({ | ||
queryKey: ['actionContent', action.title, affectedEntries, checkedState], | ||
queryFn: async () => { | ||
const disabled = | ||
(await getDisabledReason?.({ | ||
affectedEntries, | ||
checkedState, | ||
})) ?? null; | ||
onDisabledReady(disabled); | ||
return disabled; | ||
}, | ||
}); | ||
return children; | ||
}; |
Oops, something went wrong.