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 5, 2024
1 parent ec7d07b commit ed2992f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 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
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 ed2992f

Please sign in to comment.