From 19230a394ce22437c3ab19ab412efc2420db0e2a Mon Sep 17 00:00:00 2001 From: ViliusBa <114080994+ViliusBa@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:27:37 +0200 Subject: [PATCH] Show union of properties instead of intersection of selected classes in filtering dialog (#358) * initial implementation * changelog * comment edit --- .changeset/happy-points-draw.md | 5 +++++ .../InstanceFilterBuilder.tsx | 4 ++-- .../IntanceFilterBuilder.test.tsx | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .changeset/happy-points-draw.md diff --git a/.changeset/happy-points-draw.md b/.changeset/happy-points-draw.md new file mode 100644 index 000000000..0b24b6c02 --- /dev/null +++ b/.changeset/happy-points-draw.md @@ -0,0 +1,5 @@ +--- +"@itwin/presentation-components": minor +--- + +Show union of properties of selected classes in filtering dialog instead of intersection. diff --git a/packages/components/src/presentation-components/instance-filter-builder/InstanceFilterBuilder.tsx b/packages/components/src/presentation-components/instance-filter-builder/InstanceFilterBuilder.tsx index 91379b55c..9114150c5 100644 --- a/packages/components/src/presentation-components/instance-filter-builder/InstanceFilterBuilder.tsx +++ b/packages/components/src/presentation-components/instance-filter-builder/InstanceFilterBuilder.tsx @@ -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); } } diff --git a/packages/components/src/test/instance-filter-builder/IntanceFilterBuilder.test.tsx b/packages/components/src/test/instance-filter-builder/IntanceFilterBuilder.test.tsx index 2c3f71668..d72122259 100644 --- a/packages/components/src/test/instance-filter-builder/IntanceFilterBuilder.test.tsx +++ b/packages/components/src/test/instance-filter-builder/IntanceFilterBuilder.test.tsx @@ -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 });