Skip to content

Commit

Permalink
Add RJST (React JSON Schema Table) component
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
JSReds committed Jan 14, 2025
1 parent fa1bfec commit bd4b782
Show file tree
Hide file tree
Showing 71 changed files with 8,902 additions and 56 deletions.
188 changes: 148 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
"@rjsf/mui": "^5.13.0",
"@rjsf/utils": "^5.13.0",
"@rjsf/validator-ajv8": "^5.13.4",
"ajv": "^8.12.0",
"ajv-formats": "^3.0.1",
"ajv-keywords": "^5.1.0",
"analytics-client": "^2.0.1",
"color": "^4.2.3",
"color-hash": "^2.0.2",
"date-fns": "^4.1.0",
"lodash": "^4.17.21",
"notistack": "^3.0.1",
"react": "^18.2.0",
Expand Down
39 changes: 39 additions & 0 deletions src/components/RJST/Actions/ActionContent.tsx
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;
};
Loading

0 comments on commit bd4b782

Please sign in to comment.