-
Notifications
You must be signed in to change notification settings - Fork 1
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 #286 from kloudlite/update/cluster-status
WEB: Update console, auth and webinar changes
- Loading branch information
Showing
68 changed files
with
11,660 additions
and
490 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 |
---|---|---|
|
@@ -135,4 +135,6 @@ export { | |
Sliders, | ||
FileLock, | ||
StackSimple, | ||
Play, | ||
Pause, | ||
} from '@jengaicons/react'; |
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,79 @@ | ||
import { useParams } from '@remix-run/react'; | ||
import { | ||
Dispatch, | ||
ReactNode, | ||
SetStateAction, | ||
createContext, | ||
useCallback, | ||
useContext, | ||
useMemo, | ||
useState, | ||
} from 'react'; | ||
import { useSocketWatch } from '~/root/lib/client/helpers/socket/useWatch'; | ||
import useDebounce from '~/root/lib/client/hooks/use-debounce'; | ||
import { useConsoleApi } from '../server/gql/api-provider'; | ||
import { IByocClusters } from '../server/gql/queries/byok-cluster-queries'; | ||
import { ExtractNodeType, parseNodes } from '../server/r-utils/common'; | ||
|
||
type IClusterMap = { [key: string]: ExtractNodeType<IByocClusters> }; | ||
|
||
const ClusterStatusContext = createContext<{ | ||
clusters: IClusterMap; | ||
setClusters: Dispatch<SetStateAction<IClusterMap>>; | ||
}>({ clusters: {}, setClusters: () => {} }); | ||
|
||
const ClusterStatusProvider = ({ children }: { children: ReactNode }) => { | ||
const [clusters, setClusters] = useState<IClusterMap>({}); | ||
const api = useConsoleApi(); | ||
const [update, setUpdate] = useState(false); | ||
|
||
const { account } = useParams(); | ||
|
||
const topic = useCallback(() => { | ||
return Object.keys(clusters).map((c) => `account:${account}.cluster:${c}`); | ||
}, [clusters])(); | ||
|
||
const listCluster = useCallback(async () => { | ||
try { | ||
const cl = await api.listAllClusters(); | ||
const parsed = parseNodes(cl.data).reduce((acc, c) => { | ||
acc[c.metadata.name] = c; | ||
return acc; | ||
}, {} as { [key: string]: ExtractNodeType<IByocClusters> }); | ||
setClusters(parsed); | ||
return clusters; | ||
} catch (err) { | ||
console.error(err); | ||
return false; | ||
} | ||
}, []); | ||
|
||
useDebounce( | ||
() => { | ||
listCluster(); | ||
}, | ||
3000, | ||
[update] | ||
); | ||
|
||
useSocketWatch(() => { | ||
setUpdate((p) => !p); | ||
}, topic); | ||
|
||
return ( | ||
<ClusterStatusContext.Provider | ||
value={useMemo( | ||
() => ({ clusters, setClusters }), | ||
[clusters, setClusters] | ||
)} | ||
> | ||
{children} | ||
</ClusterStatusContext.Provider> | ||
); | ||
}; | ||
|
||
export default ClusterStatusProvider; | ||
|
||
export const useClusterStatusV2 = () => { | ||
return useContext(ClusterStatusContext); | ||
}; |
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.