Skip to content

Commit

Permalink
Show union of properties instead of intersection of selected classes …
Browse files Browse the repository at this point in the history
…in filtering dialog (#358)

* initial implementation

* changelog

* comment edit
  • Loading branch information
ViliusBa authored Dec 13, 2023
1 parent d140061 commit 19230a3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-points-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@itwin/presentation-components": minor
---

Show union of properties of selected classes in filtering dialog instead of intersection.
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ async function computePropertiesByClasses(
const ecClassInfos = await Promise.all(classes.map(async (info) => metadataProvider.getECClassInfo(info.id)));
const filteredProperties: PresentationInstanceFilterPropertyInfo[] = [];
for (const prop of properties) {
// property should be shown if all selected classes are derived from property source class
if (ecClassInfos.every((info) => info && info.isDerivedFrom(prop.sourceClassId))) {
// property should be shown if at least one of selected classes is derived from property source class
if (ecClassInfos.some((info) => info && info.isDerivedFrom(prop.sourceClassId))) {
filteredProperties.push(prop);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,27 @@ describe("usePresentationInstanceFilteringProps", () => {
await waitFor(() => expect(result.current.properties).to.have.lengthOf(2));
});

it("returns union of properties that are derived from two selected classes", async () => {
const testDescriptor = createTestContentDescriptor({
selectClasses: [
{ selectClassInfo: concreteClass1, isSelectPolymorphic: false },
{ selectClassInfo: concreteClass2, isSelectPolymorphic: false },
],
categories: [category],
fields: [basePropertiesField, concretePropertiesField1, concretePropertiesField2],
});

const { result } = renderHook((props: HookProps) => usePresentationInstanceFilteringProps(props.descriptor, props.imodel), {
initialProps: { ...initialProps, descriptor: testDescriptor },
});

act(() => {
result.current.onSelectedClassesChanged([concreteClass1.id, concreteClass2.id]);
});

await waitFor(() => expect(result.current.properties).to.have.lengthOf(3));
});

it("selects classes that have selected property", async () => {
const { result } = renderHook((props: HookProps) => usePresentationInstanceFilteringProps(props.descriptor, props.imodel), { initialProps });

Expand Down

0 comments on commit 19230a3

Please sign in to comment.