diff --git a/v3/src/data-interactive/handlers/data-context-from-url-handler.test.ts b/v3/src/data-interactive/handlers/data-context-from-url-handler.test.ts index 0a17752b9..7acacec16 100644 --- a/v3/src/data-interactive/handlers/data-context-from-url-handler.test.ts +++ b/v3/src/data-interactive/handlers/data-context-from-url-handler.test.ts @@ -1,11 +1,8 @@ -import { DIDataContext } from "../data-interactive-types" -import { setupTestDataset } from "./handler-test-utils" -import { toV2Id } from "../../utilities/codap-utils" -import { diDataContextFromURLHandler, getFilenameFromUrl } from "./data-context-from-url-handler" -import { CsvParseResult, downloadCsvFile } from "../../utilities/csv-import" import { appState } from "../../models/app-state" import { gDataBroker } from "../../models/data/data-broker" import { getSharedModelManager } from "../../models/tiles/tile-environment" +import { CsvParseResult, downloadCsvFile } from "../../utilities/csv-import" +import { diDataContextFromURLHandler, getFilenameFromUrl } from "./data-context-from-url-handler" jest.mock("../../utilities/csv-import", () => { const originalModule = jest.requireActual("../../utilities/csv-import") diff --git a/v3/src/data-interactive/handlers/data-context-from-url-handler.ts b/v3/src/data-interactive/handlers/data-context-from-url-handler.ts index fc1a1e885..7711f2dde 100644 --- a/v3/src/data-interactive/handlers/data-context-from-url-handler.ts +++ b/v3/src/data-interactive/handlers/data-context-from-url-handler.ts @@ -1,28 +1,24 @@ import { appState } from "../../models/app-state" import { convertParsedCsvToDataSet, CsvParseResult, downloadCsvFile } from "../../utilities/csv-import" +import { t } from "../../utilities/translation/translate" import { registerDIHandler } from "../data-interactive-handler" -import { DIErrorResult, DIHandler, diNotImplementedYet, DIResources, DIUrl, DIValues } from "../data-interactive-types" - -const kInvalidValuesError: DIErrorResult = { - success: false, - values: { - error: "dataContextFromURL requires a { URL: [url] } value" - } -} +import { DIHandler, DIResources, DIUrl, DIValues } from "../data-interactive-types" +import { errorResult, fieldRequiredResult } from "./di-results" export function getFilenameFromUrl(url: string) { return new URL(url, window.location.href).pathname.split("/").pop() } export const diDataContextFromURLHandler: DIHandler = { - // The API tester has a template for this under the dataContext section. // Because the download is async we won't know if this succeeded or failed until it // has been downloaded. As a first pass we always say it succeeds. And then when if // it fails we show an alert. - create(resources: DIResources, _values?: DIValues) { + create(_resources: DIResources, _values?: DIValues) { const values = _values as DIUrl | undefined - if (!values || !(typeof values === "object") || !values.URL) return kInvalidValuesError + if (!values || !(typeof values === "object") || !values.URL) { + return fieldRequiredResult("create", "dataContextFromURL", "URL") + } const url = values.URL @@ -54,7 +50,7 @@ export const diDataContextFromURLHandler: DIHandler = { return { success: true } } catch (e) { - return { success: false, values: { error: "Failed to download CSV file"}} + return errorResult(t("V3.DI.Error.downloadCSV")) } } } diff --git a/v3/src/utilities/translation/lang/en-US.json5 b/v3/src/utilities/translation/lang/en-US.json5 index 7cf1d97be..6afc5648a 100644 --- a/v3/src/utilities/translation/lang/en-US.json5 +++ b/v3/src/utilities/translation/lang/en-US.json5 @@ -117,6 +117,7 @@ "V3.DI.Error.caseNotFound": "Case not found", "V3.DI.Error.collectionNotFound": "Collection not found", "V3.DI.Error.componentNotCreated": "Could not create component", + "V3.DI.Error.downloadCSV": "Failed to download CSV file", "V3.DI.Error.illegalAttributeAssignment": "Cannot assign %@1 to %@2", "V3.DI.Error.componentNotFound": "Component not found", "V3.DI.Error.unsupportedComponent": "Unsupported component type %@",