Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: v2 slider export #1705

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion v3/src/components/slider/slider-registration.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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"
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"
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion v3/src/components/slider/slider-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -104,7 +106,8 @@ registerV2TileExporter(kSliderTileType, ({ tile }) => {
const v3: ICodapV2SliderStorage["v3"] = { scaleType, multipleOf, dateMultipleOfUnit }

const componentStorage: SetOptional<ICodapV2SliderStorage, keyof ICodapV2BaseComponentStorage> = {
_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),
Expand Down
Loading