-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle get collection requests. * Handle create item and get attribtueList requests. * Handle create caseTable component requests.
- Loading branch information
1 parent
9b547c4
commit 912e18a
Showing
24 changed files
with
484 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { appState } from "../../models/app-state" | ||
import { createDefaultTileOfType } from "../../models/codap/add-default-content" | ||
import { isFreeTileLayout } from "../../models/document/free-tile-row" | ||
import { | ||
ISharedCaseMetadata, kSharedCaseMetadataType, SharedCaseMetadata | ||
} from "../../models/shared/shared-case-metadata" | ||
import { ISharedDataSet } from "../../models/shared/shared-data-set" | ||
import { getTileComponentInfo } from "../../models/tiles/tile-component-info" | ||
import { getSharedModelManager } from "../../models/tiles/tile-environment" | ||
import { uiState } from "../../models/ui-state" | ||
import { ComponentRect } from "../../utilities/animation-utils" | ||
import { getPositionOfNewComponent } from "../../utilities/view-utils" | ||
import { kTitleBarHeight } from "../constants" | ||
import { kCaseTableTileType } from "./case-table-defs" | ||
|
||
export const createTableForDataset = (model: ISharedDataSet, caseMetadata: ISharedCaseMetadata) => { | ||
const document = appState.document | ||
const { content } = document | ||
const row = content?.getRowByIndex(0) | ||
const manager = getSharedModelManager(document) | ||
const caseTableComponentInfo = getTileComponentInfo(kCaseTableTileType) | ||
if (!content || !row || !caseTableComponentInfo) return | ||
|
||
const caseTableTileId = caseMetadata.caseTableTileId | ||
if (caseTableTileId) { | ||
content?.toggleNonDestroyableTileVisibility(caseTableTileId) | ||
return | ||
} | ||
|
||
const tile = createDefaultTileOfType(kCaseTableTileType) | ||
if (!tile) return | ||
|
||
manager?.addTileSharedModel(tile.content, model, true) | ||
manager?.addTileSharedModel(tile.content, caseMetadata, true) | ||
caseMetadata.setCaseTableTileId(tile.id) | ||
|
||
const width = caseTableComponentInfo.defaultWidth || 0 | ||
const height = caseTableComponentInfo.defaultHeight || 0 | ||
const {x, y} = getPositionOfNewComponent({width, height}) | ||
const from: ComponentRect = { x: 0, y: 0, width: 0, height: kTitleBarHeight }, | ||
to: ComponentRect = { x, y, width, height: height + kTitleBarHeight} | ||
content?.insertTileInRow(tile, row, from) | ||
uiState.setFocusedTile(tile.id) | ||
const tileLayout = content.getTileLayoutById(tile.id) | ||
if (!isFreeTileLayout(tileLayout)) return | ||
// use setTimeout to push the change into a subsequent action | ||
setTimeout(() => { | ||
// use applyModelChange to wrap into a single non-undoable action without undo string | ||
content.applyModelChange(() => { | ||
tileLayout.setPosition(to.x, to.y) | ||
tileLayout.setSize(to.width, to.height) | ||
}) | ||
}) | ||
|
||
return tile | ||
} | ||
|
||
export const createOrShowTableForDataset = (sharedDataset: ISharedDataSet) => { | ||
const document = appState.document | ||
const { content } = document | ||
const manager = getSharedModelManager(document) | ||
const caseMetadatas = manager?.getSharedModelsByType<typeof SharedCaseMetadata>(kSharedCaseMetadataType) | ||
|
||
const model = manager?.getSharedModelsByType("SharedDataSet") | ||
.find(m => m.id === sharedDataset.id) as ISharedDataSet | undefined | ||
const caseMetadata = caseMetadatas?.find(cm => cm.data?.id === model?.dataSet.id) | ||
if (!model || !caseMetadata) return | ||
const existingTileId = caseMetadata.lastShownTableOrCardTileId | ||
if (existingTileId) { // We already have a case table so make sure it's visible and has focus | ||
if (content?.isTileHidden(existingTileId)) { | ||
content?.toggleNonDestroyableTileVisibility(existingTileId) | ||
} | ||
uiState.setFocusedTile(existingTileId) | ||
return content?.tileMap.get(existingTileId) | ||
} else { // We don't already have a table for this dataset | ||
return createTableForDataset(model, caseMetadata) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 5 additions & 29 deletions
34
v3/src/data-interactive/handlers/all-cases-handler.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
v3/src/data-interactive/handlers/attribute-list-handler.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ICodapV2Attribute } from "../../v2/codap-v2-types" | ||
import { diAttributeListHandler } from "./attribute-list-handler" | ||
import { setupTestDataset } from "./handler-test-utils" | ||
|
||
describe("DataInteractive AttributeListHandler", () => { | ||
const handler = diAttributeListHandler | ||
|
||
it("get works as expected", () => { | ||
const { a1, a2 } = setupTestDataset() | ||
|
||
expect(handler.get?.({})?.success).toBe(false) | ||
|
||
const result = handler.get?.({ attributeList: [a1, a2] }) | ||
expect(result?.success).toBe(true) | ||
const attributeList = result?.values as Partial<ICodapV2Attribute>[] | ||
expect(attributeList.length).toBe(2) | ||
const attr1 = attributeList[0] | ||
expect(attr1.name).toBe(a1.name) | ||
expect(attr1.title).toBe(a1.title) | ||
expect(attr1.id).toBe(a1.id) | ||
const attr2 = attributeList[1] | ||
expect(attr2.name).toBe(a2.name) | ||
expect(attr2.title).toBe(a2.title) | ||
expect(attr2.id).toBe(a2.id) | ||
}) | ||
}) |
18 changes: 18 additions & 0 deletions
18
v3/src/data-interactive/handlers/attribute-list-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { t } from "../../utilities/translation/translate" | ||
import { registerDIHandler } from "../data-interactive-handler" | ||
import { basicAttributeInfo } from "../data-interactive-type-utils" | ||
import { DIHandler, DIResources } from "../data-interactive-types" | ||
|
||
export const diAttributeListHandler: DIHandler = { | ||
get(resources: DIResources) { | ||
const { attributeList } = resources | ||
if (!attributeList) return { success: false, values: { error: t("V3.DI.Error.collectionNotFound") } } | ||
|
||
return { | ||
success: true, | ||
values: attributeList.map(attribute => basicAttributeInfo(attribute)) | ||
} | ||
} | ||
} | ||
|
||
registerDIHandler("attributeList", diAttributeListHandler) |
Oops, something went wrong.