1 parent
7a098a276a
commit
e1a4242729
6 files changed
+72
-1
No files matched your search
@@ -37,4 +37,41 @@ describe("data grid column lookup search", () => {
|
||||
it("returns all columns for an empty query", () => {
|
||||
expect(filterDataGridColumnLookupItems(items, " ")).toEqual(items);
|
||||
});
|
||||
|
||||
it("keeps grouped comments aligned by result ordinal and searches them", () => {
|
||||
const groupedItems = buildDataGridColumnLookupItems({
|
||||
columns: ["label", "label", "total"],
|
||||
columnComments: ["Primary label", "Joined label", undefined],
|
||||
commentByColumn: new Map([
|
||||
["label", "Wrong name-based label"],
|
||||
["total", "Wrong aggregate label"],
|
||||
]),
|
||||
});
|
||||
|
||||
expect(groupedItems.map((item) => item.comment)).toEqual(["Primary label", "Joined label", undefined]);
|
||||
expect(filterDataGridColumnLookupItems(groupedItems, "joined").map((item) => item.index)).toEqual([1]);
|
||||
expect(filterDataGridColumnLookupItems(groupedItems, "wrong")).toEqual([]);
|
||||
});
|
||||
|
||||
it("falls back to source metadata only when ordinal comments are absent", () => {
|
||||
const comments = new Map([
|
||||
["department", "Department name"],
|
||||
["total", "Unsafe aggregate fallback"],
|
||||
]);
|
||||
|
||||
expect(
|
||||
buildDataGridColumnLookupItems({
|
||||
columns: ["dept"],
|
||||
sourceColumns: ["department"],
|
||||
commentByColumn: comments,
|
||||
}),
|
||||
).toMatchObject([{ comment: "Department name" }]);
|
||||
expect(
|
||||
buildDataGridColumnLookupItems({
|
||||
columns: ["total"],
|
||||
columnComments: [undefined],
|
||||
commentByColumn: comments,
|
||||
}),
|
||||
).toEqual([{ index: 0, name: "total" }]);
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,7 @@ export interface DataGridColumnLookupItem {
|
||||
export interface DataGridColumnLookupOptions {
|
||||
columns: readonly string[];
|
||||
sourceColumns?: readonly (string | undefined)[];
|
||||
columnComments?: readonly (string | undefined)[];
|
||||
displayableIndexes?: readonly number[];
|
||||
commentByColumn?: ReadonlyMap<string, string>;
|
||||
}
|
||||
@@ -38,7 +39,9 @@ export function buildDataGridColumnLookupItems(options: DataGridColumnLookupOpti
|
||||
return indexes.map((index) => {
|
||||
const name = options.columns[index] ?? `#${index + 1}`;
|
||||
const sourceName = options.sourceColumns?.[index];
|
||||
const comment = dataGridColumnCommentFor(options.commentByColumn, name, sourceName);
|
||||
// A present ordinal array owns unresolved entries too; falling back by
|
||||
// name there could leak another source's comment onto an aggregate/alias.
|
||||
const comment = options.columnComments === undefined ? dataGridColumnCommentFor(options.commentByColumn, name, sourceName) : nonEmptyComment(options.columnComments[index]);
|
||||
return {
|
||||
index,
|
||||
name,
|
||||
|
||||
Reference in new issue
Block a user