From 3cb66a462feb5aa488c3d4890f7fcddc2832c6e0 Mon Sep 17 00:00:00 2001 From: Kirk Swenson Date: Tue, 24 Dec 2024 12:11:12 -0800 Subject: [PATCH] fix: v2 slider export --- v3/src/components/slider/slider-registration.test.ts | 11 ++++++++++- v3/src/components/slider/slider-registration.ts | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/v3/src/components/slider/slider-registration.test.ts b/v3/src/components/slider/slider-registration.test.ts index b95b077be..2a69896a5 100644 --- a/v3/src/components/slider/slider-registration.test.ts +++ b/v3/src/components/slider/slider-registration.test.ts @@ -1,3 +1,4 @@ +import { getSnapshot } from "mobx-state-tree" import { createCodapDocument } from "../../models/codap/create-codap-document" import { FreeTileRow, IFreeTileRow } from "../../models/document/free-tile-row" import { GlobalValue, IGlobalValueSnapshot } from "../../models/global/global-value" @@ -5,6 +6,7 @@ import { getTileComponentInfo } from "../../models/tiles/tile-component-info" import { getTileContentInfo } from "../../models/tiles/tile-content-info" import { getGlobalValueManager, getSharedModelManager } from "../../models/tiles/tile-environment" import { ITileModelSnapshotIn } from "../../models/tiles/tile-model" +import { toV2Id } from "../../utilities/codap-utils" import { CodapV2Document } from "../../v2/codap-v2-document" import { exportV2Component } from "../../v2/codap-v2-tile-exporters" import { importV2Component } from "../../v2/codap-v2-tile-importers" @@ -63,9 +65,12 @@ describe("Slider registration", () => { expect(tile).toBeDefined() expect(mockInsertTile).toHaveBeenCalledTimes(1) expect(globalValueManager?.globals.size).toBe(1) + const globalValue = Object.values(getSnapshot(globalValueManager!.globals))[0] const sliderModel = isSliderModel(tile.content) ? tile.content : undefined expect(sliderModel).toBeDefined() + expect(sliderModel?.name).toBe(globalValue.name) + expect(sliderModel?.value).toBeCloseTo(globalValue._value) expect(sliderModel?.animationDirection).toBe("lowToHigh") expect(sliderModel?.animationMode).toBe("onceOnly") expect(sliderModel?._animationRate).toBeUndefined() @@ -90,7 +95,11 @@ describe("Slider registration", () => { const sliderExport = exportV2Component({ tile, row, sharedModelManager }) expect(sliderExport?.type).toBe("DG.SliderView") const sliderStorage = sliderExport!.componentStorage as ICodapV2SliderStorage - expect(sliderStorage._links_?.model).toBeDefined() + expect(sliderStorage._links_?.model).toEqual({ + type: "DG.GlobalValue", + id: toV2Id(globalValue.id) + }) + expect(sliderStorage.name).toBe(globalValue.name) expect(sliderStorage.animationDirection).toBe(1) expect(sliderStorage.animationMode).toBe(1) expect(sliderStorage.maxPerSecond).toBeNull() diff --git a/v3/src/components/slider/slider-registration.ts b/v3/src/components/slider/slider-registration.ts index 869631008..0f5db8db5 100644 --- a/v3/src/components/slider/slider-registration.ts +++ b/v3/src/components/slider/slider-registration.ts @@ -79,6 +79,8 @@ registerV2TileExporter(kSliderTileType, ({ tile }) => { const sliderModel = isSliderModel(tile.content) ? tile.content : undefined if (!sliderModel) return const { + name, + globalValue, domain: [lowerBound, upperBound], animationDirection, animationMode, @@ -104,7 +106,8 @@ registerV2TileExporter(kSliderTileType, ({ tile }) => { const v3: ICodapV2SliderStorage["v3"] = { scaleType, multipleOf, dateMultipleOfUnit } const componentStorage: SetOptional = { - _links_: { model: guidLink("DG.GlobalValue", toV2Id(tile.id)) }, + _links_: { model: guidLink("DG.GlobalValue", toV2Id(globalValue.id)) }, + name, // override tile `name` with slider model `name` (i.e. global value `name`) ...domain, animationDirection: getAnimationDirectionIndex(animationDirection), animationMode: getAnimationModeIndex(animationMode),