Skip to content

Commit

Permalink
fix up code to work with updated types
Browse files Browse the repository at this point in the history
  • Loading branch information
scytacki committed Dec 6, 2024
1 parent ec7d07b commit bac7f44
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?.())
})
})
3 changes: 2 additions & 1 deletion v3/src/components/calculator/calculator-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions v3/src/components/graph/v2-graph-importer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions v3/src/components/map/v2-map-importer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion v3/src/components/web-view/web-view-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion v3/src/v2/codap-v2-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 = {
Expand Down
24 changes: 14 additions & 10 deletions v3/src/v2/codap-v2-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ describe(`V2 "mammals.codap"`, () => {
expect(mammalsData.name).toBe("Mammals Sample")
expect(mammalsData.components?.length).toBe(5)
expect(mammalsData.contexts?.length).toBe(1)
expect(mammalsData.contexts?.[0].collections.length).toBe(1)
expect(mammalsData.contexts?.[0].collections?.[0].attrs.length).toBe(9)
expect(mammalsData.contexts?.[0].collections?.[0].cases.length).toBe(27)
const context = mammalsData.contexts?.[0]
if (! ("guid" in context)) throw new Error("Context is not a data context")
expect(context.collections.length).toBe(1)
expect(context.collections?.[0].attrs.length).toBe(9)
expect(context.collections?.[0].cases.length).toBe(27)
expect(mammalsData.globalValues?.length).toBe(0)
})

Expand All @@ -70,7 +72,7 @@ describe(`V2 "mammals.codap"`, () => {
expect(mammals.dataSets.length).toBe(1)

// numeric ids are converted to strings on import
const context = mammals.contexts[0]
const context = mammals.dataContexts[0]
const collection = context.collections[0]
const data = mammals.dataSets[0].dataSet
data.validateCases()
Expand Down Expand Up @@ -103,11 +105,13 @@ describe(`V2 "24cats.codap"`, () => {
expect(catsData.name).toBe("24cats")
expect(catsData.components?.length).toBe(5)
expect(catsData.contexts?.length).toBe(1)
expect(catsData.contexts?.[0].collections.length).toBe(2)
expect(catsData.contexts?.[0].collections?.[0].attrs.length).toBe(1)
expect(catsData.contexts?.[0].collections?.[0].cases.length).toBe(2)
expect(catsData.contexts?.[0].collections?.[1].attrs.length).toBe(8)
expect(catsData.contexts?.[0].collections?.[1].cases.length).toBe(24)
const context = catsData.contexts?.[0]
if (! ("guid" in context)) throw new Error("Context is not a data context")
expect(context.collections.length).toBe(2)
expect(context.collections?.[0].attrs.length).toBe(1)
expect(context.collections?.[0].cases.length).toBe(2)
expect(context.collections?.[1].attrs.length).toBe(8)
expect(context.collections?.[1].cases.length).toBe(24)
expect(catsData.globalValues?.length).toBe(0)
})

Expand All @@ -119,7 +123,7 @@ describe(`V2 "24cats.codap"`, () => {
expect(cats.dataSets.length).toBe(1)

// numeric ids are converted to strings on import
const context = cats.contexts[0]
const context = cats.dataContexts[0]
const [v2ParentCollection, v2ChildCollection] = context.collections
const data = cats.dataSets[0].dataSet
data.validateCases()
Expand Down
3 changes: 1 addition & 2 deletions v3/src/v2/codap-v2-tile-exporters.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -8,7 +7,7 @@ import { CodapV2Component, CodapV2ComponentStorage } from "./codap-v2-types"

export interface V2ExporterOutput {
type: CodapV2Component["type"]
storage?: SetOptional<CodapV2ComponentStorage, "cannotClose" | "userSetTitle">
storage?: CodapV2ComponentStorage
}

export interface V2TileExportArgs {
Expand Down

0 comments on commit bac7f44

Please sign in to comment.