Skip to content

Commit

Permalink
Merge pull request #58 from ScottLogic/VUU-47-link-layoutProvider-and…
Browse files Browse the repository at this point in the history
…-layoutManagerProvider

Vuu 47 link layout provider and layout manager provider
  • Loading branch information
vferraro-scottlogic authored Oct 10, 2023
2 parents dfacb9c + aca2050 commit 3d9b958
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 295 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ yarn-debug.log*
yarn-error.log*

/vuu-ui/showcase/src/examples/**/*.js
/vuu-ui/cypress/screenshots

deployed_apps
dist
Expand Down
2 changes: 1 addition & 1 deletion vuu-ui/cypress/e2e/layout-management/screenshot.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ context("Screenshot", () => {
// TODO (#VUU24): Improve test alignment with the user flow
it("Takes a screenshot of the current layout and displays it in the save layout dialog", () => {
// TODO (#VUU24): Improve selector
cy.findByRole("tab", { name: "My Instruments" }).then((tab) => {
cy.get("#tab1-tab").then((tab) => {
cy.wrap(tab).findByRole("button").click();
});

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ export interface LayoutPersistenceManager {
* @returns an array of all persisted layout metadata
*/
loadMetadata: () => Promise<LayoutMetadata[]>;

/**
* Retrieves the application layout which includes all layouts on screen
*
* @returns Full JSON representation of the application layout
*/
loadApplicationLayout: () => Promise<LayoutJSON>;

/**
* Saves the application layout which includes all layouts on screen
*
* @param layout - Full JSON representation of the application layout to be saved
*/
saveApplicationLayout: (layout: LayoutJSON) => Promise<void>
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Layout, LayoutMetadata, WithId } from "@finos/vuu-shell";
import { LayoutJSON, LayoutPersistenceManager } from "@finos/vuu-layout";

import { getLocalEntity, saveLocalEntity } from "@finos/vuu-filters";
import { getUniqueId } from "@finos/vuu-utils";

import { defaultLayout } from "./data";

const metadataSaveLocation = "layouts/metadata";
const layoutsSaveLocation = "layouts/layouts";

Expand Down Expand Up @@ -72,10 +73,32 @@ export class LocalLayoutPersistenceManager implements LayoutPersistenceManager {
}

loadMetadata(): Promise<LayoutMetadata[]> {
return new Promise(resolve => {
return new Promise((resolve) => {
const metadata = getLocalEntity<LayoutMetadata[]>(metadataSaveLocation);
resolve(metadata || []);
})
});
}

loadApplicationLayout(): Promise<LayoutJSON> {
return new Promise((resolve) => {
const applicationLayout = getLocalEntity<LayoutJSON>("api/vui");
if (applicationLayout) {
resolve(applicationLayout);
} else {
resolve(defaultLayout);
}
});
}

saveApplicationLayout(layout: LayoutJSON): Promise<void> {
return new Promise((resolve, reject) => {
const savedLayout = saveLocalEntity<LayoutJSON>("api/vui", layout);
if (savedLayout) {
resolve();
} else {
reject(new Error("Layout failed to save"));
}
});
}

private loadLayouts(): Promise<Layout[]> {
Expand Down
52 changes: 40 additions & 12 deletions vuu-ui/packages/vuu-layout/src/layout-persistence/data.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
export const warningLayout = {
type: "View",
props: {
style: { height: "calc(100% - 6px)" },
import { LayoutJSON } from "../layout-reducer";

export const warningLayout: LayoutJSON = {
type: "View",
props: {
style: { height: "calc(100% - 6px)" },
},
children: [
{
props: {
className: "vuuShell-warningPlaceholder",
},
type: "Placeholder",
},
],
};

export const defaultLayout: LayoutJSON = {
type: "Stack",
id: "main-tabs",
props: {
className: "vuuShell-mainTabs",
TabstripProps: {
allowAddTab: true,
allowRenameTab: true,
animateSelectionThumb: false,
location: "main-tab",
allowCloseTab: true
},
children: [
{
props: {
className: "vuuShell-warningPlaceholder",
},
type: "Placeholder",
preserve: true,
active: 0,
},
children: [
{
props: {
id: "tab1",
className: "vuuShell-Placeholder",
},
],
};
type: "Placeholder",
},
],
};
1 change: 1 addition & 0 deletions vuu-ui/packages/vuu-layout/src/layout-persistence/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './LayoutPersistenceManager';
export * from './LocalLayoutPersistenceManager';
export * from './data';
3 changes: 2 additions & 1 deletion vuu-ui/packages/vuu-layout/src/layout-reducer/layoutTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ReactElement } from "react";
import { CSSProperties, ReactElement } from "react";
import { DragDropRect, DragInstructions } from "../drag-drop";
import { DropTarget } from "../drag-drop/DropTarget";
import { ContributionLocation } from "../layout-view";
Expand All @@ -26,6 +26,7 @@ export interface LayoutJSON extends WithType {
props?: { [key: string]: any };
state?: any;
type: string;
style?: CSSProperties;
}

export interface WithActive {
Expand Down
1 change: 0 additions & 1 deletion vuu-ui/packages/vuu-shell/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./connection-status";
export * from "./density-switch";
export * from "./feature";
export * from "./layout-config";
export * from "./layout-management";
export * from "./left-nav";
export * from "./login";
Expand Down
1 change: 0 additions & 1 deletion vuu-ui/packages/vuu-shell/src/layout-config/index.ts

This file was deleted.

39 changes: 0 additions & 39 deletions vuu-ui/packages/vuu-shell/src/layout-config/local-config.ts

This file was deleted.

50 changes: 0 additions & 50 deletions vuu-ui/packages/vuu-shell/src/layout-config/remote-config.ts

This file was deleted.

61 changes: 0 additions & 61 deletions vuu-ui/packages/vuu-shell/src/layout-config/use-layout-config.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.vuuLayoutList {
align-self: stretch;
height: 100%;
overflow: hidden;
}

.vuuLayoutList-header {
Expand Down
26 changes: 13 additions & 13 deletions vuu-ui/packages/vuu-shell/src/layout-management/LayoutList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ type LayoutGroups = {
const classBase = "vuuLayoutList";

export const LayoutsList = (props: HTMLAttributes<HTMLDivElement>) => {
const { layoutMetadata } = useLayoutManager();
const { layoutMetadata, loadLayoutById } = useLayoutManager();

const handleLoadLayout = (layoutId?: string) => {
// TODO load layout
console.log("loading layout with id", layoutId)
console.log("json:", layoutMetadata.find(metadata => metadata.id === layoutId))
if (layoutId) {
loadLayoutById(layoutId)
}
}

const layoutsByGroup = layoutMetadata.reduce((acc: LayoutGroups, cur) => {
Expand All @@ -39,12 +39,12 @@ export const LayoutsList = (props: HTMLAttributes<HTMLDivElement>) => {
<List<[string, LayoutMetadata[]]>
height='fit-content'
source={Object.entries(layoutsByGroup)}
ListItem={({ item }) => <>
<div className={`${classBase}-groupName`}>{item?.[0]}</div>
<List<LayoutMetadata>
height='fit-content'
source={item?.[1]}
ListItem={({ item: layout }) =>
ListItem={({ item }) => {
if (!item) return <></>
const [groupName, layouts] = item
return <>
<div className={`${classBase}-groupName`}>{groupName}</div>
{layouts.map(layout =>
<div
className={`${classBase}-layoutContainer`}
key={layout?.id}
Expand All @@ -58,9 +58,9 @@ export const LayoutsList = (props: HTMLAttributes<HTMLDivElement>) => {
</div>
</div>
</div>
}
/>
</>
)}
</>
}
}
/>
</div>
Expand Down
Loading

0 comments on commit 3d9b958

Please sign in to comment.