Skip to content

Commit

Permalink
Merge pull request #83 from balena-io-modules/fix-disabled-typing
Browse files Browse the repository at this point in the history
Adapt isDisabled typing
  • Loading branch information
flowzone-app[bot] committed Apr 8, 2024
2 parents cee6bc2 + 8cf3e56 commit 5efee53
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"README.md"
],
"dependencies": {
"@balena/ui-shared-components": "^5.0.0",
"@balena/ui-shared-components": "^5.0.8",
"json-e": "^4.4.3",
"lodash": "^4.17.21",
"qs": "^6.10.3",
Expand Down
11 changes: 6 additions & 5 deletions src/AutoUI/Actions/ActionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface ActionContentProps<T> {
affectedEntries: T[] | undefined;
checkedState: CheckedState | undefined;
getDisabledReason: AutoUIAction<T>['isDisabled'];
onDisabledReady: (arg: string | undefined) => void;
onDisabledReady: (arg: string | null) => void;
}

// This component sole purpose is to have the useRequest being called exactly once per item,
Expand All @@ -23,10 +23,11 @@ export const ActionContent = <T extends {}>({
}: ActionContentProps<T>) => {
useRequest(
async () => {
const disabled = await getDisabledReason?.({
affectedEntries,
checkedState,
});
const disabled =
(await getDisabledReason?.({
affectedEntries,
checkedState,
})) ?? null;
onDisabledReady(disabled);
return disabled;
},
Expand Down
2 changes: 1 addition & 1 deletion src/AutoUI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export const AutoUI = <T extends AutoUIBaseResource<T>>({
);
},
isDisabled: async ({ affectedEntries, checkedState }) =>
getTagsDisabledReason(
await getTagsDisabledReason(
affectedEntries,
tagField as keyof T,
checkedState,
Expand Down
2 changes: 1 addition & 1 deletion src/AutoUI/schemaOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface AutoUIAction<T> {
affectedEntries: T[] | undefined;
/** checkState can be undefined only for entity case, since card does not have a selection event */
checkedState: CheckedState | undefined;
}) => MaybePromise<string | undefined>;
}) => MaybePromise<string | null>;
isDangerous?: boolean;
}

Expand Down
1 change: 1 addition & 0 deletions src/AutoUI/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const getTagsDisabledReason = async <T extends AutoUIBaseResource<T>>(
// TODO: Pass the resource name instead.
return t('info.edit_tag_no_permissions', { resource: 'item' });
}
return null;
};

export const getCreateDisabledReason = <T extends AutoUIBaseResource<T>>(
Expand Down

0 comments on commit 5efee53

Please sign in to comment.