Skip to content

Show NX badges in explorer where NX visualizations are actually supported#1990

Open
axelboc wants to merge 1 commit intomainfrom
nx-badge
Open

Show NX badges in explorer where NX visualizations are actually supported#1990
axelboc wants to merge 1 commit intomainfrom
nx-badge

Conversation

@axelboc
Copy link
Contributor

@axelboc axelboc commented Mar 18, 2026

We received feedback by email that the behaviour of the "NX" badge in the explorer is confusing.

The goal of the badge is to indicate entities that have a supported NeXus visualization. In the current implementation, we compromised accuracy in favour of limiting strongly the amount of metadata requested by simply checking for the presence of a default attribute or specific NX_class attribute (NXdata, NXentry or NXprocess).

In this PR, when deciding whether to show the NX badge, I propose to use the same resolution algorithm we use for finding supported visualizations. This includes looking for implicit "default" children, old-style NXdata (with a "signal" dataset), NXnote, etc.

Once I have the supported visualization, I check if any of the supported visualizations is a NeXus visualization before showing the badge, since the default attribute can very well point to a dataset instead of an NXdata group. I add a mock example and a test case for this.

Before After
image image
image image
image image

Because of the implicit default child algorithm, the new implementation effectively fetches the metadata of every root group on first render, and of every child group when selecting a group. If it encounters a default attribute on a group, it also fetches its value and recurses, and it if encounters NeXus attributes like signal or interpretation, it also fetches their values as per our NeXus visualizations resolution algorithm. Overall, this can lead to a number of extra requests depending on the file, which can stack up and block other requests and delaying expanding a group or showing a default visualization. The silver lining is that when the user selects a child group, the metadata for the group itself is already available, so the little spinner no longer appears.

Copy link
Contributor Author

@axelboc axelboc left a comment

Choose a reason for hiding this comment

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

Again I'll wait for #1987 and #1989 to be merged before updating the screenshots. Feel free to wait until then before reviewing.

import { page } from 'vitest/browser';

import { mockConsoleMethod, renderApp } from '../test-utils';
import { mockConsoleMethod, mockDelay, renderApp } from '../test-utils';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing some flaky tests due to slow requests when opening the resilience group.

const { selectExplorerNode } = await renderApp('/nexus_malformed');

// `default` attribute points to non-existant entity
await selectNexusExplorerNode('default_not_found');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These malformed entities no longer have the "NX" badge.

Comment on lines +397 to +400
test('visualize NXnote group', async () => {
await renderApp('/nexus_note');
expect(page.getByText('"energy": 10.2')).toBeVisible();
});
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 weren't testing the NX Note visualization

Comment on lines +7 to +11
test('visualize default dataset', async () => {
const { selectExplorerNode } = await renderApp('/entities');
await selectExplorerNode('default_dataset');
expect(page.getByText('foo')).toBeVisible();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test case for a group with a default attribute that points to a simple dataset. We were already supporting but not testing this use case. The person who sent us the feedback about the NX badge provided a file with such a use case.

<span className={styles.name}>{entity.name}</span>

<ErrorBoundary fallback={null}>
{isGroup(entity) && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking for groups here saves us from fetching other entities metadata, like datasets.

<Icon className={styles.icon} />
<span className={styles.name}>{entity.name}</span>

<ErrorBoundary fallback={null}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NxBadge now silences errors to avoid cluttering the browser console and tests when resolving malformed entities.

@axelboc axelboc requested a review from loichuder March 18, 2026 14:31
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.

1 participant