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

Add definitionContainers to categories tree #1172

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

JonasDov
Copy link
Contributor

closes #1126

@JonasDov JonasDov requested review from a team as code owners January 31, 2025 18:01
Copy link
Member

@grigasp grigasp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive set of tests - great work!

mergeMap(async (node) => validateNodeVisibility({ ...props, node })),
),
);
expect(props.nodesToExpect.every((nodeId) => nodesFound.includes(nodeId))).to.be.true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this check? we're testing visibility here, not the hierarchy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do. I think we need to confirm that visibility of expected nodes is checked. Theoretically, without this check, validateHierarchyVisibility could not check anything and it wouldn't fail

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this check, validateHierarchyVisibility could not check anything and it wouldn't fail

Yes, but that should be tested in our hierarchy tests, not visibility ones. This check unnecessarily complicates the tests, e.g.:

// this is only needed for checking what we got in the hierarchy
const expectedIds = [
  keys.definitionContainerRoot.id,
  keys.definitionContainerChild.id,
  keys.directCategory.id,
  keys.indirectCategory.id,
  keys.indirectSubCategory.id,
];
using visibilityTestData = await createVisibilityTestData({ imodel, isVisibleOnInitialize });
const { handler, provider, viewport } = visibilityTestData;
await handler.changeVisibility(createDefinitionContainerHierarchyNode(keys.definitionContainerRoot.id), true);
await validateHierarchyVisibility({
  provider,
  handler,
  viewport,
  visibilityExpectations: {},
  expectedIds,
  all: "visible",
});

JonasDov and others added 24 commits February 3, 2025 15:31
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts

Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts

Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts

Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/internal/CategoriesTreeNode.ts

Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/internal/CategoriesTreeNode.ts

Co-authored-by: Grigas <[email protected]>
…rnal/CategoriesTreeIdsCache.test.ts

Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/CategoriesTreeDefinition.ts

Co-authored-by: Grigas <[email protected]>
Comment on lines 57 to 62
const getCategoriesTreeIdsCache = useCallback(() => {
if (!idsCacheRef.current) {
idsCacheRef.current = new CategoriesTreeIdsCache(createECSqlQueryExecutor(iModel), viewType);
}
return idsCacheRef.current;
}, [viewType, iModel]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where idsCacheRef.current is reset when view type or iModel changes so it will always return same cache.

Copy link
Contributor Author

@JonasDov JonasDov Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, missed that, removed the condition, changed to useMemo

private static getInstanceIdFromHierarchyNode(node: HierarchyNode) {
return HierarchyNode.isInstancesNode(node) && node.key.instanceKeys.length > 0 ? node.key.instanceKeys[0].id : /* istanbul ignore next */ "";
private static getInstanceIdsFromHierarchyNode(node: HierarchyNode) {
return HierarchyNode.isInstancesNode(node) && node.key.instanceKeys.length > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need && node.key.instanceKeys.length > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removed

!HierarchyNodeIdentifier.isInstanceNodeIdentifier(secondToLastNode) ||
secondToLastNode.className === DEFINITION_CONTAINER_CLASS
) {
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't hide those bugs. I suggest changing this to an assert.

export class ViewportMock {
private _idsCache: CategoriesTreeIdsCache;
private _subCategories: Map<Id64String, boolean>;
export async function createViewportStub(idsCache: CategoriesTreeIdsCache, isVisibleOnInitialize = false): Promise<Viewport & ViewportStubValidation> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing args to props - easier to maintain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Comment on lines 65 to 68
}: Omit<ValidateNodeProps, "visibilityExpectations"> & {
visibilityExpectations: VisibilityExpectations;
provider: HierarchyProvider;
}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this?

Omit<ValidateNodeProps, "visibilityExpectations"> & { visibilityExpectations: VisibilityExpectations }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No purpose, removed

Comment on lines 46 to 47
private _implWithoutDefinitionContainers: HierarchyDefinition;
private _implWithDefinitionContainers: HierarchyDefinition;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need both of these? maybe one would be enough, with one of the childNodes specs being added conditionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, removed

const CATEGORIES_CTE = "AllVisibleCategories";
const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();
const ctes = [
`${CATEGORIES_CTE}(ECInstanceId, ChildCount, ModelId ${isDefinitionContainerSupported ? ", ParentDefinitionContainerExists" : ""}) AS (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the ParentDefinitionContainerExists property could always be there, but it's value would always be false if the class doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

mergeMap(async (node) => validateNodeVisibility({ ...props, node })),
),
);
expect(props.nodesToExpect.every((nodeId) => nodesFound.includes(nodeId))).to.be.true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this check, validateHierarchyVisibility could not check anything and it wouldn't fail

Yes, but that should be tested in our hierarchy tests, not visibility ones. This check unnecessarily complicates the tests, e.g.:

// this is only needed for checking what we got in the hierarchy
const expectedIds = [
  keys.definitionContainerRoot.id,
  keys.definitionContainerChild.id,
  keys.directCategory.id,
  keys.indirectCategory.id,
  keys.indirectSubCategory.id,
];
using visibilityTestData = await createVisibilityTestData({ imodel, isVisibleOnInitialize });
const { handler, provider, viewport } = visibilityTestData;
await handler.changeVisibility(createDefinitionContainerHierarchyNode(keys.definitionContainerRoot.id), true);
await validateHierarchyVisibility({
  provider,
  handler,
  viewport,
  visibilityExpectations: {},
  expectedIds,
  all: "visible",
});

Comment on lines 25 to 27
visibilityExpectations: VisibilityExpectations;
expectedIds: Id64Array;
all?: "visible" | "hidden";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about changing { visibilityExpectations: VisibilityExpectations; all?: "visible" | "hidden"; } to { expect: "all-visible" | "all-hidden" | VisibilityExpectations }?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better, changed to your suggestion, just instead of naming expect named to expectations since we are importing expect from chai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tree widget: Hierarchical categories tree
3 participants