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
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
Prev Previous commit
chore: pr review changes
  • Loading branch information
ahmadshaheer committed Sep 27, 2024
commit af0f393a92ab2acf5c20986da025caebe22fdff1
15 changes: 12 additions & 3 deletions frontend/src/container/ExplorerOptions/ExplorerOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { AppState } from 'store/reducers';
import { Dashboard } from 'types/api/dashboard/getAll';
import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { ViewProps } from 'types/api/saveViews/types';
import { DataSource, StringOperators } from 'types/common/queryBuilder';
Expand Down Expand Up @@ -262,6 +263,10 @@ function ExplorerOptions({
aggregateOperator: StringOperators.NOOP,
});

type ExtraData = {
selectColumns?: BaseAutocompleteData[];
};

const updateOrRestoreSelectColumns = (
key: string,
allViewsData: ViewProps[] | undefined,
Expand All @@ -273,9 +278,14 @@ function ExplorerOptions({
return;
}

const extraData = JSON.parse(currentViewDetails?.extraData ?? '{}');
let extraData: ExtraData = {};
try {
extraData = JSON.parse(currentViewDetails?.extraData ?? '{}') as ExtraData;
} catch (error) {
console.error('Error parsing extraData:', error);
}

if (!!extraData && extraData?.selectColumns) {
if (extraData.selectColumns?.length) {
handleOptionsChange({
...options,
selectColumns: extraData.selectColumns,
Expand All @@ -287,7 +297,6 @@ function ExplorerOptions({
});
}
};

const onMenuItemSelectHandler = useCallback(
({ key }: { key: string }): void => {
const currentViewDetails = getViewDetailsUsingViewKey(
Expand Down
Loading