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 pull request #35 from ScottLogic/feature/VUU-33-Layout-Manager-…
…Context VUU-33 add context for layouts
- Loading branch information
Showing
12 changed files
with
167 additions
and
100 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./SaveLayoutPanel"; | ||
export * from "./LayoutList"; | ||
export * from "./layoutTypes"; | ||
export * from "./LayoutList" | ||
export * from "./layoutTypes" | ||
export * from "./useLayoutManager" |
21 changes: 14 additions & 7 deletions
21
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,8 +1,15 @@ | ||
import { LayoutJSON } from "@finos/vuu-layout"; | ||
|
||
export type LayoutMetadata = { | ||
name: string, | ||
group: string, | ||
screenshot: string, | ||
user: string, | ||
date: string, | ||
id: string | ||
} | ||
name: string; | ||
group: string; | ||
screenshot: string; | ||
user: string; | ||
date: string; | ||
id: string; | ||
}; | ||
|
||
export type Layout = { | ||
json: LayoutJSON; | ||
metadata: LayoutMetadata; | ||
}; |
50 changes: 50 additions & 0 deletions
50
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState, useCallback, useContext, useEffect } from "react"; | ||
import { getLocalEntity, saveLocalEntity } from "@finos/vuu-filters"; | ||
import { LayoutJSON } from "@finos/vuu-layout"; | ||
import { getUniqueId } from "@finos/vuu-utils"; | ||
import { LayoutMetadata, Layout } from "./layoutTypes"; | ||
|
||
export const LayoutManagementContext = React.createContext<{ | ||
layouts: Layout[], | ||
saveLayout: (n: Omit<LayoutMetadata, "id">) => void | ||
}>({ layouts: [], saveLayout: () => { } }) | ||
|
||
export const LayoutManagementProvider = (props: { children: JSX.Element | JSX.Element[] }) => { | ||
|
||
const [layouts, setLayouts] = useState<Layout[]>([]) | ||
|
||
useEffect(() => { | ||
const layouts = getLocalEntity<Layout[]>("layouts") | ||
setLayouts(layouts || []) | ||
}, []) | ||
|
||
useEffect(() => { | ||
saveLocalEntity<Layout[]>("layouts", layouts) | ||
}, [layouts]) | ||
|
||
const saveLayout = useCallback((metadata: Omit<LayoutMetadata, "id">) => { | ||
const json = getLocalEntity<LayoutJSON>("api/vui") | ||
if (json) { | ||
setLayouts(prev => | ||
[ | ||
...prev, | ||
{ | ||
metadata: { | ||
...metadata, | ||
id: getUniqueId() | ||
}, | ||
json | ||
} | ||
] | ||
) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<LayoutManagementContext.Provider value={{ layouts, saveLayout }} > | ||
{props.children} | ||
</LayoutManagementContext.Provider> | ||
) | ||
} | ||
|
||
export const useLayoutManager = () => useContext(LayoutManagementContext); |
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
Oops, something went wrong.