Skip to content

Commit

Permalink
187458550 v3 DI Delete Component Hides Singletons (#1232)
Browse files Browse the repository at this point in the history
* Hide, don't delete, tables and case cards as well as singletons.
  • Loading branch information
tealefristoe authored Apr 26, 2024
1 parent d4dbccf commit f5820d1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
3 changes: 2 additions & 1 deletion v3/src/components/case-card/case-card-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ registerTileContentInfo({
type: kCaseCardTileType,
prefix: kCaseCardIdPrefix,
modelClass: CaseCardModel,
defaultContent: () => ({ type: kCaseCardTileType })
defaultContent: () => ({ type: kCaseCardTileType }),
hideOnClose: true
})

registerTileComponentInfo({
Expand Down
3 changes: 2 additions & 1 deletion v3/src/components/case-table/case-table-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ registerTileContentInfo({
type: kCaseTableTileType,
prefix: kCaseTableIdPrefix,
modelClass: CaseTableModel,
defaultContent: () => ({ type: kCaseTableTileType })
defaultContent: () => ({ type: kCaseTableTileType }),
hideOnClose: true
})

registerTileComponentInfo({
Expand Down
1 change: 1 addition & 0 deletions v3/src/data-interactive/data-interactive-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface DICase {
export type DICollection = Partial<ICodapV2Collection>
export type DIComponent = ITileModel
export interface DIComponentInfo {
hidden?: boolean
id?: string
name?: string
title?: string
Expand Down
9 changes: 6 additions & 3 deletions v3/src/data-interactive/handlers/component-handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { t } from "../../utilities/translation/translate"
import { appState } from "../../models/app-state"
import { uiState } from "../../models/ui-state"
import { registerDIHandler } from "../data-interactive-handler"
import { DIHandler, DINotification, DIResources, DIValues } from "../data-interactive-types"
import { uiState } from "../../models/ui-state"
import { appState } from "../../models/app-state"

const componentNotFoundResult = { success: false, values: { error: t("V3.DI.Error.componentNotFound") } } as const

Expand All @@ -11,7 +11,10 @@ export const diComponentHandler: DIHandler = {
const { component } = resources
if (!component) return componentNotFoundResult

appState.document.deleteTile(component.id)
const { document } = appState
document.applyModelChange(() => {
document.content?.deleteOrHideTile(component.id)
})

return { success: true }
},
Expand Down
8 changes: 6 additions & 2 deletions v3/src/data-interactive/handlers/component-list-handler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { isWebViewModel } from "../../components/web-view/web-view-model"
import { appState } from "../../models/app-state"
import { isFreeTileLayout } from "../../models/document/free-tile-row"
import { kComponentTypeV3ToV2Map, kV2GameType, kV2WebViewType } from "../data-interactive-component-types"
import { registerDIHandler } from "../data-interactive-handler"
import { DIComponentInfo, DIHandler, DIResources } from "../data-interactive-types"

export const diComponentListHandler: DIHandler = {
get(_resources: DIResources) {
const { document } = appState
const values: DIComponentInfo[] = []
appState.document.content?.tileMap.forEach(tile => {
document.content?.tileMap.forEach(tile => {
// TODO Should we add names to tiles?
// TODO Tiles sometimes show titles different than tile.title. Should we return those?
const { content, id, title } = tile
Expand All @@ -16,7 +18,9 @@ export const diComponentListHandler: DIHandler = {
? kV2GameType
: kV2WebViewType
: kComponentTypeV3ToV2Map[content.type]
values.push({ id, title, type })
const tileLayout = document.content?.getTileLayoutById(id)
const hidden = isFreeTileLayout(tileLayout) ? !!tileLayout.isHidden : false
values.push({ hidden, id, title, type })
})

return { success: true, values }
Expand Down
13 changes: 13 additions & 0 deletions v3/src/models/document/document-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ export const DocumentContentModel = BaseDocumentContentModel
return self.createTile(tileType, options)
}
}
},
// Hide the tile if it should hide on close or is a singleton and can be hidden. Otherwise, delete it.
deleteOrHideTile(tileId: string) {
const tile = self.getTile(tileId)
const tileInfo = getTileContentInfo(tile?.content.type)
if (tileInfo?.hideOnClose || tileInfo?.isSingleton) {
const tileLayout = self.getTileLayoutById(tileId)
if (isFreeTileLayout(tileLayout)) {
tileLayout.setHidden(true)
return
}
}
self.deleteTile(tileId)
}
}))
.actions(self => ({
Expand Down
1 change: 1 addition & 0 deletions v3/src/models/tiles/tile-content-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ITileContentInfo {
titleBase?: string;
metadataClass?: typeof TileMetadataModel;
isSingleton?: boolean; // Only one instance of a tile is open per document (calculator and guide)
hideOnClose?: boolean;
addSidecarNotes?: boolean;
defaultHeight?: number;
exportNonDefaultHeight?: boolean;
Expand Down

0 comments on commit f5820d1

Please sign in to comment.