Skip to content

Commit

Permalink
PR review cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
tealefristoe committed Dec 23, 2024
1 parent b2dada4 commit f182364
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
20 changes: 8 additions & 12 deletions v3/src/data-interactive/handlers/data-context-from-url-handler.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"))

Check warning on line 53 in v3/src/data-interactive/handlers/data-context-from-url-handler.ts

View check run for this annotation

Codecov / codecov/patch

v3/src/data-interactive/handlers/data-context-from-url-handler.ts#L53

Added line #L53 was not covered by tests
}
}
}
Expand Down
1 change: 1 addition & 0 deletions v3/src/utilities/translation/lang/en-US.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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 %@",
Expand Down

0 comments on commit f182364

Please sign in to comment.