From 97881bbd79c521ed1e09fef1eb92af0a5aa53e6d Mon Sep 17 00:00:00 2001 From: Scott Cytacki Date: Mon, 2 Dec 2024 14:36:57 -0500 Subject: [PATCH] Update the types to match some docs in cfm-shared This are only the updates required to validate the first 20 or so files in cfm-shared. Also this is ignoring properties that those files define but are not declared in the v2 types. --- .../graph/adornments/v2-adornment-importer.ts | 2 +- v3/src/components/graph/v2-graph-importer.ts | 4 +- v3/src/v2/codap-v2-types.ts | 86 +++++++++++++------ v3/src/v2/import-v2-document.ts | 2 +- 4 files changed, 66 insertions(+), 28 deletions(-) diff --git a/v3/src/components/graph/adornments/v2-adornment-importer.ts b/v3/src/components/graph/adornments/v2-adornment-importer.ts index 39a0fc6db..9b89d937b 100644 --- a/v3/src/components/graph/adornments/v2-adornment-importer.ts +++ b/v3/src/components/graph/adornments/v2-adornment-importer.ts @@ -235,7 +235,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA const lines: Record = {} instanceKeys?.forEach((key: string) => { const lsrlInstances: ILSRLInstanceSnapshot[] = [] - lsrlAdornment.lsrls.forEach((lsrl) => { + lsrlAdornment.lsrls?.forEach((lsrl) => { const lsrlInstance = { equationCoords: lsrl.equationCoords ?? undefined // The V2 default is null, but we want undefined } diff --git a/v3/src/components/graph/v2-graph-importer.ts b/v3/src/components/graph/v2-graph-importer.ts index 2b81f3351..215e9fe7d 100644 --- a/v3/src/components/graph/v2-graph-importer.ts +++ b/v3/src/components/graph/v2-graph-importer.ts @@ -27,7 +27,7 @@ export function v2GraphImporter({v2Component, v2Document, sharedModelManager, in pointColor, strokeColor, pointSizeMultiplier, strokeSameAsFill, isTransparent, plotBackgroundImageLockInfo, - /* The following are present in the componentStorage but not used in the V3 content model (yet): + /* TODO_V2_IMPORT: The following are present in the componentStorage but not used in the V3 content model (yet): displayOnlySelected, legendRole, legendAttributeType, numberOfLegendQuantiles, legendQuantilesAreLocked, plotBackgroundImage, transparency, strokeTransparency, plotBackgroundOpacity, @@ -65,6 +65,8 @@ export function v2GraphImporter({v2Component, v2Document, sharedModelManager, in const v2AttrId = aLink.id, attribute = v2Document.getV3Attribute(v2AttrId), v3AttrId = attribute?.id ?? '', + // This approach of dynamic key computation bypasses the typing in ICodapV2GraphStorage, + // there might be a typescript approach which fixes this. attrRoleKey = `${attrKey}Role` as keyof ICodapV2GraphStorage, v2Role = v2Component.componentStorage[attrRoleKey], attrTypeKey = `${attrKey}AttributeType` as keyof ICodapV2GraphStorage, diff --git a/v3/src/v2/codap-v2-types.ts b/v3/src/v2/codap-v2-types.ts index 4c134387a..59af0a035 100644 --- a/v3/src/v2/codap-v2-types.ts +++ b/v3/src/v2/codap-v2-types.ts @@ -8,7 +8,10 @@ export type AllowStringIds = Omit & { export interface ICodapV2Attribute { guid: number - id: number + // A document generated by build 0512 did not have this id + // It is ignored by the import code, however it is used by + // `convertValuesToAttributeSnapshot` this usage seems incorrect + id?: number name: string type?: string | null title?: string @@ -80,7 +83,7 @@ export interface ICodapV2Collection { } name: string parent?: number - title: string + title: string | null type: "DG.Collection" } // when exporting a v3 collection to v2 @@ -97,7 +100,9 @@ export interface ICodapV2DataContext { type: "DG.DataContext" document?: number // id of containing document guid: number - id: number + // This was not present in a file generated by 0512. + // It also seems to be be ignored by the import code + id?: number flexibleGroupingChangeFlag: boolean name: string title: string @@ -133,7 +138,14 @@ export interface ICodapV2BaseComponentStorage { title?: string name?: string userSetTitle: boolean - cannotClose: boolean + // in a document saved by build 0441 this property didn't exist + // TODO_V2_IMPORT: this property seems to be ignored by the import code + // The v3 models do support it, but from what I can tell each component + // importer needs to read this property from componentStorage and then + // set it on the tile snapshot they pass to insertTile + // In the CFM shared files there are more than 20,000 examples of cannotClose: true + // and more 20,000 examples cannotClose: false + cannotClose?: boolean } export interface ICodapV2CalculatorStorage extends ICodapV2BaseComponentStorage { @@ -150,7 +162,7 @@ export interface ICodapV2SliderStorage extends ICodapV2BaseComponentStorage { animationMode: number restrictToMultiplesOf: number | null maxPerSecond: number | null - userTitle: boolean + userTitle?: boolean } export interface ICodapV2TableStorage extends ICodapV2BaseComponentStorage { @@ -166,6 +178,13 @@ export interface ICodapV2TableStorage extends ICodapV2BaseComponentStorage { title: string } +export interface ICodapV2CaseCardStorage extends ICodapV2BaseComponentStorage { + _links_: { + context: IGuidLink<"DG.DataContextRecord"> + } + title: string +} + export interface ICodapV2WebViewStorage extends ICodapV2BaseComponentStorage { URL: string } @@ -286,13 +305,15 @@ interface ICodapV2LSRL { showConfidenceBands: boolean } +// In a doc generated by build 0441: +// enableMeasuresForSelection, showConfidenceBands, and lsrls were not defined interface ICodapV2MultipleLSRLsStorage { isVisible: boolean - enableMeasuresForSelection: boolean + enableMeasuresForSelection?: boolean showSumSquares: boolean isInterceptLocked: boolean - showConfidenceBands: boolean - lsrls: ICodapV2LSRL[] + showConfidenceBands?: boolean + lsrls?: ICodapV2LSRL[] } export interface ICodapV2PlotStorage { @@ -331,25 +352,33 @@ export interface ICodapV2GraphStorage extends ICodapV2BaseComponentStorage { legendQuantilesAreLocked?: boolean pointColor: string strokeColor: string - pointSizeMultiplier: 1 + // This was constrained to 1 in the types before, but there are many v2 documents + // where this is not 1. Values seem to range from 0.5 to 3 + pointSizeMultiplier: number transparency: number strokeTransparency: number - strokeSameAsFill: boolean + // This property was not defined in a document from build 0473 + strokeSameAsFill?: boolean isTransparent: boolean plotBackgroundColor?: string | null plotBackgroundOpacity: number - plotBackgroundImageLockInfo: any - plotBackgroundImage: string | null + plotBackgroundImageLockInfo?: any + plotBackgroundImage?: string | null xRole: number xAttributeType: number yRole: number yAttributeType: number y2Role: number y2AttributeType: number - topRole: number - topAttributeType: number - rightRole: number - rightAttributeType: number + + // The right* and top* properties were not defined in a document from build 0473 + topRole?: number + topAttributeType?: number + topAxisClass?: string + rightRole?: number + rightAttributeType?: number + rightAxisClass?: string + xAxisClass: string xLowerBound?: number xUpperBound?: number @@ -359,8 +388,6 @@ export interface ICodapV2GraphStorage extends ICodapV2BaseComponentStorage { y2AxisClass: string y2LowerBound?: number y2UpperBound?: number - topAxisClass: string - rightAxisClass: string plotModels: ICodapV2PlotModel[] } @@ -405,7 +432,7 @@ export interface ICodapV2MapStorage extends ICodapV2BaseComponentStorage { export interface ICodapV2GuideStorage extends ICodapV2BaseComponentStorage { currentItemIndex?: number isVisible?: boolean - items: Array<{ itemTitle: string, url: string }> + items: Array<{ itemTitle: string | null, url: string }> } export interface ICodapV2TextStorage extends ICodapV2BaseComponentStorage { @@ -421,8 +448,9 @@ export interface ICodapV2BaseComponent { id?: number componentStorage: Record layout: { - width: number - height: number + // A GameView saved by build 0606 had no width or height + width?: number + height?: number left?: number top?: number isVisible: boolean @@ -450,6 +478,13 @@ export interface ICodapV2TableComponent extends ICodapV2BaseComponent { } export const isV2TableComponent = (component: ICodapV2BaseComponent): component is ICodapV2TableComponent => component.type === "DG.TableView" + +// TODO_V2_IMPORT: handle importing case cards: +// https://www.pivotaltracker.com/story/show/188596023 +export interface ICodapV2CaseCardComponent extends ICodapV2BaseComponent { + type: "DG.CaseCard" + componentStorage: ICodapV2CaseCardStorage +} export interface ICodapV2WebViewComponent extends ICodapV2BaseComponent { type: "DG.WebView" componentStorage: ICodapV2WebViewStorage @@ -491,15 +526,16 @@ export interface ICodapV2TextComponent extends ICodapV2BaseComponent { export const isV2TextComponent = (component: ICodapV2BaseComponent): component is ICodapV2TextComponent => component.type === "DG.TextView" -export type CodapV2Component = ICodapV2CalculatorComponent | ICodapGameViewComponent | ICodapV2GraphComponent | - ICodapV2GuideComponent | ICodapV2MapComponent | ICodapV2SliderComponent | - ICodapV2TableComponent | ICodapV2TextComponent | ICodapV2WebViewComponent +export type CodapV2Component = ICodapV2CalculatorComponent | ICodapV2CaseCardComponent| ICodapGameViewComponent | + ICodapV2GraphComponent | ICodapV2GuideComponent | ICodapV2MapComponent | + ICodapV2SliderComponent | ICodapV2TableComponent | ICodapV2TextComponent | + ICodapV2WebViewComponent export interface ICodapV2DocumentJson { type?: string // "DG.Document" id?: number guid: number - name: string + name: string | null appName: string // "DG" appVersion: string appBuildNum: string diff --git a/v3/src/v2/import-v2-document.ts b/v3/src/v2/import-v2-document.ts index 7222dd664..e7bec5c70 100644 --- a/v3/src/v2/import-v2-document.ts +++ b/v3/src/v2/import-v2-document.ts @@ -46,7 +46,7 @@ export function importV2Document(v2Document: CodapV2Document) { layout: { left = 0, top = 0, width, height: v2Height, isVisible, zIndex }, savedHeight } = v2Component const isHidden = isVisible === false - const v2Minimized = (!!savedHeight && savedHeight >= v2Height) || undefined + const v2Minimized = (!!savedHeight && v2Height != null && savedHeight >= v2Height) || undefined const isMinimized = v2Minimized && !isHidden const height = savedHeight && v2Minimized ? savedHeight : v2Height // only apply imported width and height to resizable tiles