-
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 attendees settings pane (#1475)
Co-authored-by: Randy Weber <rweber@esri.com>
- Loading branch information
1 parent
568de71
commit 0c49423
Showing
29 changed files
with
1,038 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
18 changes: 18 additions & 0 deletions
18
packages/common/src/events/_internal/EventSchemaAttendeesSettings.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,18 @@ | ||
import { IConfigurationSchema } from "../../core/schemas/types"; | ||
|
||
export const buildSchema = (): IConfigurationSchema => { | ||
return { | ||
properties: { | ||
allowRegistration: { | ||
type: "boolean", | ||
enum: [true, false], | ||
default: true, | ||
}, | ||
notifyAttendees: { | ||
type: "boolean", | ||
enum: [true, false], | ||
default: true, | ||
}, | ||
}, | ||
} as IConfigurationSchema; | ||
}; |
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
64 changes: 64 additions & 0 deletions
64
packages/common/src/events/_internal/EventUiSchemaAttendeesSettings.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,64 @@ | ||
import { IArcGISContext } from "../../ArcGISContext"; | ||
import { EntityEditorOptions } from "../../core/schemas/internal/EditorOptions"; | ||
import { IUiSchema } from "../../core/schemas/types"; | ||
|
||
export const buildUiSchema = async ( | ||
i18nScope: string, | ||
options: EntityEditorOptions, | ||
context: IArcGISContext | ||
): Promise<IUiSchema> => { | ||
return { | ||
type: "Layout", | ||
elements: [ | ||
{ | ||
type: "Section", | ||
elements: [ | ||
{ | ||
labelKey: `${i18nScope}.fields.allowRegistration.label`, | ||
scope: "/properties/allowRegistration", | ||
type: "Control", | ||
options: { | ||
control: "hub-field-input-tile-select", | ||
type: "radio", | ||
helperText: { | ||
labelKey: `${i18nScope}.fields.allowRegistration.helperText`, | ||
}, | ||
labels: [ | ||
`{{${i18nScope}.fields.allowRegistration.enabled.label:translate}}`, | ||
`{{${i18nScope}.fields.allowRegistration.disabled.label:translate}}`, | ||
], | ||
descriptions: [ | ||
`{{${i18nScope}.fields.allowRegistration.enabled.description:translate}}`, | ||
`{{${i18nScope}.fields.allowRegistration.disabled.description:translate}}`, | ||
], | ||
icons: ["user-calendar", "circle-disallowed"], | ||
layout: "horizontal", | ||
}, | ||
}, | ||
{ | ||
labelKey: `${i18nScope}.fields.notifyAttendees.label`, | ||
scope: "/properties/notifyAttendees", | ||
type: "Control", | ||
options: { | ||
control: "hub-field-input-tile-select", | ||
type: "radio", | ||
helperText: { | ||
labelKey: `${i18nScope}.fields.notifyAttendees.helperText`, | ||
}, | ||
labels: [ | ||
`{{${i18nScope}.fields.notifyAttendees.enabled.label:translate}}`, | ||
`{{${i18nScope}.fields.notifyAttendees.disabled.label:translate}}`, | ||
], | ||
descriptions: [ | ||
`{{${i18nScope}.fields.notifyAttendees.enabled.description:translate}}`, | ||
`{{${i18nScope}.fields.notifyAttendees.disabled.description:translate}}`, | ||
], | ||
icons: ["envelope", "circle-disallowed"], | ||
layout: "horizontal", | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
}; |
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
52 changes: 52 additions & 0 deletions
52
packages/common/src/search/_internal/hubEventsHelpers/eventAttendeeToSearchResult.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,52 @@ | ||
import { IHubSearchResult } from "../../types/IHubSearchResult"; | ||
import { IRegistration } from "../../../events/api/orval/api/orval-events"; | ||
import { AccessLevel } from "../../../core"; | ||
import { getUser, IUser } from "@esri/arcgis-rest-portal"; | ||
import { IHubSearchOptions } from "../../types/IHubSearchOptions"; | ||
import { getUserHomeUrl } from "../../../urls/getUserHomeUrl"; | ||
import { getUserThumbnailUrl } from "../../utils"; | ||
|
||
/** | ||
* Transforms a given event attendee into a IHubSearchResult | ||
* @param attendee | ||
* @returns | ||
*/ | ||
export async function eventAttendeeToSearchResult( | ||
attendee: IRegistration, | ||
options: IHubSearchOptions | ||
): Promise<IHubSearchResult> { | ||
const [user, creator] = await Promise.all([ | ||
getUser({ | ||
username: attendee.userId, | ||
...options.requestOptions, | ||
}), | ||
getUser({ | ||
username: attendee.createdById, | ||
...options.requestOptions, | ||
}), | ||
]); | ||
return { | ||
id: attendee.id.toString(), | ||
access: user.access as AccessLevel, | ||
name: user.fullName, | ||
createdDate: new Date(attendee.createdAt), | ||
createdDateSource: "attendee.createdAt", | ||
updatedDate: new Date(attendee.updatedAt), | ||
updatedDateSource: "attendee.updatedAt", | ||
type: "Event Attendee", | ||
family: "eventAttendee", | ||
owner: creator.username, | ||
rawResult: attendee, | ||
links: { | ||
self: getUserHomeUrl(user.username, options.requestOptions), | ||
siteRelative: `/people/${user.username}`, | ||
thumbnail: user.thumbnail | ||
? getUserThumbnailUrl( | ||
options.requestOptions.portal, | ||
user, | ||
options.requestOptions.authentication?.token | ||
) | ||
: null, | ||
}, | ||
}; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/common/src/search/_internal/hubEventsHelpers/getOptionalPredicateStringsByKey.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,14 @@ | ||
import { unique } from "../../../util"; | ||
import { IFilter } from "../../types/IHubCatalog"; | ||
import { getPredicateValuesByKey } from "./getPredicateValuesByKey"; | ||
|
||
export const getOptionalPredicateStringsByKey = ( | ||
filters: IFilter[], | ||
predicateKey: string | ||
): string => { | ||
const predicateValues = getPredicateValuesByKey(filters, predicateKey); | ||
const str = predicateValues.filter(unique).join(","); | ||
if (str) { | ||
return str; | ||
} | ||
}; |
17 changes: 17 additions & 0 deletions
17
packages/common/src/search/_internal/hubEventsHelpers/getPredicateValuesByKey.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,17 @@ | ||
import { IFilter } from "../../types/IHubCatalog"; | ||
|
||
export const getPredicateValuesByKey = ( | ||
filters: IFilter[], | ||
predicateKey: string | ||
): any[] => { | ||
const toPredicateValuesByKey = (a1: any[], filter: IFilter): any[] => | ||
filter.predicates.reduce<any[]>( | ||
(a2, predicate) => | ||
Object.entries(predicate).reduce( | ||
(a3, [key, val]) => (key === predicateKey ? [...a3, val] : a3), | ||
a2 | ||
), | ||
a1 | ||
); | ||
return filters.reduce(toPredicateValuesByKey, []); | ||
}; |
65 changes: 65 additions & 0 deletions
65
packages/common/src/search/_internal/hubEventsHelpers/processAttendeeFilters.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,65 @@ | ||
import { | ||
EventAttendanceType, | ||
GetRegistrationsParams, | ||
RegistrationRole, | ||
RegistrationStatus, | ||
} from "../../../events/api/types"; | ||
import { IQuery } from "../../types"; | ||
import { getOptionalPredicateStringsByKey } from "./getOptionalPredicateStringsByKey"; | ||
import { getPredicateValuesByKey } from "./getPredicateValuesByKey"; | ||
|
||
export function processAttendeeFilters( | ||
query: IQuery | ||
): Partial<GetRegistrationsParams> { | ||
const processedFilters: Partial<GetRegistrationsParams> = { | ||
eventId: query.properties.eventId, | ||
}; | ||
const useElseJoin = (value: string, defaults: string[]): string => | ||
value?.length ? value : defaults.map((val) => val.toLowerCase()).join(","); | ||
|
||
const term = getPredicateValuesByKey(query.filters, "term"); | ||
if (term.length) { | ||
// TODO: remove ts-ignore once GetEventsParams supports filtering by username, firstName, lastName https://devtopia.esri.com/dc/hub/issues/10153 | ||
// @ts-ignore | ||
processedFilters.name = term[0]; | ||
} | ||
|
||
processedFilters.type = useElseJoin( | ||
getOptionalPredicateStringsByKey(query.filters, "attendanceType"), | ||
[EventAttendanceType.VIRTUAL, EventAttendanceType.IN_PERSON] | ||
); | ||
|
||
processedFilters.role = useElseJoin( | ||
getOptionalPredicateStringsByKey(query.filters, "role"), | ||
[ | ||
RegistrationRole.OWNER, | ||
RegistrationRole.ORGANIZER, | ||
RegistrationRole.ATTENDEE, | ||
] | ||
); | ||
|
||
processedFilters.status = useElseJoin( | ||
getOptionalPredicateStringsByKey(query.filters, "status"), | ||
[ | ||
RegistrationStatus.PENDING, | ||
RegistrationStatus.ACCEPTED, | ||
RegistrationStatus.DECLINED, | ||
RegistrationStatus.BLOCKED, | ||
] | ||
); | ||
|
||
const updatedDateRange = getPredicateValuesByKey( | ||
query.filters, | ||
"updatedDateRange" | ||
); | ||
if (updatedDateRange.length) { | ||
processedFilters.updatedAtBefore = new Date( | ||
updatedDateRange[0].to | ||
).toISOString(); | ||
processedFilters.updatedAtAfter = new Date( | ||
updatedDateRange[0].from | ||
).toISOString(); | ||
} | ||
|
||
return processedFilters; | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/common/src/search/_internal/hubEventsHelpers/processAttendeeOptions.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,32 @@ | ||
import { | ||
GetRegistrationsParams, | ||
RegistrationSort, | ||
SortOrder, | ||
} from "../../../events/api/types"; | ||
import { IHubSearchOptions } from "../../types/IHubSearchOptions"; | ||
|
||
export function processAttendeeOptions( | ||
options: IHubSearchOptions | ||
): Partial<GetRegistrationsParams> { | ||
const processedOptions: Partial<GetRegistrationsParams> = {}; | ||
if (options.num > 0) { | ||
processedOptions.num = options.num.toString(); | ||
} | ||
if (options.start > 1) { | ||
processedOptions.start = options.start.toString(); | ||
} | ||
if (options.sortField === "modified") { | ||
processedOptions.sortBy = RegistrationSort.updatedAt; | ||
} else if (options.sortField === "created") { | ||
processedOptions.sortBy = RegistrationSort.createdAt; | ||
} else if (options.sortField === "username") { | ||
processedOptions.sortBy = RegistrationSort.username; | ||
} else if (options.sortField === "firstName") { | ||
processedOptions.sortBy = RegistrationSort.firstName; | ||
} else if (options.sortField === "lastName") { | ||
processedOptions.sortBy = RegistrationSort.lastName; | ||
} | ||
processedOptions.sortOrder = | ||
options.sortOrder === "desc" ? SortOrder.desc : SortOrder.asc; | ||
return processedOptions; | ||
} |
32 changes: 3 additions & 29 deletions
32
packages/common/src/search/_internal/hubEventsHelpers/processFilters.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
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.