UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

72 lines (71 loc) 2.46 kB
/* * Copyright 2025 The Kubernetes Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { createSlice } from '@reduxjs/toolkit'; import { useMemo } from 'react'; import { useTypedSelector } from './hooks'; export const INITIAL_UI_STATE = { isVersionDialogOpen: false, hideAppBar: false, isFullWidth: false, functionsToOverride: {}, panels: [], }; export const uiSlice = createSlice({ name: 'ui', initialState: INITIAL_UI_STATE, reducers: { setHideAppBar(state, action) { state.hideAppBar = action.payload; }, setClusterChooserButton(state, action) { state.clusterChooserButtonComponent = action.payload; }, setVersionDialogOpen(state, action) { state.isVersionDialogOpen = action.payload; }, setFunctionsToOverride(state, action) { const functionToOverride = action.payload; for (const key in functionToOverride) { if (functionToOverride.hasOwnProperty(key)) { state.functionsToOverride[key] = functionToOverride[key]; } } }, setIsFullWidth(state, action) { state.isFullWidth = action.payload; }, addUIPanel(state, action) { const panel = action.payload; // Remove existing panel with this id, if it exists state.panels = state.panels.filter(it => it.id !== panel.id); state.panels.push(panel); }, }, }); /** * @returns UI panels grouped by their location */ export const useUIPanelsGroupedBySide = () => { const panels = useTypedSelector(state => state.ui.panels); return useMemo(() => panels.reduce((result, panel) => (result[panel.side].push(panel), result), { top: [], right: [], left: [], bottom: [], }), [panels]); }; export default uiSlice.reducer;