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): add content settings schemas and derive props from server definitions #1209

Merged
merged 12 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 61 additions & 24 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@esri/arcgis-rest-feature-layer": "^3.4.3",
"@esri/arcgis-rest-portal": "^3.5.0",
"@esri/arcgis-rest-request": "^3.1.1",
"@esri/arcgis-rest-service-admin": "^3.6.0",
"@esri/arcgis-rest-types": "^3.1.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@esri/arcgis-rest-feature-layer": "^3.2.0",
"@esri/arcgis-rest-portal": "^2.18.0 || 3",
"@esri/arcgis-rest-request": "^2.14.0 || 3",
"@esri/arcgis-rest-service-admin": "^3.6.0",
"@esri/arcgis-rest-types": "^2.15.0 || 3"
},
"devDependencies": {
Expand Down
11 changes: 10 additions & 1 deletion packages/common/src/content/_internal/ContentSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { IConfigurationSchema } from "../../core";
import { HubItemEntitySchema } from "../../core/schemas/shared/HubItemEntitySchema";

export type ContentEditorType = (typeof ContentEditorTypes)[number];
export const ContentEditorTypes = ["hub:content:edit"] as const;
export const ContentEditorTypes = [
"hub:content:edit",
"hub:content:settings",
] as const;

/**
* defines the JSON schema for a Hub Content's editable fields
Expand All @@ -14,5 +17,11 @@ export const ContentSchema: IConfigurationSchema = {
licenseInfo: {
type: "string",
},
serverExtractCapability: {
type: "boolean",
},
hostedDownloads: {
type: "boolean",
},
},
} as IConfigurationSchema;
6 changes: 3 additions & 3 deletions packages/common/src/content/_internal/ContentUiSchemaEdit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IUiSchema } from "../../core";
import { IArcGISContext } from "../../ArcGISContext";
import { IHubContent } from "../../core/types";
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 { IHubEditableContent } from "../../core/types/IHubEditableContent";
import { IUiSchema } from "../../core/schemas/types";

/**
* @private
Expand All @@ -14,7 +14,7 @@ import { getLocationOptions } from "../../core/schemas/internal/getLocationOptio
*/
export const buildUiSchema = async (
i18nScope: string,
entity: IHubContent,
entity: IHubEditableContent,
context: IArcGISContext
): Promise<IUiSchema> => {
return {
Expand Down
65 changes: 65 additions & 0 deletions packages/common/src/content/_internal/ContentUiSchemaSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { IArcGISContext } from "../../ArcGISContext";
import { IUiSchema, UiSchemaRuleEffects } from "../../core/schemas/types";
import { IHubEditableContent } from "../../core/types/IHubEditableContent";
import { isHostedFeatureServiceEntity } from "../hostedServiceUtils";

/**
* @private
* constructs the complete settings uiSchema for Hub Editable Content.
* This defines how the schema properties should be
* rendered in the content settings editing experience
*/
export const buildUiSchema = async (
i18nScope: string,
entity: IHubEditableContent,
_context: IArcGISContext
): Promise<IUiSchema> => {
const uiSchema: IUiSchema = {
type: "Layout",
elements: [],
};
if (isHostedFeatureServiceEntity(entity)) {
uiSchema.elements.push({
type: "Section",
labelKey: `${i18nScope}.sections.downloads.label`,
options: {
helperText: {
labelKey: `${i18nScope}.sections.downloads.helperText`,
},
},
elements: [
{
labelKey: `${i18nScope}.fields.serverExtractCapability.label`,
scope: "/properties/serverExtractCapability",
type: "Control",
options: {
helperText: {
labelKey: `${i18nScope}.fields.serverExtractCapability.helperText`,
},
},
},
{
labelKey: `${i18nScope}.fields.hostedDownloads.label`,
scope: "/properties/hostedDownloads",
type: "Control",
options: {
helperText: {
labelKey: `${i18nScope}.fields.hostedDownloads.helperText`,
},
},
rule: {
effect: UiSchemaRuleEffects.DISABLE,
condition: {
schema: {
properties: {
serverExtractCapability: { const: false },
},
},
},
},
},
],
});
}
return uiSchema;
};
15 changes: 14 additions & 1 deletion packages/common/src/content/_internal/computeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { getHubRelativeUrl } from "./internalContentUtils";
import { IHubLocation } from "../../core/types/IHubLocation";
import { IHubEditableContent } from "../../core/types/IHubEditableContent";
import { getRelativeWorkspaceUrl } from "../../core/getRelativeWorkspaceUrl";
import {
hasServiceCapability,
ServiceCapabilities,
} from "../hostedServiceUtils";
import { IItemAndIServerEnrichments } from "../../items/_enrichments";

// if called and valid, set 3 things -- else just return type custom
export const getItemExtent = (itemExtent: number[][]): IExtent => {
Expand All @@ -36,7 +41,8 @@ export function deriveLocationFromItemExtent(itemExtent?: number[][]) {
export function computeProps(
model: IModel,
content: Partial<IHubEditableContent>,
requestOptions: IRequestOptions
requestOptions: IRequestOptions,
enrichments: IItemAndIServerEnrichments = {}
): IHubEditableContent {
let token: string;
if (requestOptions.authentication) {
Expand Down Expand Up @@ -70,5 +76,12 @@ export function computeProps(
: deriveLocationFromItemExtent(model.item.extent);
}

if (enrichments.server) {
content.serverExtractCapability = hasServiceCapability(
ServiceCapabilities.EXTRACT,
enrichments.server
);
}

return content as IHubEditableContent;
}
5 changes: 5 additions & 0 deletions packages/common/src/content/_internal/getPropertyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export function getPropertyMap(): IPropertyMap[] {
storeKey: "item.licenseInfo",
});

map.push({
entityKey: "hostedDownloads",
storeKey: "item.properties.downloads.hosted",
});

// features is intentionally left out

// TODO: look into composeContent() for what we can add here
Expand Down
Loading