Skip to content

Commit

Permalink
feat(hub-common): add support to hubSearch for searching for events u…
Browse files Browse the repository at this point in the history
…sing orgId, notGroup, notReadGr

affects: @esri/hub-common

ISSUES CLOSED: 10959
  • Loading branch information
rweber-esri committed Sep 13, 2024
1 parent a7686fc commit f18925d
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 30 deletions.
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.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export async function processFilters(
if (term.length) {
processedFilters.title = term[0];
}
const orgId = getPredicateValuesByKey<string>(filters, "orgId");
if (orgId.length) {
processedFilters.orgId = orgId[0];
}
const categories = getOptionalPredicateStringsByKey(filters, "categories");
if (categories?.length) {
processedFilters.categories = categories;
Expand All @@ -53,6 +57,8 @@ export async function processFilters(
processedFilters.tags = tags;
}
const groupIds = getPredicateValuesByKey<string>(filters, "group");
// if a group was provided, we prioritize that over individual readGroupId or editGroupId
// filters to prevent collisions
if (groupIds.length) {
const { results } = await searchGroups({
q: `id:(${groupIds.join(" OR ")})`,
Expand All @@ -73,6 +79,7 @@ export async function processFilters(
processedFilters.editGroups = editGroupIds.join(",");
}
} else {
// individual readGroupId & editGroupId filters
const readGroupIds = getOptionalPredicateStringsByKey(
filters,
"readGroupId"
Expand All @@ -88,6 +95,47 @@ export async function processFilters(
processedFilters.editGroups = editGroupIds;
}
}
const notGroupIds = getPredicateValuesByKey<string>(filters, "notGroup");
// if a notGroup was provided, we prioritize that over individual notReadGroupId or notEditGroupId
// filters to prevent collisions
if (notGroupIds.length) {
const { results } = await searchGroups({
q: `id:(${notGroupIds.join(" OR ")})`,
num: notGroupIds.length,
...requestOptions,
});
const { notReadGroupIds, notEditGroupIds } = results.reduce(
(acc, group) => {
const key = isUpdateGroup(group)
? "notEditGroupIds"
: "notReadGroupIds";
return { ...acc, [key]: [...acc[key], group.id] };
},
{ notReadGroupIds: [], notEditGroupIds: [] }
);
if (notReadGroupIds.length) {
processedFilters.withoutReadGroups = notReadGroupIds.join(",");
}
if (notEditGroupIds.length) {
processedFilters.withoutEditGroups = notEditGroupIds.join(",");
}
} else {
// individual notReadGroupId & notEditGroupId filters
const notReadGroupIds = getOptionalPredicateStringsByKey(
filters,
"notReadGroupId"
);
if (notReadGroupIds?.length) {
processedFilters.withoutReadGroups = notReadGroupIds;
}
const notEditGroupIds = getOptionalPredicateStringsByKey(
filters,
"notEditGroupId"
);
if (notEditGroupIds?.length) {
processedFilters.withoutEditGroups = notEditGroupIds;
}
}
const attendanceType = getOptionalPredicateStringsByKey(
filters,
"attendanceType"
Expand Down Expand Up @@ -146,13 +194,9 @@ export async function processFilters(
// if a endDateRange was provided, we prioritize that over individual endDateBefore or endDateAfter
// filters to prevent collisions
if (endDateRange.length) {
// TODO: remove below ts-ignore once https://devtopia.esri.com/dc/hub/issues/11097 is resolved
// @ts-ignore
processedFilters.endDateTimeBefore = new Date(
endDateRange[0].to
).toISOString();
// TODO: remove below ts-ignore once https://devtopia.esri.com/dc/hub/issues/11097 is resolved
// @ts-ignore
processedFilters.endDateTimeAfter = new Date(
endDateRange[0].from
).toISOString();
Expand All @@ -163,8 +207,6 @@ export async function processFilters(
"endDateBefore"
);
if (endDateBefore.length) {
// TODO: remove below ts-ignore once https://devtopia.esri.com/dc/hub/issues/11097 is resolved
// @ts-ignore
processedFilters.endDateTimeBefore = new Date(
endDateBefore[0]
).toISOString();
Expand All @@ -174,8 +216,6 @@ export async function processFilters(
"endDateAfter"
);
if (endDateAfter.length) {
// TODO: remove below ts-ignore once https://devtopia.esri.com/dc/hub/issues/11097 is resolved
// @ts-ignore
processedFilters.endDateTimeAfter = new Date(
endDateAfter[0]
).toISOString();
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/search/_internal/hubSearchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import { processFilters } from "./hubEventsHelpers/processFilters";
* - categories: string | string[];
* - tags: string | string[];
* - group: string | string[];
* - notGroup: string | string[];
* - readGroupId: string | string[];
* - notReadGroupId: string | string[];
* - editGroupId: string | string[];
* - notEditGroupId: string | string[];
* - attendanceType: 'virtual' | 'in_person' | Array<'virtual' | 'in_person'>;
* - owner: string | string[];
* - status: 'planned' | 'canceled' | 'removed' | Array<'planned' | 'canceled' | 'removed'>;
Expand All @@ -32,6 +35,7 @@ import { processFilters } from "./hubEventsHelpers/processFilters";
* - endDateRange: IDateRange<string | number>;
* - endDateBefore: string | number;
* - endDateAfter: string | number;
* - orgId: string;
* Currently supported sort fields include:
* - created
* - modified
Expand Down
Loading

0 comments on commit f18925d

Please sign in to comment.