-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hub-common): add support for configuring entity references for E… (
- Loading branch information
1 parent
31fb3ea
commit 9435382
Showing
28 changed files
with
905 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/common/src/events/_internal/buildEventAssociations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { IHubRequestOptions } from "../../types"; | ||
import { ICreateEventAssociation } from "../api"; | ||
import { searchItems } from "@esri/arcgis-rest-portal"; | ||
|
||
export async function buildEventAssociations( | ||
referencedContentIdsByType: Array<{ entityId: string; entityType: string }>, | ||
referencedContentIds: string[], | ||
hubRequestOptions: IHubRequestOptions | ||
): Promise<ICreateEventAssociation[]> { | ||
// filter out content that was removed | ||
const associations = referencedContentIdsByType.filter(({ entityId }) => | ||
referencedContentIds.includes(entityId) | ||
); | ||
// get content ids being added | ||
const added = referencedContentIds.filter( | ||
(referencedContentId) => | ||
!associations.find(({ entityId }) => entityId === referencedContentId) | ||
); | ||
if (added.length) { | ||
// fetch the content being added | ||
const { results } = await searchItems({ | ||
q: added.map((id) => `id:${id}`).join(" OR "), | ||
num: added.length, | ||
authentication: hubRequestOptions.authentication, | ||
}); | ||
// map content to ICreateEventAssociation structures | ||
const addedAssociations = results.map(({ id, type }) => ({ | ||
entityId: id, | ||
entityType: type, | ||
})); | ||
associations.push(...addedAssociations); | ||
} | ||
return associations as ICreateEventAssociation[]; | ||
} |
72 changes: 72 additions & 0 deletions
72
packages/common/src/events/_internal/buildReferencedContentSchema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { IArcGISContext } from "../../ArcGISContext"; | ||
import { IUiSchemaElement } from "../../core/schemas/types"; | ||
import { getWellKnownCatalog } from "../../search/wellKnownCatalog"; | ||
|
||
export function buildReferencedContentSchema( | ||
i18nScope: string, | ||
context: IArcGISContext, | ||
label?: string | ||
): IUiSchemaElement { | ||
return { | ||
scope: "/properties/referencedContentIds", | ||
type: "Control", | ||
label, | ||
options: { | ||
control: "hub-field-input-gallery-picker", | ||
helperText: { | ||
labelKey: `${i18nScope}.fields.referencedContent.helperText.label`, | ||
}, | ||
targetEntity: "item", | ||
catalogs: [ | ||
getWellKnownCatalog( | ||
`${i18nScope}.fields.referencedContent`, | ||
"organization", | ||
"item", | ||
{ | ||
user: context.currentUser, | ||
collectionNames: ["site", "initiative", "project"], | ||
filters: [], | ||
context, | ||
} | ||
), | ||
], | ||
facets: [ | ||
{ | ||
label: `{{${i18nScope}.fields.referencedContent.facets.from.label:translate}}`, | ||
key: "from", | ||
display: "single-select", | ||
operation: "OR", | ||
options: [ | ||
{ | ||
label: `{{${i18nScope}.fields.referencedContent.facets.from.myContent.label:translate}}`, | ||
key: "myContent", | ||
selected: true, | ||
predicates: [ | ||
{ | ||
owner: context.currentUser.username, | ||
}, | ||
], | ||
}, | ||
{ | ||
label: `{{${i18nScope}.fields.referencedContent.facets.from.myOrganization.label:translate}}`, | ||
key: "myOrganization", | ||
selected: false, | ||
predicates: [ | ||
{ | ||
orgId: context.currentUser.orgId, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
label: `{{${i18nScope}.fields.referencedContent.facets.access.label:translate}}`, | ||
key: "access", | ||
field: "access", | ||
display: "multi-select", | ||
operation: "OR", | ||
}, | ||
], | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.