Skip to content

Commit

Permalink
feat: force update tile select now reharvests
Browse files Browse the repository at this point in the history
  • Loading branch information
abp6318 committed May 1, 2024
1 parent 42e0fcd commit 11c1228
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const ContentPermissionPolicies: IPermissionPolicy[] = [
// can view = (alpha org + devext environment) || (permission is passed via query param)
permission: "hub:content:workspace:settings:schedule",
availability: ["alpha"],
// environments: ["devext"],
environments: ["devext"],
},
{
permission: "hub:content:workspace:collaborators",
Expand Down
16 changes: 2 additions & 14 deletions packages/common/src/content/_internal/ContentUiSchemaSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,16 @@ export const buildUiSchema = async (
],
},
},
// force update checkbox -- TODO: replace with button once available
{
type: "Control",
scope: "/properties/schedule/properties/_forceUpdate",
rule: {
effect: UiSchemaRuleEffects.SHOW,
condition: {
scope: "/properties/schedule",
schema: {
enum: [
{ mode: "manual" },
{ mode: "manual", _forceUpdate: [] },
{ mode: "manual", _forceUpdate: [true] },
],
},
},
},
options: {
control: "hub-field-input-tile-select",
type: "checkbox",
labels: ["Force Update"],
descriptions: [
"Use this option to manually update the search index and cached download files for this item.",
'Select this option and then select "Save" to manually update the search index and cached download files for this item as applicable.',
],
},
},
Expand Down
12 changes: 0 additions & 12 deletions packages/common/src/content/_internal/getSchedulerApiUrl.ts

This file was deleted.

37 changes: 37 additions & 0 deletions packages/common/src/content/_internal/internalContentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import { _getHubUrlFromPortalHostname } from "../../urls/_get-hub-url-from-porta
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { geojsonToArcGIS } from "@terraformer/arcgis";
import { Polygon } from "geojson";
import { getHubApiUrl } from "../../api";
import { IUserRequestOptions } from "@esri/arcgis-rest-auth";

/**
* Hashmap of Hub environment and application url surfix
Expand Down Expand Up @@ -965,3 +967,38 @@ const getUrbanModelEditUrl = (item: IItem, requestOptions: IRequestOptions) => {
const isPortalFromUrl = (portalUrl: string): boolean => {
return portalUrl.indexOf("arcgis.com") === -1;
};

export function getSchedulerApiUrl(
itemId: string,
requestOptions: IRequestOptions
): string {
const hubApiUrlRoot = getHubApiUrlRoot(requestOptions);
return `${hubApiUrlRoot}/api/download/v1/items/${itemId}/schedule`;
}

export function getHubApiUrlRoot(requestOptions: IRequestOptions): string {
// sometimes the url has /api/v3 at the end, so we need to remove it
const hubApiUrlWithVersion = getHubApiUrl(requestOptions);
return hubApiUrlWithVersion.replace(/\/api\/v3$/, "");
}

export const forceUpdateContent = async (
itemId: string,
requestOptions: IUserRequestOptions
) => {
// https://opendata{qa|dev}.arcgis.com/api/v3/jobs/item/${itemId}/harvest with a token in the header

const hubApiUrlRoot = getHubApiUrl(requestOptions);
const url = `${hubApiUrlRoot}/api/v3/jobs/item/${itemId}/harvest`;
const options = {
method: "POST",
headers: {
"content-type": "application/json",
// I see a number of ways to use getToken, but I'm not sure which one is correct
authorization: requestOptions.authentication.token,
},
};

const response = await fetch(url, options);
return response.json();
};
10 changes: 10 additions & 0 deletions packages/common/src/content/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
isDownloadSchedulingAvailable,
maybeUpdateSchedule,
} from "./manageSchedule";
import { forceUpdateContent } from "./_internal/internalContentUtils";
import { deepEqual } from "../objects";

// TODO: move this to defaults?
const DEFAULT_CONTENT_MODEL: IModel = {
Expand Down Expand Up @@ -174,6 +176,14 @@ export async function updateContent(
}

if (isDownloadSchedulingAvailable(requestOptions, content.access)) {
// if schedule has "Force Update" checked and clicked save, initiate an update
if (deepEqual((content.schedule as any)._forceUpdate, [true])) {
// [true]
await forceUpdateContent(item.id, requestOptions);
}

delete (content.schedule as any)._forceUpdate;

await maybeUpdateSchedule(content, requestOptions);
}

Expand Down
10 changes: 9 additions & 1 deletion packages/common/src/content/manageSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IHubSchedule, IHubScheduleResponse } from "../core/types/IHubSchedule";
import { cloneObject } from "../util";
import { deepEqual } from "../objects/deepEqual";
import { AccessLevel, IHubEditableContent } from "../core";
import { getSchedulerApiUrl } from "./_internal/getSchedulerApiUrl";
import { getSchedulerApiUrl } from "./_internal/internalContentUtils";

// Any code referencing these functions must first pass isDownloadSchedulingAvailable

Expand Down Expand Up @@ -43,6 +43,14 @@ export const getSchedule = async (
message: `Download schedule found for item ${itemId}`,
statusCode: 200,
} as IHubScheduleResponse;
case "manual":
return {
schedule: {
mode: "manual",
},
message: `Download schedule found for item ${itemId}`,
statusCode: 200,
} as IHubScheduleResponse;
}
};

Expand Down

0 comments on commit 11c1228

Please sign in to comment.