Skip to content

Commit

Permalink
Wiring up of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
travjenkins committed Oct 10, 2023
1 parent 597cbaf commit bdc206a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/components/editor/Bindings/Filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import defaultRenderers from 'services/jsonforms/defaultRenderers';
import { defaultOptions, showValidation } from 'services/jsonforms/shared';
import {
useResourceConfig_fullSourceOfCollectionProperty,
useResourceConfig_updateFullSourceErrors,
useResourceConfig_updateFullSourceProperty,
} from 'stores/ResourceConfig/hooks';

Expand All @@ -23,6 +24,7 @@ function Filters({ collectionName }: Props) {

const updateFullSourceProperty =
useResourceConfig_updateFullSourceProperty();
const updateFullSourceErrors = useResourceConfig_updateFullSourceErrors();

const notBefore = useResourceConfig_fullSourceOfCollectionProperty(
collectionName,
Expand Down Expand Up @@ -112,6 +114,10 @@ function Filters({ collectionName }: Props) {
'notAfter',
state.data.notAfter
);
updateFullSourceErrors(
collectionName,
state.errors
);
}}
/>
</StyledEngineProvider>
Expand Down
1 change: 1 addition & 0 deletions src/lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ const EntityCreate: ResolvedIntlConfig['messages'] = {
'entityCreate.endpointConfig.endpointConfigMissing': `${endpointConfigHeader} empty`,
'entityCreate.endpointConfig.collectionsMissing': `${CommonMessages['terms.collections']} missing`,
'entityCreate.endpointConfig.resourceConfigInvalid': `Resource Config invalid`,
'entityCreate.endpointConfig.timeTravelInvalid': `Time Travel invalid`,

'entityCreate.endpointConfig.configCanBeBlank.message': `This {entityType} requires no configuration.`,

Expand Down
21 changes: 20 additions & 1 deletion src/stores/ResourceConfig/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ const populateResourceConfigErrors = (

if (hasConfigs) {
map(resourceConfig, (config) => {
const { errors } = config;
const { errors, fullSourceErrors } = config;

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (errors && errors.length > 0) {
resourceConfigErrors = resourceConfigErrors.concat(errors);
}

if (fullSourceErrors && fullSourceErrors.length > 0) {
resourceConfigErrors =
resourceConfigErrors.concat(fullSourceErrors);
}
});
} else {
// TODO (errors) Need to populate this object with something?
Expand Down Expand Up @@ -442,6 +447,20 @@ const getInitialState = (
);
},

updateFullSourceErrors: (collectionName, errors) => {
set(
produce((state: ResourceConfigState) => {
const configToUpdate = state.resourceConfig[collectionName];

configToUpdate.fullSourceErrors = errors;

populateResourceConfigErrors(state.resourceConfig, state);
}),
false,
'Updating Full Source Error'
);
},

setResourceConfig: (key, value, disableCheckingErrors, disableOmit) => {
set(
produce((state: ResourceConfigState) => {
Expand Down
10 changes: 10 additions & 0 deletions src/stores/ResourceConfig/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ export const useResourceConfig_updateFullSourceProperty = () => {
);
};

export const useResourceConfig_updateFullSourceErrors = () => {
return useZustandStore<
ResourceConfigState,
ResourceConfigState['updateFullSourceErrors']
>(
ResourceConfigStoreNames.GENERAL,
(state) => state.updateFullSourceErrors
);
};

export const useResourceConfig_resetResourceConfigAndCollections = () => {
return useZustandStore<
ResourceConfigState,
Expand Down
2 changes: 2 additions & 0 deletions src/stores/ResourceConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ResourceConfig extends JsonFormsData {
errors: any[];
disable?: boolean;
fullSource?: FullSource;
fullSourceErrors?: any[];
}

export interface ResourceConfigDictionary {
Expand Down Expand Up @@ -74,6 +75,7 @@ export interface ResourceConfigState {
key: string,
value: FilterProperties | null
) => void;
updateFullSourceErrors: (collection: string, errors?: any[]) => void;

// Resource Schema
resourceSchema: Schema;
Expand Down

0 comments on commit bdc206a

Please sign in to comment.