diff --git a/v3/src/components/calculator/calculator-registration.test.ts b/v3/src/components/calculator/calculator-registration.test.ts index 260f16c6b..3250a27bf 100644 --- a/v3/src/components/calculator/calculator-registration.test.ts +++ b/v3/src/components/calculator/calculator-registration.test.ts @@ -61,6 +61,6 @@ describe("Calculator registration", () => { })! const output = exportV2Component({ tile, row: freeTileRow }) expect(output?.type).toBe(kV2CalculatorDGType) - expect(output?.componentStorage.name).toBe(calculatorContentInfo?.defaultName?.()) + expect(output?.componentStorage?.name).toBe(calculatorContentInfo?.defaultName?.()) }) }) diff --git a/v3/src/components/calculator/calculator-registration.ts b/v3/src/components/calculator/calculator-registration.ts index b6efbba57..960ff2641 100644 --- a/v3/src/components/calculator/calculator-registration.ts +++ b/v3/src/components/calculator/calculator-registration.ts @@ -50,7 +50,8 @@ registerTileComponentInfo({ registerV2TileImporter(kV2CalculatorDGType, ({ v2Component, insertTile }) => { if (!isV2CalculatorComponent(v2Component)) return - const { guid, componentStorage: { name = "", title = "" } } = v2Component + const { guid, componentStorage } = v2Component + const { name = "", title = "" } = componentStorage || {} const content: ICalculatorSnapshot = { type: kCalculatorTileType, diff --git a/v3/src/components/graph/v2-graph-importer.test.ts b/v3/src/components/graph/v2-graph-importer.test.ts index 4d1a58dd3..bb625898c 100644 --- a/v3/src/components/graph/v2-graph-importer.test.ts +++ b/v3/src/components/graph/v2-graph-importer.test.ts @@ -21,7 +21,7 @@ function firstGraphComponent(v2Document: CodapV2Document) { } function graphComponentWithTitle(v2Document: CodapV2Document, title: string) { - return v2Document.components.find(c => c.componentStorage.title === title)! + return v2Document.components.find(c => c.componentStorage?.title === title)! } describe("V2GraphImporter", () => { @@ -45,7 +45,7 @@ describe("V2GraphImporter", () => { sharedModelManager.setDocument(docContent) // load shared models into sharedModelManager - v2Document.contexts.forEach(({ guid }) => { + v2Document.dataContexts.forEach(({ guid }) => { const { data, metadata } = v2Document.getDataAndMetadata(guid) data && sharedModelManager!.addSharedModel(data) metadata?.setData(data?.dataSet) diff --git a/v3/src/components/map/v2-map-importer.test.ts b/v3/src/components/map/v2-map-importer.test.ts index e9426ff3b..d369ba982 100644 --- a/v3/src/components/map/v2-map-importer.test.ts +++ b/v3/src/components/map/v2-map-importer.test.ts @@ -38,7 +38,7 @@ describe("V2MapImporter imports legacy v2 map documents", () => { sharedModelManager.setDocument(docContent) // load shared models into sharedModelManager - v2Document.contexts.forEach(({ guid }) => { + v2Document.dataContexts.forEach(({ guid }) => { const { data, metadata } = v2Document.getDataAndMetadata(guid) data && sharedModelManager!.addSharedModel(data) metadata?.setData(data?.dataSet) @@ -84,7 +84,7 @@ describe("V2MapImporter imports current v2 map documents", () => { sharedModelManager.setDocument(docContent) // load shared models into sharedModelManager - v2Document.contexts.forEach(({ guid }) => { + v2Document.dataContexts.forEach(({ guid }) => { const { data, metadata } = v2Document.getDataAndMetadata(guid) data && sharedModelManager!.addSharedModel(data) metadata?.setData(data?.dataSet) diff --git a/v3/src/components/web-view/web-view-registration.ts b/v3/src/components/web-view/web-view-registration.ts index a479ac93c..0db358837 100644 --- a/v3/src/components/web-view/web-view-registration.ts +++ b/v3/src/components/web-view/web-view-registration.ts @@ -42,7 +42,7 @@ registerTileComponentInfo({ function addWebViewSnapshot(args: V2TileImportArgs, guid: number, url?: string, state?: unknown) { const { v2Component, insertTile } = args - const { name, title, userSetTitle } = v2Component.componentStorage + const { name, title, userSetTitle } = v2Component.componentStorage || {} const content: IWebViewSnapshot = { type: kWebViewTileType, diff --git a/v3/src/v2/codap-v2-document.ts b/v3/src/v2/codap-v2-document.ts index 7c3ba2bb1..7131e157d 100644 --- a/v3/src/v2/codap-v2-document.ts +++ b/v3/src/v2/codap-v2-document.ts @@ -51,6 +51,10 @@ export class CodapV2Document { return this.document.contexts } + get dataContexts() { + return this.document.contexts.filter(context => "guid" in context) + } + get components() { return this.document.components } @@ -201,7 +205,8 @@ export class CodapV2Document { // for level 0 (child-most collection), add items with their item ids and stash case ids if (level === 0) { // FIXME: values can include objects not just the primitives defined by IValueType - let itemValues = { __id__: itemID, ...toCanonical(data, values as any) } + // FIXME: should the itemID overwrite any __id__ returned by toCanonical? + let itemValues = { ...toCanonical(data, values as any), __id__: itemID } // look up parent case attributes and add them to caseValues for (let parentCase = this.getParentCase(_case); parentCase; parentCase = this.getParentCase(parentCase)) { itemValues = { diff --git a/v3/src/v2/codap-v2-tile-exporters.ts b/v3/src/v2/codap-v2-tile-exporters.ts index 4a18dce2c..cada983a4 100644 --- a/v3/src/v2/codap-v2-tile-exporters.ts +++ b/v3/src/v2/codap-v2-tile-exporters.ts @@ -1,4 +1,3 @@ -import { SetOptional } from "type-fest" import { kDefaultTileHeight, kDefaultTileWidth, kTitleBarHeight } from "../components/constants" import { IFreeTileRow, isFreeTileLayout } from "../models/document/free-tile-row" import { ISharedModelManager } from "../models/shared/shared-model-manager" @@ -8,7 +7,7 @@ import { CodapV2Component, CodapV2ComponentStorage } from "./codap-v2-types" export interface V2ExporterOutput { type: CodapV2Component["type"] - storage?: SetOptional + storage?: CodapV2ComponentStorage } export interface V2TileExportArgs {