Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hub-common): disable categories field and provide notice when no options are available #1561

Merged
merged 9 commits into from
Jun 24, 2024
Merged
21 changes: 2 additions & 19 deletions packages/common/src/content/_internal/ContentUiSchemaEdit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IArcGISContext } from "../../ArcGISContext";
import { getTagItems } from "../../core/schemas/internal/getTagItems";
import { getCategoryItems } from "../../core/schemas/internal/getCategoryItems";
import { getLocationExtent } from "../../core/schemas/internal/getLocationExtent";
import { getLocationOptions } from "../../core/schemas/internal/getLocationOptions";
import { IUiSchema } from "../../core/schemas/types";
import { getThumbnailUiSchemaElement } from "../../core/schemas/internal/getThumbnailUiSchemaElement";
import { IHubEditableContent } from "../../core/types";
import { fetchCategoriesUiSchemaElement } from "../../core/schemas/internal/fetchCategoriesUiSchemaElement";

/**
* @private
Expand Down Expand Up @@ -109,24 +109,7 @@ export const buildUiSchema = async (
},
},
// categories
{
labelKey: `${i18nScope}.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: await getCategoryItems(
context.portal.id,
context.hubRequestOptions
),
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
helperText: {
labelKey: `${i18nScope}.fields.categories.agolHint`, // TODO: hint should describe whether it can be set on Enterprise or Online
},
},
},
await fetchCategoriesUiSchemaElement(i18nScope, context),
// license
{
labelKey: `${i18nScope}.fields.license.label`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { IArcGISContext } from "../../../ArcGISContext";
import {
IUiSchemaElement,
IUiSchemaMessage,
UiSchemaMessageTypes,
} from "../types";
import { fetchCategoryItems } from "./fetchCategoryItems";

/**
* Returns the UI schema element needed to render
* the categories editing control for an entity.
*
* @param i18nScope i18n scope for the entity translations
* @param entity The entity to build the UI schema for
* @returns the UI schema element for thumbnail editing
*/
export async function fetchCategoriesUiSchemaElement(
sonofflynn89 marked this conversation as resolved.
Show resolved Hide resolved
i18nScope: string,
context: IArcGISContext
): Promise<IUiSchemaElement> {
const categoryItems = await fetchCategoryItems(
context.portal.id,
context.hubRequestOptions
);

const result: IUiSchemaElement = {
labelKey: `shared.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: categoryItems,
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
helperText: {
// helper text varies between entity types
labelKey: `${i18nScope}.fields.categories.helperText`,
},
},
};

if (!categoryItems.length) {
result.options.disabled = true;
result.options.messages = [
{
type: UiSchemaMessageTypes.custom,
display: "notice",
kind: "warning",
icon: "exclamation-mark-triangle",
labelKey: "shared.fields.categories.noCategoriesNotice.body",
link: {
kind: "external",
label:
"{{shared.fields.categories.noCategoriesNotice.link:translate}}",
href: "https://doc.arcgis.com/en/arcgis-online/reference/content-categories.htm",
target: "_blank",
},
allowShowBeforeInteract: true,
alwaysShow: true,
} as IUiSchemaMessage,
];
}

return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IUiSchemaComboboxItem } from "../types";
* @param hubRequestOptions The hub request options
* @returns a _nested_ structure of categories
*/
export async function getCategoryItems(
export async function fetchCategoryItems(
orgId: string,
hubRequestOptions: IHubRequestOptions
): Promise<IUiSchemaComboboxItem[]> {
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/core/schemas/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "./internal/EditorOptions";
import { IArcGISContext } from "../../ArcGISContext";
import { EventEditorTypes } from "../../events/_internal/EventSchemaCreate";
import { HubActionLink } from "../types";

export interface IEditorConfig {
schema: IConfigurationSchema;
Expand Down Expand Up @@ -250,6 +251,7 @@ export interface IUiSchemaMessage {
labelKey?: string;
icon?: boolean | string;
kind?: "brand" | "danger" | "info" | "success" | "warning";
link?: HubActionLink;
hidden?: boolean;
// NOTE: condition is deprecated and remains for backwards compatibility only. Please use conditions instead.
condition?: IUiSchemaCondition;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IUiSchema } from "../../core/schemas/types";
import { IArcGISContext } from "../../ArcGISContext";
import { getTagItems } from "../../core/schemas/internal/getTagItems";
import { getCategoryItems } from "../../core/schemas/internal/getCategoryItems";
import { getLocationExtent } from "../../core/schemas/internal/getLocationExtent";
import { getLocationOptions } from "../../core/schemas/internal/getLocationOptions";
import { getThumbnailUiSchemaElement } from "../../core/schemas/internal/getThumbnailUiSchemaElement";
import { IHubDiscussion } from "../../core/types";
import { fetchCategoriesUiSchemaElement } from "../../core/schemas/internal/fetchCategoriesUiSchemaElement";

/**
* @private
Expand Down Expand Up @@ -121,21 +121,7 @@ export const buildUiSchema = async (
placeholderIcon: "label",
},
},
{
labelKey: `${i18nScope}.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: await getCategoryItems(
context.portal.id,
context.hubRequestOptions
),
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
},
},
await fetchCategoriesUiSchemaElement(i18nScope, context),
{
labelKey: `${i18nScope}.fields.summary.label`,
scope: "/properties/summary",
Expand Down
21 changes: 2 additions & 19 deletions packages/common/src/events/_internal/EventUiSchemaEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { IUiSchema, UiSchemaRuleEffects } from "../../core/schemas/types";
import { IArcGISContext } from "../../ArcGISContext";
import { getDatePickerDate } from "../../utils/date/getDatePickerDate";
import { IHubEvent } from "../../core/types/IHubEvent";
import { getCategoryItems } from "../../core/schemas/internal/getCategoryItems";
import { getTagItems } from "../../core/schemas/internal/getTagItems";
import { HubEventAttendanceType, HubEventCapacityType } from "../types";
import { getLocationExtent } from "../../core/schemas/internal/getLocationExtent";
import { getLocationOptions } from "../../core/schemas/internal/getLocationOptions";
import { fetchCategoriesUiSchemaElement } from "../../core/schemas/internal/fetchCategoriesUiSchemaElement";

/**
* @private
Expand Down Expand Up @@ -433,24 +433,7 @@ export const buildUiSchema = async (
},
},
},
{
labelKey: `${i18nScope}.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: await getCategoryItems(
context.portal.id,
context.hubRequestOptions
),
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
helperText: {
labelKey: `${i18nScope}.fields.categories.helperText`,
},
},
},
await fetchCategoriesUiSchemaElement(i18nScope, context),
{
labelKey: `${i18nScope}.fields.summary.label`,
scope: "/properties/summary",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { IUiSchema, UiSchemaRuleEffects } from "../../core/schemas/types";
import { IArcGISContext } from "../../ArcGISContext";
import { getTagItems } from "../../core/schemas/internal/getTagItems";
import { getCategoryItems } from "../../core/schemas/internal/getCategoryItems";
import { getLocationExtent } from "../../core/schemas/internal/getLocationExtent";
import { getLocationOptions } from "../../core/schemas/internal/getLocationOptions";
import { getThumbnailUiSchemaElement } from "../../core/schemas/internal/getThumbnailUiSchemaElement";
import { IHubInitiative } from "../../core";
import { getAuthedImageUrl } from "../../core/_internal/getAuthedImageUrl";
import { fetchCategoriesUiSchemaElement } from "../../core/schemas/internal/fetchCategoriesUiSchemaElement";

/**
* @private
Expand Down Expand Up @@ -181,24 +181,7 @@ export const buildUiSchema = async (
type: "Section",
labelKey: `${i18nScope}.sections.searchDiscoverability.label`,
elements: [
{
labelKey: `${i18nScope}.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: await getCategoryItems(
context.portal.id,
context.hubRequestOptions
),
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
helperText: {
labelKey: `${i18nScope}.fields.categories.helperText`,
},
},
},
await fetchCategoriesUiSchemaElement(i18nScope, context),
{
labelKey: `${i18nScope}.fields.tags.label`,
scope: "/properties/tags",
Expand Down
21 changes: 2 additions & 19 deletions packages/common/src/pages/_internal/PageUiSchemaEdit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IUiSchema } from "../../core/schemas/types";
import { IArcGISContext } from "../../ArcGISContext";
import { getTagItems } from "../../core/schemas/internal/getTagItems";
import { getCategoryItems } from "../../core/schemas/internal/getCategoryItems";
import { getLocationExtent } from "../../core/schemas/internal/getLocationExtent";
import { getLocationOptions } from "../../core/schemas/internal/getLocationOptions";
import { getThumbnailUiSchemaElement } from "../../core/schemas/internal/getThumbnailUiSchemaElement";
import { IHubPage } from "../../core/types";
import { fetchCategoriesUiSchemaElement } from "../../core/schemas/internal/fetchCategoriesUiSchemaElement";

/**
* @private
Expand Down Expand Up @@ -101,24 +101,7 @@ export const buildUiSchema = async (
helperText: { labelKey: `${i18nScope}.fields.tags.helperText` },
},
},
{
labelKey: `${i18nScope}.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: await getCategoryItems(
context.portal.id,
context.hubRequestOptions
),
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
helperText: {
labelKey: `${i18nScope}.fields.categories.helperText`,
},
},
},
await fetchCategoriesUiSchemaElement(i18nScope, context),
],
},
{
Expand Down
21 changes: 2 additions & 19 deletions packages/common/src/projects/_internal/ProjectUiSchemaEdit.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { IArcGISContext } from "../../ArcGISContext";
import { IUiSchema } from "../../core/schemas/types";
import { getCategoryItems } from "../../core/schemas/internal/getCategoryItems";
import { getFeaturedContentCatalogs } from "../../core/schemas/internal/getFeaturedContentCatalogs";
import { getLocationExtent } from "../../core/schemas/internal/getLocationExtent";
import { getLocationOptions } from "../../core/schemas/internal/getLocationOptions";
import { getTagItems } from "../../core/schemas/internal/getTagItems";
import { getThumbnailUiSchemaElement } from "../../core/schemas/internal/getThumbnailUiSchemaElement";
import { IHubProject } from "../../core/types";
import { getAuthedImageUrl } from "../../core/_internal/getAuthedImageUrl";
import { fetchCategoriesUiSchemaElement } from "../../core/schemas/internal/fetchCategoriesUiSchemaElement";

/**
* @private
Expand Down Expand Up @@ -164,24 +164,7 @@ export const buildUiSchema = async (
helperText: { labelKey: `${i18nScope}.fields.tags.helperText` },
},
},
{
labelKey: `${i18nScope}.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: await getCategoryItems(
context.portal.id,
context.hubRequestOptions
),
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
helperText: {
labelKey: `${i18nScope}.fields.categories.helperText`,
},
},
},
await fetchCategoriesUiSchemaElement(i18nScope, context),
getThumbnailUiSchemaElement(
i18nScope,
options.thumbnail,
Expand Down
21 changes: 2 additions & 19 deletions packages/common/src/sites/_internal/SiteUiSchemaEdit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IArcGISContext } from "../../ArcGISContext";
import { getCategoryItems } from "../../core/schemas/internal/getCategoryItems";
import { getLocationExtent } from "../../core/schemas/internal/getLocationExtent";
import { getLocationOptions } from "../../core/schemas/internal/getLocationOptions";
import { getTagItems } from "../../core/schemas/internal/getTagItems";
import { IUiSchema } from "../../core/schemas/types";
import { getThumbnailUiSchemaElement } from "../../core/schemas/internal/getThumbnailUiSchemaElement";
import { IHubSite } from "../../core/types";
import { fetchCategoriesUiSchemaElement } from "../../core/schemas/internal/fetchCategoriesUiSchemaElement";

/**
* @private
Expand Down Expand Up @@ -101,24 +101,7 @@ export const buildUiSchema = async (
helperText: { labelKey: `${i18nScope}.fields.tags.helperText` },
},
},
{
labelKey: `${i18nScope}.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: await getCategoryItems(
context.portal.id,
context.hubRequestOptions
),
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
helperText: {
labelKey: `${i18nScope}.fields.categories.helperText`,
},
},
},
await fetchCategoriesUiSchemaElement(i18nScope, context),
],
},
{
Expand Down
18 changes: 2 additions & 16 deletions packages/common/src/surveys/_internal/SurveyUiSchemaEdit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IArcGISContext } from "../../ArcGISContext";
import { getCategoryItems } from "../../core/schemas/internal/getCategoryItems";
import { fetchCategoriesUiSchemaElement } from "../../core/schemas/internal/fetchCategoriesUiSchemaElement";
import { getTagItems } from "../../core/schemas/internal/getTagItems";
import { getThumbnailUiSchemaElement } from "../../core/schemas/internal/getThumbnailUiSchemaElement";
import { IUiSchema } from "../../core/schemas/types";
Expand Down Expand Up @@ -99,21 +99,7 @@ export const buildUiSchema = async (
placeholderIcon: "label",
},
},
{
labelKey: `${i18nScope}.fields.categories.label`,
scope: "/properties/categories",
type: "Control",
options: {
control: "hub-field-input-combobox",
items: await getCategoryItems(
context.portal.id,
context.hubRequestOptions
),
allowCustomValues: false,
selectionMode: "ancestors",
placeholderIcon: "select-category",
},
},
await fetchCategoriesUiSchemaElement(i18nScope, context),
getThumbnailUiSchemaElement(
i18nScope,
options.thumbnail,
Expand Down
Loading
Loading