Persist column selection

This commit is contained in:
Laurent Nguyen 2024-08-22 16:19:23 +02:00
parent 905aa26f27
commit 2397283649
3 changed files with 36 additions and 20 deletions

View File

@ -11,11 +11,13 @@ export enum SubComponentName {
ColumnSizes = "ColumnSizes",
FilterHistory = "FilterHistory",
MainTabDivider = "MainTabDivider",
ColumnsSelection = "ColumnsSelection",
}
export type ColumnSizesMap = { [columnId: string]: WidthDefinition };
export type WidthDefinition = { idealWidth?: number; minWidth?: number };
export type TabDivider = { leftPaneWidthPercent: number };
export type ColumnsSelection = { selectedColumnIds: string[] };
/**
*

View File

@ -92,11 +92,13 @@ async function waitForComponentToPaint<P = unknown>(wrapper: ReactWrapper<P> | S
describe("Documents tab (noSql API)", () => {
describe("buildQuery", () => {
it("should generate the right select query for SQL API", () => {
expect(buildQuery(false, "", ['pk'], {
paths: ['pk'],
kind: 'Hash',
expect(
buildQuery(false, "", ["pk"], {
paths: ["pk"],
kind: "Hash",
version: 2,
})).toContain("select");
}),
).toContain("select");
});
});

View File

@ -470,6 +470,15 @@ export const showPartitionKey = (collection: ViewModels.CollectionBase, isPrefer
};
// Export to expose to unit tests
/**
* Build default query
* @param isMongo true if mongo api
* @param filter
* @param partitionKeyProperties optional for mongo
* @param partitionKey optional for mongo
* @param additionalField
* @returns
*/
export const buildQuery = (
isMongo: boolean,
filter: string,
@ -647,11 +656,12 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
);
const getInitialColumnSelection = () => {
const columnsIds = ["id"];
const defaultColumnsIds = ["id"];
if (showPartitionKey(_collection, isPreferredApiMongoDB)) {
columnsIds.push(...partitionKeyPropertyHeaders);
defaultColumnsIds.push(...partitionKeyPropertyHeaders);
}
return columnsIds;
return readSubComponentState(SubComponentName.ColumnsSelection, _collection, defaultColumnsIds);
};
const [selectedColumnIds, setSelectedColumnIds] = useState<string[]>(getInitialColumnSelection);
@ -1845,6 +1855,8 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
}
setSelectedColumnIds(newSelectedColumnIds);
saveSubComponentState(SubComponentName.ColumnsSelection, _collection, newSelectedColumnIds);
};
const prevSelectedColumnIds = usePrevious({ selectedColumnIds, setSelectedColumnIds });