forked from flyteorg/flyte
-
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.
chore: preparations for "Only Mine" feature support (flyteorg#411)
The main UI is added and execution's filter is connected. All changes leave under OnlyMine featureFlag Signed-off-by: Eugene Jahn <eugenejahnjahn@gmail.com>
- Loading branch information
1 parent
16c0721
commit 0590d1c
Showing
19 changed files
with
455 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// More info on Local storage: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage | ||
import { log } from 'common/log'; | ||
import * as React from 'react'; | ||
import { useState, createContext, useCallback } from 'react'; | ||
import { defaultLocalCacheConfig, LocalCacheItem } from './defaultConfig'; | ||
|
||
export { LocalCacheItem } from './defaultConfig'; | ||
|
||
interface LocalCacheState { | ||
localCacheMap: Record<string, any>; | ||
setLocalCache: (localCacheItem: LocalCacheItem, newValue: any) => void; | ||
getLocalCache: (localCacheItem: LocalCacheItem) => any; | ||
} | ||
|
||
interface LocalCacheProviderProps { | ||
children?: React.ReactNode; | ||
} | ||
|
||
// get the local storage value, if local storage is null, use default value | ||
function allStorage() { | ||
const defaultKeys = Object.keys(defaultLocalCacheConfig); | ||
|
||
const localCacheMap: Record<string, any> = {}; | ||
let i = defaultKeys.length; | ||
while (i--) { | ||
const key = defaultKeys[i]; | ||
const value = localStorage.getItem(key) || defaultLocalCacheConfig[key]; | ||
localCacheMap[defaultKeys[i]] = JSON.parse(value); | ||
} | ||
return localCacheMap; | ||
} | ||
|
||
export const LocalCacheContext = createContext<LocalCacheState>({ | ||
localCacheMap: { ...allStorage() }, | ||
setLocalCache: () => { | ||
/* Provider is not initialized */ | ||
}, | ||
getLocalCache: () => false, | ||
}); | ||
|
||
export const LocalCacheProvider = (props: LocalCacheProviderProps) => { | ||
const [localCacheMap, setLocalCacheMap] = useState({ ...allStorage() }); | ||
|
||
const setLocalCache = useCallback((localCacheItem: LocalCacheItem, newValue: any) => { | ||
setLocalCacheMap((prev) => ({ ...prev, [localCacheItem]: newValue })); | ||
}, []); | ||
|
||
const getLocalCache = useCallback( | ||
(localCacheItem: LocalCacheItem) => { | ||
const localCache = localCacheMap[localCacheItem]; | ||
if (localCache == null) { | ||
log.error( | ||
`ERROR: LocalCacheItem ${localCacheItem} doesn't have default value provided in defaultLocalCacheConfig`, | ||
); | ||
return null; | ||
} | ||
return localCache; | ||
}, | ||
[localCacheMap], | ||
); | ||
|
||
return ( | ||
<LocalCacheContext.Provider value={{ localCacheMap, setLocalCache, getLocalCache }}> | ||
{props.children} | ||
</LocalCacheContext.Provider> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export enum OnlyMyFilter { | ||
SelectAll = 'selectAll', | ||
OnlyMyWorkflow = 'onlyMyWorkflow', | ||
OnlyMyExecutions = 'onlyMyExecutions', | ||
OnlyMyTasks = 'onlyMyTasks', | ||
OnlyMyWorkflowVersions = 'onlyMyWorkflowVersions', | ||
OnlyMyLaunchForm = 'onlyMyLaunchForm', | ||
} | ||
|
||
export const filterByDefault = [ | ||
{ | ||
value: 'selectAll', | ||
label: 'Select All', | ||
data: true, | ||
}, | ||
{ | ||
value: 'onlyMyWorkflow', | ||
label: 'Only My Workflow', | ||
data: true, | ||
}, | ||
{ | ||
value: 'onlyMyExecutions', | ||
label: 'Only My Executions', | ||
data: true, | ||
}, | ||
{ | ||
value: 'onlyMyTasks', | ||
label: 'Only My Tasks', | ||
data: true, | ||
}, | ||
{ | ||
value: 'onlyMyWorkflowVersions', | ||
label: 'Only My Workflow Versions', | ||
data: true, | ||
}, | ||
{ | ||
value: 'onlyMyLaunchForm', | ||
label: 'Only My Launch Form', | ||
data: true, | ||
}, | ||
]; | ||
|
||
export const defaultSelectedValues = Object.assign( | ||
{}, | ||
...filterByDefault.map((x) => ({ [x.value]: x.data })), | ||
); |
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.