-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISV catalog refresh must bring control back to previously selected se…
…rvice.
- Loading branch information
Showing
5 changed files
with
143 additions
and
9 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
59 changes: 59 additions & 0 deletions
59
src/components/content/catalog/services/store/CatalogTreeStore.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,59 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { createWithEqualityFn } from 'zustand/traditional'; | ||
import { shallow } from 'zustand/shallow'; | ||
import { createJSONStorage, persist } from 'zustand/middleware'; | ||
import React from 'react'; | ||
|
||
interface CurrentCatalogTreeSelectKeyStore { | ||
currentCatalogTreeSelectKey: React.Key | undefined; | ||
isUnRegister: boolean; | ||
currentCatalogTreeExpandKeys: React.Key[]; | ||
currentCsp: string | undefined; | ||
} | ||
|
||
const initialState: CurrentCatalogTreeSelectKeyStore = { | ||
currentCatalogTreeSelectKey: undefined, | ||
isUnRegister: false, | ||
currentCatalogTreeExpandKeys: [], | ||
currentCsp: undefined, | ||
}; | ||
|
||
interface updateState { | ||
addCurrentCatalogTreeSelectKey: ( | ||
currentSelectKey: React.Key, | ||
unregisterSelectKey: boolean, | ||
currentExpandKeys: React.Key[], | ||
currentCsp: string | ||
) => void; | ||
clearCurrentCatalogTreeSelectKey: () => void; | ||
} | ||
|
||
export const useCurrentCatalogTreeSelectKeyStore = createWithEqualityFn< | ||
CurrentCatalogTreeSelectKeyStore & updateState | ||
>()( | ||
persist( | ||
(set) => ({ | ||
...initialState, | ||
addCurrentCatalogTreeSelectKey: (currentSelectKey, isUnRegister, currentExpandKeys, currentCsp) => { | ||
set({ | ||
currentCatalogTreeSelectKey: currentSelectKey, | ||
isUnRegister: isUnRegister, | ||
currentCatalogTreeExpandKeys: currentExpandKeys, | ||
currentCsp: currentCsp, | ||
}); | ||
}, | ||
clearCurrentCatalogTreeSelectKey: () => { | ||
set(initialState); | ||
}, | ||
}), | ||
{ | ||
name: 'storage', | ||
storage: createJSONStorage(() => localStorage), | ||
} | ||
), | ||
shallow | ||
); |
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