-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add localStorage for selected Project/Domain (#774)
* chore: init checkin Signed-off-by: Jason Porter <[email protected]> * feat: added support for persisting the last viewed project and domain Signed-off-by: Jason Porter <[email protected]> * feat: added a view all link to the project list, still missing styles Signed-off-by: Jason Porter <[email protected]> * feat: changed save to explicit project select Signed-off-by: Jason Porter <[email protected]> * fix: refactored to use static route for select Signed-off-by: Jason Porter <[email protected]> * chore: view all as styled list item Signed-off-by: Frank Flitton <[email protected]> * feat: refactored to make localStorage utils Signed-off-by: Jason Porter <[email protected]> * chore: purple text and new route Signed-off-by: Frank Flitton <[email protected]> * chore: fix null state condition Signed-off-by: Frank Flitton <[email protected]> * feat: addressed pr comments and fixed project dropdown select Signed-off-by: Jason Porter <[email protected]> * chore: add elipsis Signed-off-by: Frank Flitton <[email protected]> --------- Signed-off-by: Jason Porter <[email protected]> Signed-off-by: Frank Flitton <[email protected]> Co-authored-by: Frank Flitton <[email protected]> Co-authored-by: Carina Ursu <[email protected]>
- Loading branch information
1 parent
4b57956
commit 007e636
Showing
8 changed files
with
232 additions
and
47 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
58 changes: 58 additions & 0 deletions
58
packages/console/src/components/common/LocalStoreDefaults.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,58 @@ | ||
export const LOCAL_STORE_DEFAULTS = 'flyteDefaults'; | ||
export const LOCAL_PROJECT_DOMAIN = 'projectDomain'; | ||
|
||
export interface LocalStorageRecord { | ||
[key: string]: any; | ||
} | ||
|
||
/** | ||
* Use: skipping project select page is value is present | ||
*/ | ||
export type LocalStorageProjectDomain = { | ||
project: string; | ||
domain: string; | ||
}; | ||
|
||
/** | ||
* Generic localStorage interface | ||
*/ | ||
export interface LocalStoreDefaults { | ||
projectDomain?: LocalStorageProjectDomain; | ||
} | ||
|
||
/** | ||
* Queries localStorage for flye values. If a query key is provided it will | ||
* check for only that key (and return false otherwise) else return the entire | ||
* JSON | ||
* | ||
* @param key Optional param to return just one key from localStorage | ||
* @returns value or false | ||
*/ | ||
export const getLocalStore = (key: string | null = null): any | false => { | ||
const localStoreDefaults = localStorage.getItem(LOCAL_STORE_DEFAULTS); | ||
if (!localStoreDefaults) { | ||
return false; | ||
} | ||
const localJSON = JSON.parse(localStoreDefaults) as LocalStoreDefaults; | ||
if (key) { | ||
if (localJSON[key]) { | ||
return localJSON[key]; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return localJSON; | ||
} | ||
}; | ||
|
||
/** | ||
* Sets values to 'flyteDefaults' for use in persisting various user defaults. | ||
*/ | ||
export const setLocalStore = (key: string, value: any) => { | ||
const localStoreDefaults = localStorage.getItem(LOCAL_STORE_DEFAULTS) || '{}'; | ||
const storeDefaultsJSON = JSON.parse( | ||
localStoreDefaults, | ||
) as LocalStoreDefaults; | ||
storeDefaultsJSON[key] = value; | ||
localStorage.setItem(LOCAL_STORE_DEFAULTS, JSON.stringify(storeDefaultsJSON)); | ||
}; |
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