mirror of
https://github.com/bitwarden/browser
synced 2026-01-27 14:53:44 +00:00
fix "No Folder" filter
This commit is contained in:
@@ -143,6 +143,17 @@ describe("VaultFilter", () => {
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true when filtering on unassigned folder via empty string id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedFolder: true,
|
||||
selectedFolderId: "",
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("given an organizational cipher (with organization and collections)", () => {
|
||||
|
||||
@@ -57,10 +57,19 @@ export class VaultFilter {
|
||||
if (this.cipherType != null && cipherPassesFilter) {
|
||||
cipherPassesFilter = CipherViewLikeUtils.getType(cipher) === this.cipherType;
|
||||
}
|
||||
if (this.selectedFolder && this.selectedFolderId == null && cipherPassesFilter) {
|
||||
cipherPassesFilter = cipher.folderId == null;
|
||||
if (
|
||||
this.selectedFolder &&
|
||||
(this.selectedFolderId == null || this.selectedFolderId === "") &&
|
||||
cipherPassesFilter
|
||||
) {
|
||||
cipherPassesFilter = cipher.folderId == null || cipher.folderId === "";
|
||||
}
|
||||
if (this.selectedFolder && this.selectedFolderId != null && cipherPassesFilter) {
|
||||
if (
|
||||
this.selectedFolder &&
|
||||
this.selectedFolderId != null &&
|
||||
this.selectedFolderId !== "" &&
|
||||
cipherPassesFilter
|
||||
) {
|
||||
cipherPassesFilter = cipher.folderId === this.selectedFolderId;
|
||||
}
|
||||
if (this.selectedCollection && this.selectedCollectionId == null && cipherPassesFilter) {
|
||||
|
||||
@@ -116,6 +116,14 @@ describe("createFilter", () => {
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true when filtering on empty-string folder id", () => {
|
||||
const filterFunction = createFilterFunction({ folderId: "" });
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("given an organizational cipher (with organization and collections)", () => {
|
||||
|
||||
@@ -55,8 +55,11 @@ export function createFilterFunction(
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const isNoFolderFilter = filter.folderId === Unassigned || filter.folderId === "";
|
||||
const cipherHasFolder = cipher.folderId != null && cipher.folderId !== "";
|
||||
|
||||
// No folder
|
||||
if (filter.folderId === Unassigned && cipher.folderId != null) {
|
||||
if (isNoFolderFilter && cipherHasFolder) {
|
||||
return false;
|
||||
}
|
||||
// Folder
|
||||
@@ -64,6 +67,7 @@ export function createFilterFunction(
|
||||
filter.folderId !== undefined &&
|
||||
filter.folderId !== All &&
|
||||
filter.folderId !== Unassigned &&
|
||||
filter.folderId !== "" &&
|
||||
cipher.folderId !== filter.folderId
|
||||
) {
|
||||
return false;
|
||||
|
||||
@@ -87,7 +87,7 @@ export class RoutedVaultFilterBridge implements VaultFilter {
|
||||
return this.legacyFilter.selectedFolderNode;
|
||||
}
|
||||
set selectedFolderNode(value: TreeNode<FolderFilter>) {
|
||||
const folderId = value?.node.id ?? Unassigned;
|
||||
const folderId = value?.node.id ? value.node.id : Unassigned;
|
||||
this.bridgeService.navigate({
|
||||
...this.routedFilter,
|
||||
folderId,
|
||||
|
||||
@@ -134,7 +134,7 @@ export class VaultFilter {
|
||||
if (this.selectedFolderNode) {
|
||||
// No folder
|
||||
if (this.folderId === null && cipherPassesFilter) {
|
||||
cipherPassesFilter = cipher.folderId === null;
|
||||
cipherPassesFilter = cipher.folderId == null || cipher.folderId === "";
|
||||
}
|
||||
// Folder
|
||||
if (this.folderId !== null && cipherPassesFilter) {
|
||||
|
||||
@@ -145,7 +145,7 @@ function createLegacyFilterForEndUser(
|
||||
);
|
||||
}
|
||||
|
||||
if (filter.folderId !== undefined && filter.folderId === Unassigned) {
|
||||
if (filter.folderId !== undefined && (filter.folderId === Unassigned || filter.folderId === "")) {
|
||||
legacyFilter.selectedFolderNode = ServiceUtils.getTreeNodeObject(folderTree, null);
|
||||
} else if (filter.folderId !== undefined && filter.folderId !== Unassigned) {
|
||||
legacyFilter.selectedFolderNode = ServiceUtils.getTreeNodeObject(folderTree, filter.folderId);
|
||||
|
||||
Reference in New Issue
Block a user