Skip to content
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

feat: store columns while saving view and restore columns on selecting view without select columns #5647

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: store columns while saving view and restore columns on selectin…
…g view without select columns
  • Loading branch information
ahmadshaheer committed Sep 10, 2024
commit aad4aa5efecb6c91f8785af35126f3f06ce9bff5
8 changes: 7 additions & 1 deletion frontend/src/components/ExplorerCard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export type GetViewDetailsUsingViewKey = (
viewKey: string,
data: ViewProps[] | undefined,
) =>
| { query: Query; name: string; uuid: string; panelType: PANEL_TYPES }
| {
query: Query;
name: string;
uuid: string;
panelType: PANEL_TYPES;
extraData?: string;
}
| undefined;

export interface IsQueryUpdatedInViewProps {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/ExplorerCard/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export const getViewDetailsUsingViewKey: GetViewDetailsUsingViewKey = (
) => {
const selectedView = data?.find((view) => view.uuid === viewKey);
if (selectedView) {
const { compositeQuery, name, uuid } = selectedView;
const { compositeQuery, name, uuid, extraData } = selectedView;
ahmadshaheer marked this conversation as resolved.
Show resolved Hide resolved
const query = mapQueryDataFromApi(compositeQuery);
return { query, name, uuid, panelType: compositeQuery.panelType };
return { query, name, uuid, panelType: compositeQuery.panelType, extraData };
}
return undefined;
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/constants/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export enum LOCALSTORAGE {
THEME_ANALYTICS_V1 = 'THEME_ANALYTICS_V1',
LAST_USED_SAVED_VIEWS = 'LAST_USED_SAVED_VIEWS',
SHOW_LOGS_QUICK_FILTERS = 'SHOW_LOGS_QUICK_FILTERS',
OLD_SELECT_COLUMNS = 'OLD_SELECT_COLUMNS',
}
64 changes: 61 additions & 3 deletions frontend/src/container/ExplorerOptions/ExplorerOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { QueryParams } from 'constants/query';
import { PANEL_TYPES } from 'constants/queryBuilder';
import ROUTES from 'constants/routes';
import ExportPanelContainer from 'container/ExportPanel/ExportPanelContainer';
import { useOptionsMenu } from 'container/OptionsMenu';
import { OptionsQuery } from 'container/OptionsMenu/types';
import { useGetSearchQueryParam } from 'hooks/queryBuilder/useGetSearchQueryParam';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { useGetAllViews } from 'hooks/saveViews/useGetAllViews';
Expand All @@ -34,7 +36,7 @@ import useErrorNotification from 'hooks/useErrorNotification';
import { useHandleExplorerTabChange } from 'hooks/useHandleExplorerTabChange';
import { useNotifications } from 'hooks/useNotifications';
import { mapCompositeQueryFromQuery } from 'lib/newQueryBuilder/queryBuilderMappers/mapCompositeQueryFromQuery';
import { cloneDeep } from 'lodash-es';
import { cloneDeep, isEqual } from 'lodash-es';
import {
Check,
ConciergeBell,
Expand All @@ -59,6 +61,7 @@ import { useHistory } from 'react-router-dom';
import { AppState } from 'store/reducers';
import { Dashboard } from 'types/api/dashboard/getAll';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { ViewProps } from 'types/api/saveViews/types';
import { DataSource, StringOperators } from 'types/common/queryBuilder';
import AppReducer from 'types/reducer/app';
import { USER_ROLES } from 'types/roles';
Expand Down Expand Up @@ -252,6 +255,48 @@ function ExplorerOptions({

const { handleExplorerTabChange } = useHandleExplorerTabChange();

const { options, handleOptionsChange } = useOptionsMenu({
storageKey: LOCALSTORAGE.TRACES_LIST_OPTIONS,
dataSource: DataSource.TRACES,
aggregateOperator: StringOperators.NOOP,
});

const updateOrRestoreSelectColumns = (
key: string,
allViewsData: ViewProps[] | undefined,
options: OptionsQuery,
handleOptionsChange: (newQueryData: OptionsQuery) => void,
): void => {
const currentViewDetails = getViewDetailsUsingViewKey(key, allViewsData);
ahmadshaheer marked this conversation as resolved.
Show resolved Hide resolved
if (!currentViewDetails) {
return;
}

const extraData = JSON.parse(currentViewDetails?.extraData ?? '{}');
ahmadshaheer marked this conversation as resolved.
Show resolved Hide resolved

if (extraData?.selectColumns) {
localStorage.setItem(
LOCALSTORAGE.OLD_SELECT_COLUMNS,
JSON.stringify(options.selectColumns),
);

handleOptionsChange({
...options,
selectColumns: extraData.selectColumns,
});
} else {
const oldSelectColumns = JSON.parse(
localStorage.getItem(LOCALSTORAGE.OLD_SELECT_COLUMNS) ?? '{}',
);
if (!isEqual(oldSelectColumns, options.selectColumns)) {
handleOptionsChange({
...options,
selectColumns: oldSelectColumns,
});
}
}
};

const onMenuItemSelectHandler = useCallback(
({ key }: { key: string }): void => {
const currentViewDetails = getViewDetailsUsingViewKey(
Expand Down Expand Up @@ -321,6 +366,13 @@ function ExplorerOptions({

updatePreservedViewInLocalStorage(option);

updateOrRestoreSelectColumns(
option.key,
viewsData?.data?.data,
ahmadshaheer marked this conversation as resolved.
Show resolved Hide resolved
options,
handleOptionsChange,
);

if (ref.current) {
ref.current.blur();
}
Expand Down Expand Up @@ -360,14 +412,20 @@ function ExplorerOptions({
viewName: newViewName || '',
compositeQuery,
sourcePage: sourcepage,
extraData: JSON.stringify({ color }),
extraData: JSON.stringify({
color,
selectColumns: options.selectColumns,
}),
});

const onSaveHandler = (): void => {
saveNewViewHandler({
compositeQuery,
handlePopOverClose: hideSaveViewModal,
extraData: JSON.stringify({ color }),
extraData: JSON.stringify({
color,
selectColumns: options.selectColumns,
}),
notifications,
panelType: panelType || PANEL_TYPES.LIST,
redirectWithQueryBuilderData,
Expand Down