Skip to content

Commit

Permalink
[Discover] Moved breakdown field to URL app state instead of local st…
Browse files Browse the repository at this point in the history
…orage
  • Loading branch information
davismcphee committed Nov 2, 2022
1 parent 838445c commit 017a7cb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,20 @@ export const useDiscoverHistogram = ({
* Breakdown
*/

const [field, setField] = useState(() => {
const fieldName = storage.get(HISTOGRAM_BREAKDOWN_FIELD_KEY);
return dataView.getFieldByName(fieldName);
});

const onBreakdownFieldChange = useCallback(
(breakdownField: DataViewField | undefined) => {
storage.set(HISTOGRAM_BREAKDOWN_FIELD_KEY, breakdownField?.name);
setField(breakdownField);
stateContainer.setAppState({ breakdownField: breakdownField?.name });
},
[storage]
[stateContainer]
);

const field = useMemo(
() => (state.breakdownField ? dataView.getFieldByName(state.breakdownField) : undefined),
[dataView, state.breakdownField]
);

const breakdown = useMemo(
() => (isPlainRecord || !isTimeBased ? undefined : { field }),
() => (isPlainRecord || !isTimeBased || !field ? undefined : { field }),
[field, isPlainRecord, isTimeBased]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export interface AppState {
* Number of rows in the grid per page
*/
rowsPerPage?: number;
/**
* Current histogram breakdown field name
*/
breakdownField?: string;
}

export interface AppStateUrl extends Omit<AppState, 'sort'> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function getStateDefaults({
rowHeight: undefined,
rowsPerPage: undefined,
grid: undefined,
breakdownField: undefined,
};
if (savedSearch.grid) {
defaultState.grid = savedSearch.grid;
Expand Down

0 comments on commit 017a7cb

Please sign in to comment.