mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-02-16 17:25:58 +00:00
Persist column selection
This commit is contained in:
parent
905aa26f27
commit
2397283649
@ -11,11 +11,13 @@ export enum SubComponentName {
|
|||||||
ColumnSizes = "ColumnSizes",
|
ColumnSizes = "ColumnSizes",
|
||||||
FilterHistory = "FilterHistory",
|
FilterHistory = "FilterHistory",
|
||||||
MainTabDivider = "MainTabDivider",
|
MainTabDivider = "MainTabDivider",
|
||||||
|
ColumnsSelection = "ColumnsSelection",
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ColumnSizesMap = { [columnId: string]: WidthDefinition };
|
export type ColumnSizesMap = { [columnId: string]: WidthDefinition };
|
||||||
export type WidthDefinition = { idealWidth?: number; minWidth?: number };
|
export type WidthDefinition = { idealWidth?: number; minWidth?: number };
|
||||||
export type TabDivider = { leftPaneWidthPercent: number };
|
export type TabDivider = { leftPaneWidthPercent: number };
|
||||||
|
export type ColumnsSelection = { selectedColumnIds: string[] };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -92,11 +92,13 @@ async function waitForComponentToPaint<P = unknown>(wrapper: ReactWrapper<P> | S
|
|||||||
describe("Documents tab (noSql API)", () => {
|
describe("Documents tab (noSql API)", () => {
|
||||||
describe("buildQuery", () => {
|
describe("buildQuery", () => {
|
||||||
it("should generate the right select query for SQL API", () => {
|
it("should generate the right select query for SQL API", () => {
|
||||||
expect(buildQuery(false, "", ['pk'], {
|
expect(
|
||||||
paths: ['pk'],
|
buildQuery(false, "", ["pk"], {
|
||||||
kind: 'Hash',
|
paths: ["pk"],
|
||||||
|
kind: "Hash",
|
||||||
version: 2,
|
version: 2,
|
||||||
})).toContain("select");
|
}),
|
||||||
|
).toContain("select");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -470,6 +470,15 @@ export const showPartitionKey = (collection: ViewModels.CollectionBase, isPrefer
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Export to expose to unit tests
|
// 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 = (
|
export const buildQuery = (
|
||||||
isMongo: boolean,
|
isMongo: boolean,
|
||||||
filter: string,
|
filter: string,
|
||||||
@ -647,11 +656,12 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
|||||||
);
|
);
|
||||||
|
|
||||||
const getInitialColumnSelection = () => {
|
const getInitialColumnSelection = () => {
|
||||||
const columnsIds = ["id"];
|
const defaultColumnsIds = ["id"];
|
||||||
if (showPartitionKey(_collection, isPreferredApiMongoDB)) {
|
if (showPartitionKey(_collection, isPreferredApiMongoDB)) {
|
||||||
columnsIds.push(...partitionKeyPropertyHeaders);
|
defaultColumnsIds.push(...partitionKeyPropertyHeaders);
|
||||||
}
|
}
|
||||||
return columnsIds;
|
|
||||||
|
return readSubComponentState(SubComponentName.ColumnsSelection, _collection, defaultColumnsIds);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [selectedColumnIds, setSelectedColumnIds] = useState<string[]>(getInitialColumnSelection);
|
const [selectedColumnIds, setSelectedColumnIds] = useState<string[]>(getInitialColumnSelection);
|
||||||
@ -1845,6 +1855,8 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
|||||||
}
|
}
|
||||||
|
|
||||||
setSelectedColumnIds(newSelectedColumnIds);
|
setSelectedColumnIds(newSelectedColumnIds);
|
||||||
|
|
||||||
|
saveSubComponentState(SubComponentName.ColumnsSelection, _collection, newSelectedColumnIds);
|
||||||
};
|
};
|
||||||
|
|
||||||
const prevSelectedColumnIds = usePrevious({ selectedColumnIds, setSelectedColumnIds });
|
const prevSelectedColumnIds = usePrevious({ selectedColumnIds, setSelectedColumnIds });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user