Skip to content

Commit

Permalink
Implement menu option close functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
SorexBentley committed Dec 5, 2023
1 parent 77e9241 commit ff9b08f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ export const useIModelTableConfig = ({
disableSortBy: true,
maxWidth: 50,
Cell: (props: CellProps<IModelFull>) => {
const moreOptions = () => {
const moreOptions = (close: () => void) => {
const options = _buildManagedContextMenuOptions(
iModelActions,
props.row.original
props.row.original,
close
);
return options !== undefined ? options : [];
};
Expand Down
21 changes: 15 additions & 6 deletions packages/modules/imodel-browser/src/utils/_buildMenuOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ export interface ContextMenuBuilderItem<T = any>
extends Omit<MenuItemProps, "onClick" | "value"> {
key: string;
visible?: boolean | ((value: T) => boolean);
onClick?: ((value?: unknown) => void) | undefined;
onClick?: (value: T, closeMenu?: () => void) => void | undefined;
}

/** Build MenuItem array for the value for each provided options
* @private
*/
export const _buildManagedContextMenuOptions: <T>(
options: ContextMenuBuilderItem<T>[] | undefined,
value: T
) => JSX.Element[] | undefined = (options, value) =>
options
value: T,
closeMenu?: () => void
) => JSX.Element[] | undefined = (options, value, closeMenu) => {
return options
?.filter?.(({ visible }) => {
return typeof visible === "function" ? visible(value) : visible ?? true;
})
.map(({ key, visible, ...contextMenuProps }) => {
return <MenuItem {...contextMenuProps} key={key} value={value} />;
.map(({ key, visible, onClick, ...contextMenuProps }) => {
return (
<MenuItem
{...contextMenuProps}
onClick={() => onClick?.(value, closeMenu)}
key={key}
value={value}
/>
);
});
};

0 comments on commit ff9b08f

Please sign in to comment.