-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) O3-3244 & O3-3250: Allow data sharing between workspaces with …
…same sidebar family name (#1094)
- Loading branch information
1 parent
4d3f1b0
commit 9811845
Showing
10 changed files
with
265 additions
and
26 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
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
40 changes: 40 additions & 0 deletions
40
...ramework/esm-styleguide/src/workspaces/workspace-sidebar-store/useWorkspaceFamilyStore.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,40 @@ | ||
import { useEffect, useMemo, useState } from 'react'; | ||
import { getWorkspaceFamilyStore } from '../workspaces'; | ||
import type { StoreApi } from 'zustand/vanilla'; | ||
|
||
/** | ||
* This hook is used to interact with the store of a workspace family. | ||
* A workspace family is defined as a group of workspaces that share the same sidebarFamilyName. | ||
* | ||
* In case a workspace doesn't have a sidebarFamilyName, it will be considered as a standalone workspace, and hence this hook will return an empty object and updateFunction as an empty function. | ||
* | ||
* @internal | ||
* | ||
* @param {string} sidebarFamilyName The sidebarFamilyName of the workspace used when registering the workspace in the module's routes.json file. | ||
*/ | ||
export function useWorkspaceFamilyStore(sidebarFamilyName: string) { | ||
const [storeState, setStoreState] = useState<object>({}); | ||
const [currentSidebarFamilyName, setCurrentSidebarFamilyName] = useState(sidebarFamilyName); | ||
|
||
useEffect(() => { | ||
if (currentSidebarFamilyName !== sidebarFamilyName) { | ||
setCurrentSidebarFamilyName(sidebarFamilyName); | ||
} | ||
}, [sidebarFamilyName]); | ||
|
||
useEffect(() => { | ||
const store = getWorkspaceFamilyStore(currentSidebarFamilyName); | ||
let unsubscribe: () => void; | ||
if (store) { | ||
setStoreState(store.getState()); | ||
unsubscribe = store.subscribe(setStoreState); | ||
} | ||
return () => { | ||
if (store) { | ||
unsubscribe?.(); | ||
} | ||
}; | ||
}, [currentSidebarFamilyName]); | ||
|
||
return storeState; | ||
} |
Oops, something went wrong.