Skip to content

Commit

Permalink
feat: save filter preset
Browse files Browse the repository at this point in the history
  • Loading branch information
topliceanurazvan committed May 20, 2022
1 parent bcb16eb commit 366b1c0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {Suspense} from 'react';
import {Form, Modal, Skeleton} from 'antd';

import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {saveFilterPreset} from '@redux/reducers/main';
import {closeFiltersPresetModal} from '@redux/reducers/ui';

const SaveModalContent = React.lazy(() => import('./SaveModalContent'));
Expand All @@ -25,8 +26,7 @@ const FiltersPresetModal: React.FC = () => {
form.validateFields().then(values => {
const {name} = values;

console.log(name);

dispatch(saveFilterPreset(name));
dispatch(closeFiltersPresetModal());
});
};
Expand Down
6 changes: 6 additions & 0 deletions src/models/appstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type PreviewLoaderType = {
targetId?: string;
};

type FiltersPresetsType = {
[name: string]: ResourceFilterType;
};

type ResourceDiffType = {
targetResourceId?: string;
};
Expand Down Expand Up @@ -178,6 +182,7 @@ interface AppState {
selectedDockerImage?: DockerImage | null;
imagesSearchedValue?: string;
imagesMap: ImagesMapType;
filtersPresets: FiltersPresetsType;
}

export interface PossibleResource {
Expand All @@ -197,6 +202,7 @@ export type {
AppState,
ResourceMapType,
ResourceFilterType,
FiltersPresetsType,
FileMapType,
ImagesMapType,
HelmChartMapType,
Expand Down
1 change: 1 addition & 0 deletions src/redux/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const initialAppState: AppState = {
},
deviceID: electronStore.get('main.deviceID'),
imagesMap: [],
filtersPresets: electronStore.get('main.filtersPresets') || {},
};

const initialAppConfigState: AppConfig = {
Expand Down
7 changes: 7 additions & 0 deletions src/redux/reducers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ export const mainSlice = createSlice({
setImagesMap: (state: Draft<AppState>, action: PayloadAction<ImagesMapType>) => {
state.imagesMap = action.payload;
},
saveFilterPreset: (state: Draft<AppState>, action: PayloadAction<string>) => {
const name = action.payload;

state.filtersPresets[name] = state.resourceFilter;
electronStore.set('main.filtersPresets', state.filtersPresets);
},
},
extraReducers: builder => {
builder.addCase(setAlert, (state, action) => {
Expand Down Expand Up @@ -1236,6 +1242,7 @@ export const {
openResourceDiffModal,
reloadClusterDiff,
resetResourceFilter,
saveFilterPreset,
seenNotifications,
selectDockerImage,
selectFile,
Expand Down
6 changes: 6 additions & 0 deletions src/utils/electronStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const schema = {
deviceID: {
type: 'string',
},
filtersPresets: {
type: 'object',
},
},
},
appConfig: {
Expand Down Expand Up @@ -247,6 +250,9 @@ const schema = {
};

const defaults = {
main: {
filtersPresets: {},
},
appConfig: {
isClusterSelectorVisible: true,
loadLastProjectOnStartup: false,
Expand Down

0 comments on commit 366b1c0

Please sign in to comment.