Skip to content

Commit

Permalink
Merge branch 'master' into 11062/set-location-name
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannaeapicella authored Oct 14, 2024
2 parents c7df591 + 4c8a762 commit 12e7b46
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 127 deletions.
14 changes: 14 additions & 0 deletions packages/common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# @esri/hub-common [14.213.0](https://github.com/Esri/hub.js/compare/@esri/hub-common@14.212.0...@esri/hub-common@14.213.0) (2024-10-11)


### Features

* **hub-discussions:** discussions can now query by orgId ([#1685](https://github.com/Esri/hub.js/issues/1685)) ([ae51c2f](https://github.com/Esri/hub.js/commit/ae51c2fe8498fe6330874568093a4e27b868ac0c))

# @esri/hub-common [14.212.0](https://github.com/Esri/hub.js/compare/@esri/hub-common@14.211.0...@esri/hub-common@14.212.0) (2024-10-11)


### Features

* events processFilters support occurrence && group to sharedToGroup ([#1683](https://github.com/Esri/hub.js/issues/1683)) ([44bb6f2](https://github.com/Esri/hub.js/commit/44bb6f2dc8acfcc75434b870c84441486671d73c))

# @esri/hub-common [14.211.0](https://github.com/Esri/hub.js/compare/@esri/hub-common@14.210.0...@esri/hub-common@14.211.0) (2024-10-09)


Expand Down
4 changes: 2 additions & 2 deletions packages/common/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@esri/hub-common",
"version": "14.211.0",
"version": "14.213.0",
"description": "Common TypeScript types and utility functions for @esri/hub.js.",
"main": "dist/node/index.js",
"module": "dist/esm/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/discussions/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ export interface ISearchChannels
access?: SharingAccess[];
relations?: ChannelRelation[];
name?: string;
orgId?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,12 @@ export async function processFilters(
if (tags?.length) {
processedFilters.tags = tags;
}
const groupIds = getPredicateValuesByKey<string>(filters, "group");
const groupIds = getOptionalPredicateStringsByKey(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 ")})`,
num: groupIds.length,
...requestOptions,
});
const { readGroupIds, editGroupIds } = results.reduce(
(acc, group) => {
const key = isUpdateGroup(group) ? "editGroupIds" : "readGroupIds";
return { ...acc, [key]: [...acc[key], group.id] };
},
{ readGroupIds: [], editGroupIds: [] }
);
if (readGroupIds.length) {
processedFilters.readGroups = readGroupIds.join(",");
}
if (editGroupIds.length) {
processedFilters.editGroups = editGroupIds.join(",");
}
if (groupIds?.length) {
// We are explicitly sending groupIds to sharedToGroups
processedFilters.sharedToGroups = groupIds;
} else {
// individual readGroupId & editGroupId filters
const readGroupIds = getOptionalPredicateStringsByKey(
Expand All @@ -95,6 +79,8 @@ export async function processFilters(
processedFilters.editGroups = editGroupIds;
}
}
// NOTE: previously notGroup was an inverse of group, but now they are subtly different
// We do not yet have an inverse of sharedToGroups.
const notGroupIds = getPredicateValuesByKey<string>(filters, "notGroup");
// if a notGroup was provided, we prioritize that over individual notReadGroupId or notEditGroupId
// filters to prevent collisions
Expand Down Expand Up @@ -159,13 +145,17 @@ export async function processFilters(
);
// if a startDateRange was provided, we prioritize that over individual startDateBefore or startDateAfter
// filters to prevent collisions
// We are explicitly checking if the to and from values are present
// Because w/ Occurrence, we can have just to or from values
if (startDateRange.length) {
processedFilters.startDateTimeBefore = new Date(
startDateRange[0].to
).toISOString();
processedFilters.startDateTimeAfter = new Date(
startDateRange[0].from
).toISOString();
startDateRange[0].to &&
(processedFilters.startDateTimeBefore = new Date(
startDateRange[0].to
).toISOString());
startDateRange[0].from &&
(processedFilters.startDateTimeAfter = new Date(
startDateRange[0].from
).toISOString());
} else {
// individual startDateBefore & startDateAfter filters
const startDateBefore = getPredicateValuesByKey<string | number>(
Expand Down Expand Up @@ -193,13 +183,17 @@ export async function processFilters(
);
// if a endDateRange was provided, we prioritize that over individual endDateBefore or endDateAfter
// filters to prevent collisions
// We are explicitly checking if the to and from values are present
// Because w/ Occurrence, we can have just to or from values
if (endDateRange.length) {
processedFilters.endDateTimeBefore = new Date(
endDateRange[0].to
).toISOString();
processedFilters.endDateTimeAfter = new Date(
endDateRange[0].from
).toISOString();
endDateRange[0].to &&
(processedFilters.endDateTimeBefore = new Date(
endDateRange[0].to
).toISOString());
endDateRange[0].from &&
(processedFilters.endDateTimeAfter = new Date(
endDateRange[0].from
).toISOString());
} else {
// individual endDateBefore & endDateAfter filters
const endDateBefore = getPredicateValuesByKey<string | number>(
Expand All @@ -221,5 +215,25 @@ export async function processFilters(
).toISOString();
}
}

// If there's an occurrence filter, we need to adjust the startDateTimeBefore, startDateTimeAfter
// Depending on the occurrence.
const occurrence = getPredicateValuesByKey<string>(filters, "occurrence");
if (occurrence.length) {
occurrence.forEach((o) => {
switch (o) {
case "upcoming":
processedFilters.startDateTimeAfter = new Date().toISOString();
break;
case "past":
processedFilters.endDateTimeBefore = new Date().toISOString();
break;
case "inProgress":
processedFilters.startDateTimeBefore = new Date().toISOString();
processedFilters.endDateTimeAfter = new Date().toISOString();
break;
}
});
}
return processedFilters;
}
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,9 @@ describe("processFilters", () => {
[{ predicates: [] }],
hubRequestOptions
);
expect(result.readGroups).toBeUndefined();
expect(result.editGroups).toBeUndefined();
expect(result.sharedToGroups).toBeUndefined();
});
it("should return readGroups and editGroups", async () => {
const searchGroupsSpy = spyOn(
arcgisRestPortal,
"searchGroups"
).and.returnValue(
Promise.resolve({ results: [editGroup1, readGroup1, editGroup2] })
);
it("should return returnToGroups if group has been supplied", async () => {
const result = await processFilters(
[
{
Expand All @@ -518,89 +511,8 @@ describe("processFilters", () => {
],
hubRequestOptions
);
expect(searchGroupsSpy).toHaveBeenCalledTimes(1);
expect(searchGroupsSpy).toHaveBeenCalledWith({
q: `id:(${[editGroup1.id, readGroup1.id, editGroup2.id].join(" OR ")})`,
num: 3,
...hubRequestOptions,
});
expect(result.readGroups).toEqual(readGroup1.id);
expect(result.editGroups).toEqual(
[editGroup1.id, editGroup2.id].join(",")
);
});
it("should filter out inaccessible groups", async () => {
const searchGroupsSpy = spyOn(
arcgisRestPortal,
"searchGroups"
).and.returnValue(Promise.resolve({ results: [] }));
const result = await processFilters(
[
{
predicates: [
{
group: editGroup1.id,
},
],
},
{
predicates: [
{
group: [readGroup1.id, editGroup2.id],
},
],
},
],
hubRequestOptions
);
expect(searchGroupsSpy).toHaveBeenCalledTimes(1);
expect(searchGroupsSpy).toHaveBeenCalledWith({
q: `id:(${[editGroup1.id, readGroup1.id, editGroup2.id].join(" OR ")})`,
num: 3,
...hubRequestOptions,
});
expect(result.readGroups).toBeUndefined();
expect(result.editGroups).toBeUndefined();
});
it("should be prioritized over individual readGroupId and editGroupId", async () => {
const searchGroupsSpy = spyOn(
arcgisRestPortal,
"searchGroups"
).and.returnValue(
Promise.resolve({ results: [editGroup1, readGroup1, editGroup2] })
);
const result = await processFilters(
[
{
predicates: [
{
group: editGroup1.id,
},
{
readGroupId: "some-other-read-group-id",
},
],
},
{
predicates: [
{
group: [readGroup1.id, editGroup2.id],
editGroupId: ["some-other-edit-group-id"],
},
],
},
],
hubRequestOptions
);
expect(searchGroupsSpy).toHaveBeenCalledTimes(1);
expect(searchGroupsSpy).toHaveBeenCalledWith({
q: `id:(${[editGroup1.id, readGroup1.id, editGroup2.id].join(" OR ")})`,
num: 3,
...hubRequestOptions,
});
expect(result.readGroups).toEqual(readGroup1.id);
expect(result.editGroups).toEqual(
[editGroup1.id, editGroup2.id].join(",")
expect(result.sharedToGroups).toEqual(
[editGroup1.id, readGroup1.id, editGroup2.id].join(",")
);
});
});
Expand Down Expand Up @@ -1101,4 +1013,67 @@ describe("processFilters", () => {
expect(result.endDateTimeAfter).toEqual("2024-04-28T04:00:00.000Z");
});
});
describe("occurrence", () => {
const mockedDate = new Date(1711987200000);
beforeAll(() => {
jasmine.clock().mockDate(mockedDate);
});
afterAll(() => {
jasmine.clock().uninstall();
});
it("should return undefined", async () => {
const result = await processFilters(
[{ predicates: [] }],
hubRequestOptions
);
expect(result.startDateTimeBefore).toBeUndefined();
expect(result.startDateTimeAfter).toBeUndefined();
});
it("should handle upcoming", async () => {
const result = await processFilters(
[
{
predicates: [
{
occurrence: "upcoming",
},
],
},
],
hubRequestOptions
);
expect(result.startDateTimeAfter).toEqual(mockedDate.toISOString());
});
it("should handle past", async () => {
const result = await processFilters(
[
{
predicates: [
{
occurrence: "past",
},
],
},
],
hubRequestOptions
);
expect(result.endDateTimeBefore).toEqual(mockedDate.toISOString());
});
it("should handle inProgress", async () => {
const result = await processFilters(
[
{
predicates: [
{
occurrence: "inProgress",
},
],
},
],
hubRequestOptions
);
expect(result.startDateTimeBefore).toEqual(mockedDate.toISOString());
expect(result.endDateTimeAfter).toEqual(mockedDate.toISOString());
});
});
});

0 comments on commit 12e7b46

Please sign in to comment.