Skip to content

Commit

Permalink
add Layout Management Provider to sample apps (#917)
Browse files Browse the repository at this point in the history
* add Layout Management Provider to sample apps

* fix test dependencies
  • Loading branch information
heswell authored Oct 18, 2023
1 parent b09a523 commit 09ea1af
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 260 deletions.
7 changes: 4 additions & 3 deletions vuu-ui/packages/vuu-layout/src/layout-persistence/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './LayoutPersistenceManager';
export * from './LocalLayoutPersistenceManager';
export * from './data';
export * from "./data";
export * from "./LayoutPersistenceManager";
export * from "./LocalLayoutPersistenceManager";
export * from "./useLayoutContextMenuItems";
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
LayoutMetadata,
SaveLayoutPanel,
useLayoutManager,
} from "@finos/vuu-shell";
import {
ContextMenuItemDescriptor,
MenuActionHandler,
MenuBuilder,
} from "@finos/vuu-data-types";
import { ReactElement, useCallback, useMemo, useState } from "react";
import { MenuActionClosePopup } from "@finos/vuu-popups";

export const useLayoutContextMenuItems = () => {
const [dialogContent, setDialogContent] = useState<ReactElement>();

const { saveLayout } = useLayoutManager();

const handleCloseDialog = useCallback(() => {
setDialogContent(undefined);
}, []);

const handleSave = useCallback(
(layoutMetadata: Omit<LayoutMetadata, "id">) => {
saveLayout(layoutMetadata);
setDialogContent(undefined);
},
[saveLayout]
);

const [buildMenuOptions, handleMenuAction] = useMemo<
[MenuBuilder, MenuActionHandler]
>(() => {
return [
(location, options) => {
console.log({ options });
const locations = location.split(" ");
const menuDescriptors: ContextMenuItemDescriptor[] = [];
if (locations.includes("main-tab")) {
menuDescriptors.push(
{
label: "Save Layout",
action: "save-layout",
options,
},
{
label: "Layout Settings",
action: "layout-settings",
options,
}
);
}
return menuDescriptors;
},
(action: MenuActionClosePopup) => {
console.log("menu action", {
action,
});
if (action.menuId === "save-layout") {
setDialogContent(
<SaveLayoutPanel
onCancel={handleCloseDialog}
onSave={handleSave}
componentId={action.options.controlledComponentId}
/>
);
return true;
}
return false;
},
];
}, [handleCloseDialog, handleSave]);

return {
buildMenuOptions,
dialogContent,
handleCloseDialog,
handleMenuAction,
};
};
23 changes: 23 additions & 0 deletions vuu-ui/packages/vuu-layout/test/global-mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { vi } from "vitest";

const BlobMock = vi.fn(() => ({}));
const URLMock = {
createObjectURL: () => ({}),
};
vi.stubGlobal("Blob", BlobMock);
vi.stubGlobal("URL", URLMock);
vi.stubGlobal("loggingSettings", { loggingLevel: "error" });

vi.mock("@finos/vuu-utils", async () => {
const actual = await vi.importActual("@finos/vuu-utils");
return {
// @ts-ignore
...actual,
uuid: () => "uuid-1",
};
});

vi.mock("./inlined-worker", async () => ({
workerSourceCode: "",
}));
Loading

0 comments on commit 09ea1af

Please sign in to comment.