Make datalist for filter unique per database/container combination

This commit is contained in:
Laurent Nguyen 2024-07-23 10:09:01 +02:00
parent 4fda518a3f
commit bf1474e101
2 changed files with 12 additions and 4 deletions

View File

@ -19,7 +19,7 @@ import {
getSaveExistingDocumentButtonState, getSaveExistingDocumentButtonState,
getSaveNewDocumentButtonState, getSaveNewDocumentButtonState,
getTabsButtons, getTabsButtons,
showPartitionKey, showPartitionKey
} from "Explorer/Tabs/DocumentsTabV2/DocumentsTabV2"; } from "Explorer/Tabs/DocumentsTabV2/DocumentsTabV2";
import { ReactWrapper, ShallowWrapper, mount, shallow } from "enzyme"; import { ReactWrapper, ShallowWrapper, mount, shallow } from "enzyme";
import * as ko from "knockout"; import * as ko from "knockout";
@ -474,3 +474,9 @@ describe("Documents tab (noSql API)", () => {
}); });
}); });
}); });
describe("Documents tab", () => {
it("should add strings to array without duplicate", () => {
addStringsNoDuplicates(test this);
});
});

View File

@ -459,6 +459,8 @@ export interface IDocumentsTabComponentProps {
isTabActive: boolean; isTabActive: boolean;
} }
const getUniqueId = (collection: ViewModels.CollectionBase): string => `${collection.databaseId}-${collection.id()}`;
const defaultSqlFilters = ['WHERE c.id = "foo"', "ORDER BY c._ts DESC", 'WHERE c.id = "foo" ORDER BY c._ts DESC']; const defaultSqlFilters = ['WHERE c.id = "foo"', "ORDER BY c._ts DESC", 'WHERE c.id = "foo" ORDER BY c._ts DESC'];
const defaultMongoFilters = ['{"id":"foo"}', "{ qty: { $gte: 20 } }"]; const defaultMongoFilters = ['{"id":"foo"}', "{ qty: { $gte: 20 } }"];
@ -1756,7 +1758,7 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
id="filterInput" id="filterInput"
ref={filterInput} ref={filterInput}
type="text" type="text"
list="filtersList" list={`filtersList-${getUniqueId(_collection)}`}
className={`${filterContent.length === 0 ? "placeholderVisible" : ""}`} className={`${filterContent.length === 0 ? "placeholderVisible" : ""}`}
style={{ width: "100%" }} style={{ width: "100%" }}
title="Type a query predicate or choose one from the list." title="Type a query predicate or choose one from the list."
@ -1772,7 +1774,7 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
onBlur={() => setIsFilterFocused(false)} onBlur={() => setIsFilterFocused(false)}
/> />
<datalist id="filtersList"> <datalist id={`filtersList-${getUniqueId(_collection)}`}>
{addStringsNoDuplicate( {addStringsNoDuplicate(
lastFilterContents, lastFilterContents,
isPreferredApiMongoDB ? defaultMongoFilters : defaultSqlFilters, isPreferredApiMongoDB ? defaultMongoFilters : defaultSqlFilters,