-
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: add logic/schema to allow follower group creation (#1333)
- add a new uiSchema to create followers groups - hoist getUniqueGroupTitle util from hub-teams into hub-common/groups and leverage in group creation workflow - gate followers pane on sites to premium licenses - add permission for creating followers group
- Loading branch information
1 parent
9ff78e4
commit 9515f8c
Showing
17 changed files
with
504 additions
and
34 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
111 changes: 111 additions & 0 deletions
111
packages/common/src/groups/_internal/GroupUiSchemaCreateFollowers.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,111 @@ | ||
import { IUiSchema, UiSchemaRuleEffects } from "../../core/schemas/types"; | ||
import { IArcGISContext } from "../../ArcGISContext"; | ||
import { EntityEditorOptions } from "../../core/schemas/internal/EditorOptions"; | ||
|
||
/** | ||
* @private | ||
* constructs the complete uiSchema for creating a followers | ||
* group. This defines how the schema properties should be | ||
* rendered in the follower group creation experience | ||
*/ | ||
export const buildUiSchema = async ( | ||
i18nScope: string, | ||
options: EntityEditorOptions, | ||
context: IArcGISContext | ||
): Promise<IUiSchema> => { | ||
return { | ||
type: "Layout", | ||
elements: [ | ||
{ | ||
type: "Section", | ||
options: { section: "stepper", scale: "l" }, | ||
elements: [ | ||
{ | ||
type: "Step", | ||
labelKey: `${i18nScope}.sections.details.label`, | ||
elements: [ | ||
{ | ||
labelKey: `${i18nScope}.fields.name.label`, | ||
scope: "/properties/name", | ||
type: "Control", | ||
options: { | ||
messages: [ | ||
{ | ||
type: "ERROR", | ||
keyword: "required", | ||
icon: true, | ||
labelKey: `${i18nScope}.fields.name.requiredError`, | ||
}, | ||
{ | ||
type: "ERROR", | ||
keyword: "maxLength", | ||
icon: true, | ||
labelKey: `${i18nScope}.fields.name.maxLengthError`, | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
labelKey: `${i18nScope}.fields.summary.label`, | ||
scope: "/properties/summary", | ||
type: "Control", | ||
options: { | ||
control: "hub-field-input-input", | ||
type: "textarea", | ||
rows: 4, | ||
messages: [ | ||
{ | ||
type: "ERROR", | ||
keyword: "maxLength", | ||
icon: true, | ||
labelKey: `${i18nScope}.fields.summary.maxLengthError`, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: "Step", | ||
labelKey: `${i18nScope}.sections.membershipAccess.label`, | ||
rule: { | ||
effect: UiSchemaRuleEffects.DISABLE, | ||
condition: { | ||
scope: "/properties/name", | ||
schema: { const: "" }, | ||
}, | ||
}, | ||
elements: [ | ||
{ | ||
labelKey: `${i18nScope}.fields.membershipAccess.label`, | ||
scope: "/properties/membershipAccess", | ||
type: "Control", | ||
options: { | ||
control: "hub-field-input-radio", | ||
labels: [ | ||
`{{${i18nScope}.fields.membershipAccess.org:translate}}`, | ||
`{{${i18nScope}.fields.membershipAccess.collab:translate}}`, | ||
`{{${i18nScope}.fields.membershipAccess.any:translate}}`, | ||
], | ||
disabled: [false, false, options.isSharedUpdate], | ||
}, | ||
}, | ||
{ | ||
labelKey: `${i18nScope}.fields.contributeContent.label`, | ||
scope: "/properties/isViewOnly", | ||
type: "Control", | ||
options: { | ||
control: "hub-field-input-radio", | ||
labels: [ | ||
`{{${i18nScope}.fields.contributeContent.all:translate}}`, | ||
`{{${i18nScope}.fields.contributeContent.admins:translate}}`, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
}; |
65 changes: 65 additions & 0 deletions
65
packages/common/src/groups/_internal/getUniqueGroupTitle.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 { IQuery } from "../../search/types"; | ||
import { hubSearch } from "../../search/hubSearch"; | ||
import { IUserRequestOptions } from "@esri/arcgis-rest-auth"; | ||
|
||
/** | ||
* @private | ||
* Given a title, construct a group title that is unique | ||
* in the user's org. | ||
* | ||
* Ex: Given a title of "Medical Team", if a group with that | ||
* title exists, this fn will add a number on the end, and | ||
* increment until an available group title is found - i.e. | ||
* "Medical Team 3" | ||
* | ||
* @param {String} title Group Title to ensure is unique | ||
* @param {IUserRequestOptions} requestOptions | ||
* @param {Number} step Number to increment. Defaults to 0 | ||
*/ | ||
export async function getUniqueGroupTitle( | ||
title: string, | ||
requestOptions: IUserRequestOptions, | ||
step = 0 | ||
): Promise<string> { | ||
let combinedName = title; | ||
|
||
if (step) { | ||
combinedName = `${title} ${step}`; | ||
} | ||
|
||
return doesGroupExist(combinedName, requestOptions) | ||
.then((result) => { | ||
if (result) { | ||
step++; | ||
return getUniqueGroupTitle(title, requestOptions, step); | ||
} else { | ||
return combinedName; | ||
} | ||
}) | ||
.catch((err) => { | ||
throw Error(`Error in getUniqueGroupTitle: ${err}`); | ||
}); | ||
} | ||
|
||
/** | ||
* checks whether a group with the specified title | ||
* exists in the user's org | ||
* | ||
* @param {String} title Group Title | ||
* @param {IUserRequestOptions} requestOptions | ||
*/ | ||
async function doesGroupExist( | ||
title: string, | ||
requestOptions: IUserRequestOptions | ||
) { | ||
const query: IQuery = { | ||
targetEntity: "group", | ||
filters: [{ predicates: [{ title }] }], | ||
}; | ||
try { | ||
const { results } = await hubSearch(query, { requestOptions }); | ||
return results.length > 0; | ||
} catch (error) { | ||
throw Error(`Error in getUniqueGroupTitle > doesGroupExist: ${error}`); | ||
} | ||
} |
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.