-
Notifications
You must be signed in to change notification settings - Fork 916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[D&D] Adds autosave while editing aggregation #1953
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import { useTypedDispatch, useTypedSelector } from '../../../utils/state_managem | |
import { DropboxDisplay, DropboxProps } from '../dropbox'; | ||
import { useDrop } from '../../../utils/drag_drop'; | ||
import { | ||
editAgg, | ||
editDraftAgg, | ||
reorderAgg, | ||
updateAggConfigParams, | ||
} from '../../../utils/state_management/visualization_slice'; | ||
|
@@ -88,18 +88,18 @@ export const useDropbox = (props: UseDropboxProps): DropboxProps => { | |
throw new Error('Missing new aggConfig'); | ||
} | ||
|
||
dispatch(editAgg(newAggConfig.serialize())); | ||
dispatch(editDraftAgg(newAggConfig.serialize())); | ||
}, [aggConfigs, aggService, aggs, dispatch, indexPattern, schema.name]); | ||
|
||
const onEditField = useCallback( | ||
(aggId) => { | ||
(aggId: string) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
const aggConfig = aggConfigs?.aggs.find((agg) => agg.id === aggId); | ||
|
||
if (!aggConfig) { | ||
throw new Error('Could not find agg in aggConfigs'); | ||
} | ||
|
||
dispatch(editAgg(aggConfig.serialize())); | ||
dispatch(editDraftAgg(aggConfig.serialize())); | ||
}, | ||
[aggConfigs?.aggs, dispatch] | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { WizardServices } from '../../../types'; | ||
|
||
export interface MetadataState { | ||
editorState: { | ||
valid: { | ||
// Vaidity for each section in the editor | ||
ashwin-pc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[key: string]: boolean; | ||
}; | ||
}; | ||
} | ||
|
||
const initialState: MetadataState = { | ||
editorState: { | ||
valid: {}, | ||
}, | ||
}; | ||
|
||
export const getPreloadedState = async ({ | ||
types, | ||
data, | ||
}: WizardServices): Promise<MetadataState> => { | ||
const preloadedState = { ...initialState }; | ||
|
||
return preloadedState; | ||
}; | ||
|
||
export const slice = createSlice({ | ||
name: 'metadata', | ||
initialState, | ||
reducers: { | ||
setValid: (state, action: PayloadAction<{ key: string; valid: boolean }>) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - I think it would be a little more clear if this was There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I'll fix the naming in a follow-up PR. Miki didn't like it the way it is too. |
||
const { key, valid } = action.payload; | ||
state.editorState.valid[key] = valid; | ||
}, | ||
setState: (_state, action: PayloadAction<MetadataState>) => { | ||
return action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { reducer } = slice; | ||
export const { setValid, setState } = slice.actions; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,15 +59,13 @@ export const slice = createSlice({ | |
setSearchField: (state, action: PayloadAction<string>) => { | ||
state.searchField = action.payload; | ||
}, | ||
editAgg: (state, action: PayloadAction<CreateAggConfigParams>) => { | ||
editDraftAgg: (state, action: PayloadAction<CreateAggConfigParams | undefined>) => { | ||
state.activeVisualization!.draftAgg = action.payload; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it need to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Action can never be undefined. Action always has the type and payload properties. Payload however can be undefined |
||
}, | ||
saveAgg: (state, action: PayloadAction<boolean>) => { | ||
const saveDraft = action.payload; | ||
saveDraftAgg: (state, action: PayloadAction<undefined>) => { | ||
const draftAgg = state.activeVisualization!.draftAgg; | ||
|
||
// Delete the aggConfigParam if the save is not true | ||
if (saveDraft && draftAgg) { | ||
if (draftAgg) { | ||
const aggIndex = state.activeVisualization!.aggConfigParams.findIndex( | ||
(agg) => agg.id === draftAgg.id | ||
); | ||
|
@@ -78,7 +76,6 @@ export const slice = createSlice({ | |
state.activeVisualization!.aggConfigParams.splice(aggIndex, 1, draftAgg); | ||
} | ||
} | ||
delete state.activeVisualization!.draftAgg; | ||
}, | ||
reorderAgg: ( | ||
state, | ||
|
@@ -116,9 +113,9 @@ export const { | |
setActiveVisualization, | ||
setIndexPattern, | ||
setSearchField, | ||
editAgg, | ||
editDraftAgg, | ||
saveDraftAgg, | ||
updateAggConfigParams, | ||
saveAgg, | ||
reorderAgg, | ||
setState, | ||
} = slice.actions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are
isValid
andvalid
supposed to be different? If yes, the naming can improve in a future change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, is
isValid
is the value passed to the callback function.valid
is the value stored in state. Yeah I agree, naming can improve. Will take note to update it in the next PR :)