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

Fixes table display bug when collection has one attribute and it is hidden #1836

Merged
merged 3 commits into from
Mar 11, 2025
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
4 changes: 2 additions & 2 deletions v3/src/data-interactive/handlers/collection-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ describe("DataInteractive CollectionHandler", () => {

it("get works", () => {
const documentContent = appState.document.content!
const { dataset } = setupTestDataset()
const { dataset, a3 } = setupTestDataset()
documentContent.createDataSet(getSnapshot(dataset))
const dataContext = getSharedDataSets(documentContent)[0].dataSet
const c1 = dataContext.collections[0]
expect(handler.get?.({}).success).toBe(false)
dataContext.moveAttribute(a3.id, { collection: c1.id })
expect(handler.get?.({ dataContext }).success).toBe(false)

// Grouped collection
Expand Down
29 changes: 27 additions & 2 deletions v3/src/models/shared/shared-case-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { observable } from "mobx"
import { getSnapshot, getType, Instance, ISerializedActionCall, types } from "mobx-state-tree"
import { observable, reaction, comparer } from "mobx"
import { getSnapshot, getType, Instance, ISerializedActionCall, types, addDisposer } from "mobx-state-tree"
import { onAnyAction } from "../../utilities/mst-utils"
import { CategorySet, createProvisionalCategorySet, ICategorySet } from "../data/category-set"
import { DataSet, IDataSet } from "../data/data-set"
Expand Down Expand Up @@ -194,6 +194,31 @@ export const SharedCaseMetadata = SharedModel
return categorySet
}
}))
.actions(self => ({
afterCreate() {
// respond to change of collections by showing hidden attributes if all attributes are hidden
addDisposer(self, reaction(
() => {
return {
hiddenAttrs: Array.from(self.hidden.keys()),
collections: self.data?.collections.map(collection => collection.attributes.map(attr => attr?.id)) || []
}
},
({hiddenAttrs}) => {
self.data?.collections.forEach(collection => {
const attrs = collection.attributes
if (attrs && attrs.every(attr => attr && hiddenAttrs.includes(attr.id))) {
attrs.forEach(attr => attr && self.setIsHidden(attr.id, false))
}
})
},
{ name: "DataConfigurationModel.afterCreate.reaction [show all hidden attributes in a collection]",
fireImmediately: true,
equals: comparer.structural
}
))
}
}))
.actions(applyModelChange)

export interface ISharedCaseMetadata extends Instance<typeof SharedCaseMetadata> {}
Expand Down