Skip to content

Commit

Permalink
feat: telemetry config (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuniper authored Oct 13, 2023
1 parent bc81b11 commit 7a0a40c
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 22 deletions.
50 changes: 31 additions & 19 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export async function getEntityEditorSchemas(
import("../../../sites/_internal/SiteUiSchemaFollowers"),
"hub:site:discussions": () =>
import("../../../sites/_internal/SiteUiSchemaDiscussions"),
"hub:site:settings": () =>
import("../../../sites/_internal/SiteUiSchemaSettings"),
}[type as SiteEditorType]();
uiSchema = await siteModule.buildUiSchema(
i18nScope,
Expand Down
9 changes: 9 additions & 0 deletions packages/common/src/core/schemas/shared/subschemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,12 @@ export const ENTITY_TIMELINE_SCHEMA = {
},
},
};

export const PRIVACY_CONFIG_SCHEMA = {
type: "object",
properties: {
consentNotice: {
type: "object",
},
},
};
7 changes: 6 additions & 1 deletion packages/common/src/sites/_internal/SiteSchema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { IConfigurationSchema } from "../../core";
import { ENTITY_IS_DISCUSSABLE_SCHEMA } from "../../core/schemas/shared";
import {
ENTITY_IS_DISCUSSABLE_SCHEMA,
PRIVACY_CONFIG_SCHEMA,
} from "../../core/schemas/shared";
import { HubItemEntitySchema } from "../../core/schemas/shared/HubItemEntitySchema";

export type SiteEditorType = (typeof SiteEditorTypes)[number];
Expand All @@ -8,6 +11,7 @@ export const SiteEditorTypes = [
"hub:site:create",
"hub:site:followers",
"hub:site:discussions",
"hub:site:settings",
] as const;

/**
Expand All @@ -18,5 +22,6 @@ export const SiteSchema: IConfigurationSchema = {
properties: {
...HubItemEntitySchema.properties,
_discussions: ENTITY_IS_DISCUSSABLE_SCHEMA,
telemetry: PRIVACY_CONFIG_SCHEMA,
},
} as IConfigurationSchema;
33 changes: 33 additions & 0 deletions packages/common/src/sites/_internal/SiteUiSchemaSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { IHubSite } from "../../core/types";
import { IArcGISContext } from "../../ArcGISContext";
import { IUiSchema } from "../../core/schemas/types";

/**
* @private
* constructs the edit uiSchema for Hub Sites.
* This defines how the schema properties should
* be rendered in the site editing experience
*/
export const buildUiSchema = async (
i18nScope: string,
entity: IHubSite,
context: IArcGISContext
): Promise<IUiSchema> => {
return {
type: "Layout",
elements: [
{
type: "Section",
elements: [
{
scope: "/properties/telemetry/properties/consentNotice",
type: "Control",
options: {
control: "arcgis-privacy-config",
},
},
],
},
],
};
};
59 changes: 59 additions & 0 deletions packages/common/src/sites/_internal/_migrate-telemetry-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { getProp, setProp } from "../../objects";
import { IModel, IDraft } from "../../types";
import { cloneObject } from "../../util";

/**
* Reconfigure event list card properties
* @private
* @param {object} model Site Model
* @returns {object}
*/
export function _migrateTelemetryConfig<T extends IModel | IDraft>(
model: T
): T {
const newSchemaVersion = 1.7;
// do nothing if migration already applied
if (getProp(model, "item.properties.schemaVersion") >= newSchemaVersion) {
return model;
}

// apply migration
const clone = cloneObject(model);

clone.data.telemetry = {};
// get allowPrivacyConfig from consentNotice capability
const capabilities = getProp(model, "data.values.capabilities") || [];
const allowPrivacyConfig = capabilities.includes("consentNotice");

// migrate consentNotice
clone.data.telemetry.consentNotice = {
allowPrivacyConfig,
disclaimer: [
{
text:
getProp(model, "data.values.telemetry.consentNotice.consentText") ||
"",
default: true,
},
],
policyURL:
getProp(model, "data.values.telemetry.consentNotice.policyURL") || "",
};

// this doesn't actually have any effect - not sure we have a way to get rid of stuff
// delete clone.data?.values?.telemetry;

// if we have item.properties.telemetry.plugins, move it to data.telemetry
const plugins = getProp(model, "item.properties.telemetry.plugins");
if (plugins) {
clone.data.telemetry.plugins = plugins;

// this doesn't actually have any effect - not sure we have a way to get rid of stuff
// delete clone.item?.properties?.telemetry;
}

// increment schemaVersion
setProp("item.properties.schemaVersion", newSchemaVersion, clone);

return clone;
}
7 changes: 6 additions & 1 deletion packages/common/src/sites/_internal/getPropertyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function getPropertyMap(): IPropertyMap[] {
"clientId",
"defaultExtent",
"map",
"telemetry",
"headerSass",
"headContent",
"layout",
Expand Down Expand Up @@ -67,5 +66,11 @@ export function getPropertyMap(): IPropertyMap[] {
entityKey: "features",
storeKey: "data.settings.features",
});

map.push({
entityKey: "telemetry",
storeKey: "data.telemetry",
});

return map;
}
1 change: 1 addition & 0 deletions packages/common/src/sites/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./_internal/_ensure-telemetry";
export * from "./_internal/_migrate-feed-config";
export * from "./_internal/_migrate-event-list-card-configs";
export * from "./_internal/_migrate-telemetry-config";
export * from "./domains";
export * from "./drafts";
export * from "./fetchSiteModel";
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/sites/site-schema-version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const SITE_SCHEMA_VERSION = 1.6;
export const SITE_SCHEMA_VERSION = 1.7;
2 changes: 2 additions & 0 deletions packages/common/src/sites/upgrade-site-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { _ensureTelemetry } from "./_internal/_ensure-telemetry";
import { _migrateFeedConfig } from "./_internal/_migrate-feed-config";
import { _migrateEventListCardConfigs } from "./_internal/_migrate-event-list-card-configs";
import { migrateLegacyCapabilitiesToFeatures } from "./_internal/capabilities/migrateLegacyCapabilitiesToFeatures";
import { _migrateTelemetryConfig } from "./_internal/_migrate-telemetry-config";

/**
* Upgrades the schema upgrades
Expand All @@ -27,6 +28,7 @@ export function upgradeSiteSchema(model: IModel) {
model = _migrateFeedConfig(model);
model = _migrateEventListCardConfigs(model);
model = migrateLegacyCapabilitiesToFeatures(model);
model = _migrateTelemetryConfig(model);

// WARNING - If you are writing a site schema migration,
// you probably need to apply it to site drafts as well!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as SiteBuildEditUiSchema from "../../../../src/sites/_internal/SiteUiSc
import * as SiteBuildCreateUiSchema from "../../../../src/sites/_internal/SiteUiSchemaCreate";
import * as SiteBuildFollowersUiSchema from "../../../../src/sites/_internal/SiteUiSchemaFollowers";
import * as SiteBuildDiscussionsUiSchema from "../../../../src/sites/_internal/SiteUiSchemaDiscussions";
import * as SiteBuildTelemetryUiSchema from "../../../../src/sites/_internal/SiteUiSchemaSettings";

import { DiscussionEditorTypes } from "../../../../src/discussions/_internal/DiscussionSchema";
import * as DiscussionBuildEditUiSchema from "../../../../src/discussions/_internal/DiscussionUiSchemaEdit";
Expand Down Expand Up @@ -53,6 +54,7 @@ describe("getEntityEditorSchemas: ", () => {
{ type: SiteEditorTypes[1], buildFn: SiteBuildCreateUiSchema },
{ type: SiteEditorTypes[2], buildFn: SiteBuildFollowersUiSchema },
{ type: SiteEditorTypes[3], buildFn: SiteBuildDiscussionsUiSchema },
{ type: SiteEditorTypes[4], buildFn: SiteBuildTelemetryUiSchema },
{ type: DiscussionEditorTypes[0], buildFn: DiscussionBuildEditUiSchema },
{ type: DiscussionEditorTypes[1], buildFn: DiscussionBuildCreateUiSchema },
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { buildUiSchema } from "../../../src/sites/_internal/SiteUiSchemaSettings";
import { MOCK_CONTEXT } from "../../mocks/mock-auth";

describe("buildUiSchema: site telemetry", () => {
it("returns the full site telemetry uiSchema", async () => {
const uiSchema = await buildUiSchema("some.scope", {} as any, MOCK_CONTEXT);
expect(uiSchema).toEqual({
type: "Layout",
elements: [
{
type: "Section",
elements: [
{
scope: "/properties/telemetry/properties/consentNotice",
type: "Control",
options: {
control: "arcgis-privacy-config",
},
},
],
},
],
});
});
});
Loading

0 comments on commit 7a0a40c

Please sign in to comment.