Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hub-common): site collections not hidden properly #1827

Merged
merged 5 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions packages/common/src/search/types/IHubCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ export const targetEntities = [
] as const;
export type EntityType = (typeof targetEntities)[number];

/**
* @private
*
* This interface wraps IHubCollection and provides additional fields
* for collection configuration. It is the actual interface used when
* when storing an entity's catalog collections.
*/
export interface IHubCollectionPersistance extends IHubCollection {
hidden?: boolean;
}

/**
* IQuery is the fundamental unit used to execute a search. By composing
* `Filter`'s and `IPredicate`s, we can express very complex queries
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getWithDefault } from "../../objects";
import { IHubCollectionPersistance } from "../../search/types/IHubCatalog";
import { IHubCollection } from "../../search/types/IHubCatalog";
import { WellKnownCollection } from "../../search/wellKnownCatalog";
import { IModel } from "../../hub-types";
import { SearchCategories } from "./types";
Expand All @@ -21,7 +21,7 @@ import { defaultSiteCollectionKeys } from "../defaultSiteCollectionKeys";
* NOTE: The changes made in this migration will not be persisted to AGO at this time
*
* @param model site model to migrate
* @returns a migrated model with default `IHubCollectionPersistance` objects added
* @returns a migrated model with default `IHubCollection` objects added
* to the catalog
*/
export function applyDefaultCollectionMigration(model: IModel): IModel {
Expand All @@ -44,9 +44,12 @@ export function applyDefaultCollectionMigration(model: IModel): IModel {
collection: key,
filters: [],
},
displayConfig: {
hidden: false,
},
};
return map;
}, {} as Record<string, IHubCollectionPersistance>);
}, {} as Record<string, IHubCollection>);
const searchCategoryToCollection: Partial<
Record<SearchCategories, WellKnownCollection>
> = {
Expand Down Expand Up @@ -86,7 +89,7 @@ export function applyDefaultCollectionMigration(model: IModel): IModel {
searchCategoryToCollection[searchCategory.key as SearchCategories];
const collection = baseCollectionMap[collectionKey];
collection.label = searchCategory.overrideText || null;
collection.hidden = searchCategory.hidden;
collection.displayConfig.hidden = !!searchCategory.hidden;
return collection;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WellKnownCollection } from "../../search";
import { IHubCollectionPersistance } from "../../search/types/IHubCatalog";
import { IHubCollection } from "../../search/types/IHubCatalog";
import { IModel } from "../../hub-types";
import { cloneObject } from "../../util";
import { SearchCategories } from "./types";
Expand Down Expand Up @@ -35,8 +35,7 @@ export function reflectCollectionsToSearchCategories(model: IModel) {
[SearchCategories.APPS_AND_MAPS]: "App,Map",
[SearchCategories.DOCUMENTS]: "Document",
};
const collections: IHubCollectionPersistance[] =
clone.data.catalog.collections;
const collections: IHubCollection[] = clone.data.catalog.collections;

const updatedSearchCategories = collections
// We don't want to persist any non-standard collection as a search category,
Expand All @@ -46,7 +45,7 @@ export function reflectCollectionsToSearchCategories(model: IModel) {
const searchCategoryKey =
collectionToSearchCategory[c.key as WellKnownCollection];
const updated: any = {
hidden: c.hidden,
hidden: !!c.displayConfig?.hidden,
key: searchCategoryKey,
queryParams: {
collection: searchCategoryToQueryParam[searchCategoryKey],
Expand Down
8 changes: 5 additions & 3 deletions packages/common/test/sites/HubSites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
cloneObject,
enrichSiteSearchResult,
fetchSite,
IHubCollectionPersistance,
IHubCollection,
IHubRequestOptions,
} from "../../src";
import * as slugUtils from "../../src/items/slugs";
Expand Down Expand Up @@ -477,13 +477,15 @@ describe("HubSites:", () => {
label: "My Datasets",
key: "dataset",
targetEntity: "item",
hidden: true,
scope: {
targetEntity: "item",
collection: "dataset",
filters: [],
},
} as IHubCollectionPersistance,
displayConfig: {
hidden: true,
},
} as IHubCollection,
];
const chk = await commonModule.updateSite(updatedSite, MOCK_HUB_REQOPTS);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IHubCollectionPersistance } from "../../../src/search/types/IHubCatalog";
import { IHubCollection } from "../../../src/search/types/IHubCatalog";
import { applyDefaultCollectionMigration } from "../../../src/sites/_internal/applyDefaultCollectionMigration";
import { SearchCategories } from "../../../src/sites/_internal/types";
import { IModel } from "../../../src/hub-types";
Expand Down Expand Up @@ -31,7 +31,7 @@ describe("applyDefaultCollectionMigration", () => {
it("Adds untouched default collections when no search categories are configured", () => {
const result = applyDefaultCollectionMigration(site);
const collectionKeys = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.key
(c: IHubCollection) => c.key
);
expect(collectionKeys).toEqual([
"all",
Expand All @@ -41,19 +41,13 @@ describe("applyDefaultCollectionMigration", () => {
"appAndMap",
]);
const collectionLabels = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.label
(c: IHubCollection) => c.label
);
expect(collectionLabels).toEqual([null, null, null, null, null]);
const hiddenStatuses = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.hidden
(c: IHubCollection) => c.displayConfig?.hidden
);
expect(hiddenStatuses).toEqual([
undefined,
true,
undefined,
undefined,
undefined,
]);
expect(hiddenStatuses).toEqual([false, true, false, false, false]);
});

it("Reorders, re-labels, and hides default collections when search categories are configured", () => {
Expand All @@ -78,7 +72,7 @@ describe("applyDefaultCollectionMigration", () => {
];
const result = applyDefaultCollectionMigration(site);
const collectionKeys = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.key
(c: IHubCollection) => c.key
);
// Note: 'all' collection is always prepended
expect(collectionKeys).toEqual([
Expand All @@ -90,14 +84,14 @@ describe("applyDefaultCollectionMigration", () => {
]);

const collectionLabels = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.label
(c: IHubCollection) => c.label
);
expect(collectionLabels).toEqual([null, null, null, "My Sites", "My Data"]);

const hiddenStatuses = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.hidden
(c: IHubCollection) => c.displayConfig.hidden
);
expect(hiddenStatuses).toEqual([undefined, undefined, true, false, false]);
expect(hiddenStatuses).toEqual([false, false, true, false, false]);
});

it("Handles when a site has the 'initiatives' search category saved", () => {
Expand All @@ -110,20 +104,20 @@ describe("applyDefaultCollectionMigration", () => {
];
const result = applyDefaultCollectionMigration(site);
const collectionKeys = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.key
(c: IHubCollection) => c.key
);
// Note: 'all' collection is always prepended
expect(collectionKeys).toEqual(["all", "site"]);

const collectionLabels = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.label
(c: IHubCollection) => c.label
);
expect(collectionLabels).toEqual([null, "My Initiatives"]);

const hiddenStatuses = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.hidden
(c: IHubCollection) => c.displayConfig.hidden
);
expect(hiddenStatuses).toEqual([undefined, true]);
expect(hiddenStatuses).toEqual([false, true]);
});

it("Omits unsupported search categories, like an explicit 'all' or events", () => {
Expand All @@ -139,19 +133,19 @@ describe("applyDefaultCollectionMigration", () => {
];
const result = applyDefaultCollectionMigration(site);
const collectionKeys = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.key
(c: IHubCollection) => c.key
);
// Note: 'all' collection can never be relabeled, hidden, or reordered
expect(collectionKeys).toEqual(["all"]);

const collectionLabels = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.label
(c: IHubCollection) => c.label
);
expect(collectionLabels).toEqual([null]);

const hiddenStatuses = result.data.catalog.collections.map(
(c: IHubCollectionPersistance) => c.hidden
(c: IHubCollection) => c.displayConfig.hidden
);
expect(hiddenStatuses).toEqual([undefined]);
expect(hiddenStatuses).toEqual([false]);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IHubCollectionPersistance } from "../../../src/search/types/IHubCatalog";
import { IHubCollection } from "../../../src/search/types/IHubCatalog";
import { WellKnownCollection } from "../../../src/search/wellKnownCatalog";
import { reflectCollectionsToSearchCategories } from "../../../src/sites/_internal/reflectCollectionsToSearchCategories";
import { SearchCategories } from "../../../src/sites/_internal/types";
Expand Down Expand Up @@ -33,24 +33,39 @@ describe("reflectCollectionsToSearchCategories", () => {
label: null,
key: "dataset",
targetEntity: "item",
hidden: true,
scope: {
targetEntity: "item",
collection: "dataset",
filters: [],
},
} as IHubCollectionPersistance,
displayConfig: {
hidden: true,
},
} as IHubCollection,
{
label: null,
key: "document",
targetEntity: "item",
hidden: false,
displayConfig: {
hidden: false,
},
scope: {
targetEntity: "item",
collection: "document",
filters: [],
},
} as IHubCollectionPersistance,
} as IHubCollection,
{
label: null,
key: "appAndMap",
targetEntity: "item",
// intentionally leaving out displayConfig.hidden for branch coverage
scope: {
targetEntity: "item",
collection: "appAndMap",
filters: [],
},
} as IHubCollection,
];

const result = reflectCollectionsToSearchCategories(site);
Expand All @@ -69,6 +84,13 @@ describe("reflectCollectionsToSearchCategories", () => {
collection: "Document",
},
},
{
key: SearchCategories.APPS_AND_MAPS,
hidden: false,
queryParams: {
collection: "App,Map",
},
},
]);
});
it("handles re-labeled collections", () => {
Expand All @@ -77,24 +99,28 @@ describe("reflectCollectionsToSearchCategories", () => {
label: "My Cool Sites!",
key: "site",
targetEntity: "item",
hidden: false,
displayConfig: {
hidden: false,
},
scope: {
targetEntity: "item",
collection: "site",
filters: [],
},
} as IHubCollectionPersistance,
} as IHubCollection,
{
label: "Apps & Maps",
key: "appAndMap",
targetEntity: "item",
hidden: false,
displayConfig: {
hidden: false,
},
scope: {
targetEntity: "item",
collection: "appAndMap",
filters: [],
},
} as IHubCollectionPersistance,
} as IHubCollection,
];

const result = reflectCollectionsToSearchCategories(site);
Expand Down Expand Up @@ -124,36 +150,42 @@ describe("reflectCollectionsToSearchCategories", () => {
label: null,
key: "dataset",
targetEntity: "item",
hidden: false,
displayConfig: {
hidden: false,
},
scope: {
targetEntity: "item",
collection: "dataset",
filters: [],
},
} as IHubCollectionPersistance,
} as IHubCollection,
// 'all' _can_ be converted to a search category, but we explicitly do not persist it
{
label: null,
key: "all",
targetEntity: "item",
hidden: false,
displayConfig: {
hidden: false,
},
scope: {
targetEntity: "item",
collection: "all" as WellKnownCollection,
filters: [],
},
} as IHubCollectionPersistance,
} as IHubCollection,
// Customer-defined collection, cannot be converted to search category
{
label: "My Custom Collection",
key: "custom-collection",
targetEntity: "event",
hidden: false,
displayConfig: {
hidden: false,
},
scope: {
targetEntity: "event",
filters: [],
},
} as IHubCollectionPersistance,
} as IHubCollection,
];

const result = reflectCollectionsToSearchCategories(site);
Expand Down
Loading