forked from finos/vuu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ScottLogic/finos-vuu into s…
…ync-SL-main
- Loading branch information
Showing
16 changed files
with
176 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
vuu-ui/packages/vuu-layout/src/layout-persistence/LayoutPersistenceManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { LayoutJSON } from "@finos/vuu-layout"; | ||
import { LayoutMetadata } from "@finos/vuu-shell"; | ||
|
||
export interface LayoutPersistenceManager { | ||
/** | ||
* Saves a new layout and its corresponding metadata | ||
* | ||
* @param metadata - Metadata about the layout to be saved | ||
* @param layout - Full JSON representation of the layout to be saved | ||
* | ||
* @returns Unique identifier assigned to the saved layout | ||
*/ | ||
createLayout: (metadata: Omit<LayoutMetadata, "id">, layout: LayoutJSON) => string; | ||
|
||
/** | ||
* Overwrites an existing layout and its corresponding metadata with the provided infromation | ||
* | ||
* @param id - Unique identifier of the existing layout to be updated | ||
* @param metadata - Metadata describing the new layout to overwrite with | ||
* @param layout - Full JSON representation of the new layout to overwrite with | ||
*/ | ||
updateLayout: (id: string, metadata: Omit<LayoutMetadata, "id">, layout: LayoutJSON) => void; | ||
|
||
/** | ||
* Deletes an existing layout and its corresponding metadata | ||
* | ||
* @param id - Unique identifier of the existing layout to be deleted | ||
*/ | ||
deleteLayout: (id: string) => void; | ||
|
||
/** | ||
* Retrieves an existing layout | ||
* | ||
* @param id - Unique identifier of the existing layout to be retrieved | ||
* | ||
* @returns Full JSON representation of the layout corresponding to the provided ID | ||
*/ | ||
loadLayout: (id: string) => LayoutJSON; | ||
|
||
/** | ||
* Retrieves metadata for all existing layouts | ||
* | ||
* @returns an array of all persisted layout metadata | ||
*/ | ||
loadMetadata: () => LayoutMetadata[]; | ||
} |
79 changes: 79 additions & 0 deletions
79
vuu-ui/packages/vuu-layout/src/layout-persistence/LocalLayoutPersistenceManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Layout, LayoutMetadata } from "@finos/vuu-shell"; | ||
import { LayoutJSON, LayoutPersistenceManager } from "@finos/vuu-layout"; | ||
|
||
import { getLocalEntity, saveLocalEntity } from "@finos/vuu-filters"; | ||
import { getUniqueId } from "@finos/vuu-utils"; | ||
|
||
const metadataSaveLocation = "layouts/metadata"; | ||
const layoutsSaveLocation = "layouts/layouts"; | ||
|
||
export class LocalLayoutPersistenceManager implements LayoutPersistenceManager { | ||
createLayout(metadata: Omit<LayoutMetadata, "id">, layout: LayoutJSON): string { | ||
console.log(`Saving layout as ${metadata.name} to group ${metadata.group}...`); | ||
|
||
const existingLayouts = this.loadLayouts(); | ||
const existingMetadata = this.loadMetadata(); | ||
|
||
const id = getUniqueId(); | ||
|
||
this.appendAndPersist(id, metadata, layout, existingLayouts, existingMetadata); | ||
|
||
return id; | ||
} | ||
|
||
updateLayout(id: string, metadata: Omit<LayoutMetadata, "id">, newLayoutJson: LayoutJSON): void { | ||
const existingLayouts = this.loadLayouts().filter(layout => layout.id !== id); | ||
const existingMetadata = this.loadMetadata().filter(metadata => metadata.id !== id); | ||
|
||
this.appendAndPersist(id, metadata, newLayoutJson, existingLayouts, existingMetadata); | ||
} | ||
|
||
deleteLayout(id: string): void { | ||
const layouts = this.loadLayouts().filter(layout => layout.id !== id); | ||
const metadata = this.loadMetadata().filter(metadata => metadata.id !== id); | ||
|
||
this.saveLayoutsWithMetadata(layouts, metadata); | ||
} | ||
|
||
loadLayout(id: string): LayoutJSON { | ||
const layout = this.loadLayouts().filter(layout => layout.id === id); | ||
|
||
switch (layout.length) { | ||
case 1: { | ||
return layout[0].json; | ||
} | ||
case 0: { | ||
console.log(`WARNING: no layout exists for ID "${id}"; returning empty layout`); | ||
return {} as LayoutJSON; | ||
} | ||
default: { | ||
console.log(`WARNING: multiple layouts exist for ID "${id}"; returning first instance`) | ||
return layout[0].json; | ||
} | ||
} | ||
} | ||
|
||
loadMetadata(): LayoutMetadata[] { | ||
return getLocalEntity<LayoutMetadata[]>(metadataSaveLocation) || []; | ||
} | ||
|
||
private loadLayouts(): Layout[] { | ||
return getLocalEntity<Layout[]>(layoutsSaveLocation) || []; | ||
} | ||
|
||
private appendAndPersist(newId: string, | ||
newMetadata: Omit<LayoutMetadata, "id">, | ||
newLayout: LayoutJSON, | ||
existingLayouts: Layout[], | ||
existingMetadata: LayoutMetadata[]) { | ||
existingLayouts.push({id: newId, json: newLayout}); | ||
existingMetadata.push({id: newId, ...newMetadata}); | ||
|
||
this.saveLayoutsWithMetadata(existingLayouts, existingMetadata); | ||
} | ||
|
||
private saveLayoutsWithMetadata(layouts: Layout[], metadata: LayoutMetadata[]): void { | ||
saveLocalEntity<Layout[]>(layoutsSaveLocation, layouts); | ||
saveLocalEntity<LayoutMetadata[]>(metadataSaveLocation, metadata); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './LayoutPersistenceManager'; | ||
export * from './LocalLayoutPersistenceManager'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
vuu-ui/packages/vuu-shell/src/layout-management/layoutTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { LayoutJSON } from "@finos/vuu-layout"; | ||
|
||
export type LayoutMetadata = { | ||
id: string; | ||
name: string; | ||
group: string; | ||
screenshot: string; | ||
user: string; | ||
date: string; | ||
id: string; | ||
}; | ||
|
||
export type Layout = { | ||
id: string, | ||
json: LayoutJSON; | ||
metadata: LayoutMetadata; | ||
}; |
57 changes: 28 additions & 29 deletions
57
vuu-ui/packages/vuu-shell/src/layout-management/useLayoutManager.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
.vuu-theme { | ||
--salt-focused-outlineColor: var(--salt-palette-interact-outline); | ||
--salt-focused-outlineStyle: dotted; | ||
--salt-focused-outlineWidth: 2px; | ||
--salt-focused-outlineInset: 0; | ||
--salt-focused-outlineOffset: 0; | ||
|
||
--salt-focused-outline: var(--salt-focused-outlineWidth) var(--salt-focused-outlineStyle) var(--salt-focused-outlineColor); /* CSS shortcut token: not in Figma */ | ||
--vuu-editable-borderColor-active: var(--editable-border-active, #6D18BD); | ||
} | ||
|
||
.saltFocusVisible:after, | ||
.focused:focus:after, | ||
.focused:focus-visible:after { | ||
content: ""; | ||
inset: var(--salt-focused-outlineInset); | ||
outline-color: var(--salt-focused-outlineColor); | ||
outline-offset: var(--salt-focused-outlineOffset); | ||
outline-style: var(--salt-focused-outlineStyle); | ||
outline-width: var(--salt-focused-outlineWidth); | ||
position: absolute; | ||
} | ||
.saltInput-focused { | ||
border-color: var(--vuu-editable-borderColor-active) !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters