Skip to content

Commit

Permalink
feat: search result has rawResult prop (#1336)
Browse files Browse the repository at this point in the history
* feat: search result has rawResult prop

* refactor: remove unused import

* refactor: remove unused import - again

* refactor: make rawResult optional so this is not a breaking change
  • Loading branch information
dbouwman authored Nov 17, 2023
1 parent 0aa5fad commit c8a41f4
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/common/src/content/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export async function enrichContentSearchResult(
siteRelative: "not-implemented",
thumbnail: "not-implemented",
},
rawResult: item,
};

// default includes
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/groups/HubGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function enrichGroupSearchResult(
siteRelative: "not-implemented",
thumbnail: "not-implemented",
},
rawResult: group,
};

// Informal Enrichments - basically adding type-specific props
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/initiative-templates/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export async function enrichInitiativeTemplateSearchResult(
thumbnail: "not-implemented",
workspaceRelative: "not-implemented",
},
rawResult: item,
};

// TODO: reimplement enrichment fetching when we know what enrichments we're looking for
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/initiatives/HubInitiatives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export async function enrichInitiativeSearchResult(
thumbnail: "not-implemented",
workspaceRelative: "not-implemented",
},
rawResult: item,
};

// default includes
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/pages/HubPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export async function enrichPageSearchResult(
siteRelative: "not-implemented",
thumbnail: "not-implemented",
},
rawResult: item,
};

// default includes
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/projects/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export async function enrichProjectSearchResult(
thumbnail: "not-implemented",
workspaceRelative: "not-implemented",
},
rawResult: item,
};

// default includes
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/search/_internal/hubSearchChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export const toHubSearchResult = async (
)
: [],
},
rawResult: channel,
};
};
return {
Expand Down
13 changes: 13 additions & 0 deletions packages/common/src/search/types/IHubSearchResult.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { IGroup, IItem, IUser } from "@esri/arcgis-rest-portal";
import { AccessLevel, IHubEntityBase } from "../../core";
import { HubFamily, IHubGeography } from "../../types";
import { IOgcItem } from "../_internal/hubSearchItemsHelpers/interfaces";
import { IChannel } from "../../discussions/api/types";

/**
* Standardized light-weight search result structure, applicable to all
Expand Down Expand Up @@ -44,6 +47,16 @@ export interface IHubSearchResult extends IHubEntityBase {
*/
geometry?: IHubGeography;

/**
* Raw result object returned from the search.
* This allows downstream processing to access
* additional properties that may not be
* explicitly defined in this interface
* Note: We will need to cast to the approproate type
* in order to access the properties
*/
rawResult?: IItem | IGroup | IUser | IOgcItem | IChannel;

/** Allow any additional properties to be added */
[key: string]: any;
}
1 change: 1 addition & 0 deletions packages/common/src/sites/HubSites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ export async function enrichSiteSearchResult(
siteRelative: "not-implemented",
thumbnail: "not-implemented",
},
rawResult: item,
};

// default includes
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/templates/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export async function enrichTemplateSearchResult(
thumbnail: "not-implemented",
workspaceRelative: "not-implemented",
},
rawResult: item,
};

// 1. optionally enrich the template item with
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/users/HubUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export async function enrichUserSearchResult(
siteRelative: "not-implemented",
thumbnail: null,
},
rawResult: user,
};
// Group Memberships need these additional properties
if (user.memberType) {
Expand Down
1 change: 1 addition & 0 deletions packages/common/test/initiative-templates/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const INITIATIVE_TEMPLATE_HUB_SEARCH_RESULT: IHubSearchResult = {
thumbnail: "https://thumbnail/mock-thumbnail.png",
workspaceRelative: "/mock-relative-workspace-url",
},
rawResult: INITIATIVE_TEMPLATE_ITEM,
};

export const INITIATIVE_TEMPLATE_DATA = {
Expand Down
1 change: 1 addition & 0 deletions packages/common/test/initiatives/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const INITIATIVE_HUB_SEARCH_RESULT: IHubSearchResult = {
thumbnail: "https://thumbnail/mock-thumbnail.png",
workspaceRelative: "/mock-relative-workspace-url",
},
rawResult: INITIATIVE_ITEM,
};

export const INITIATIVE_DATA = {
Expand Down
1 change: 1 addition & 0 deletions packages/common/test/projects/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const PROJECT_HUB_SEARCH_RESULT: IHubSearchResult = {
thumbnail: "https://thumbnail/mock-thumbnail.png",
workspaceRelative: "/mock-relative-workspace-url",
},
rawResult: PROJECT_ITEM,
};

export const PROJECT_DATA = {
Expand Down
2 changes: 2 additions & 0 deletions packages/common/test/search/_internal/hubSearchItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ describe("hubSearchItems Module |", () => {
thumbnail:
"https://www.arcgis.com/sharing/rest/content/items/f4bcc/info/thumbnail/hub_thumbnail_1658341016537.png",
},
// TODO: fill this and add some verification
rawResult: ogcItemsResponse.features[0].properties as IOgcItem,
},
];

Expand Down
1 change: 1 addition & 0 deletions packages/common/test/templates/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const TEMPLATE_HUB_SEARCH_RESULT: IHubSearchResult = {
thumbnail: "https://thumbnail/mock-thumbnail.png",
workspaceRelative: "/mock-relative-workspace-url",
},
rawResult: TEMPLATE_ITEM,
};

export const TEMPLATE_DATA = {};
Expand Down
1 change: 1 addition & 0 deletions packages/common/test/users/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ export const USER_HUB_SEARCH_RESULT: IHubSearchResult = {
index: 2,
typeKeywords: ["User"],
tags: ["tag1", "tag2"],
rawResult: USER,
};

0 comments on commit c8a41f4

Please sign in to comment.