Skip to content

Commit

Permalink
Infer additional item fields in BlocksBlock and ListBlock (vivid-…
Browse files Browse the repository at this point in the history
…planet#1481)

Additional fields in the `item` prop of `AdditionalItemContextMenuItems`
and `AdditionalItemContent` will be typed correctly if the
`additionalItemFields` option is strongly typed.
  • Loading branch information
johnnyomair authored and VP-DS committed Jan 12, 2024
1 parent bdb827a commit 2c5b097
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 151 deletions.
7 changes: 7 additions & 0 deletions .changeset/silly-lemons-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/blocks-admin": patch
---

Infer additional item fields in `BlocksBlock` and `ListBlock`

Additional fields in the `item` prop of `AdditionalItemContextMenuItems` and `AdditionalItemContent` will be typed correctly if the `additionalItemFields` option is strongly typed.
4 changes: 0 additions & 4 deletions demo/admin/src/common/blocks/LinkListBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ export const LinkListBlock = createListBlock({
...userGroupAdditionalItemFields,
},
AdditionalItemContextMenuItems: ({ item, onChange, onMenuClose }) => {
// TODO fix typing: infer additional fields somehow
// @ts-expect-error missing additional field
return <UserGroupContextMenuItem item={item} onChange={onChange} onMenuClose={onMenuClose} />;
},
AdditionalItemContent: ({ item }) => {
// TODO fix typing: infer additional fields somehow
// @ts-expect-error missing additional field
return <UserGroupChip item={item} />;
},
});
4 changes: 0 additions & 4 deletions demo/admin/src/pages/PageContentBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@ export const PageContentBlock = createBlocksBlock({
...userGroupAdditionalItemFields,
},
AdditionalItemContextMenuItems: ({ item, onChange, onMenuClose }) => {
// TODO fix typing: infer additional fields somehow
// @ts-expect-error missing additional field
return <UserGroupContextMenuItem item={item} onChange={onChange} onMenuClose={onMenuClose} />;
},
AdditionalItemContent: ({ item }) => {
// TODO fix typing: infer additional fields somehow
// @ts-expect-error missing additional field
return <UserGroupChip item={item} />;
},
});
4 changes: 3 additions & 1 deletion demo/admin/src/userGroups/userGroupAdditionalItemFields.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { GQLUserGroup } from "@src/graphql.generated";

const userGroupAdditionalItemFields = {
userGroup: {
defaultValue: "All",
defaultValue: "All" as GQLUserGroup,
},
};

Expand Down
Loading

0 comments on commit 2c5b097

Please sign in to comment.