mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scopes: Open the selector to a selected scope (#89686)
This commit is contained in:
parent
529d4e1169
commit
9770ebcd6c
@ -166,7 +166,19 @@ export class ScopesFiltersScene extends SceneObjectBase<ScopesFiltersSceneState>
|
|||||||
|
|
||||||
public open() {
|
public open() {
|
||||||
if (!this.scopesParent.state.isViewing) {
|
if (!this.scopesParent.state.isViewing) {
|
||||||
this.setState({ isOpened: true });
|
let nodes = { ...this.state.nodes };
|
||||||
|
|
||||||
|
// First close all nodes
|
||||||
|
nodes = this.closeNodes(nodes);
|
||||||
|
|
||||||
|
// Extract the path of a scope
|
||||||
|
let path = [...(this.state.scopes[0]?.path ?? ['', ''])];
|
||||||
|
path.splice(path.length - 1, 1);
|
||||||
|
|
||||||
|
// Expand the nodes to the selected scope
|
||||||
|
nodes = this.expandNodes(nodes, path);
|
||||||
|
|
||||||
|
this.setState({ isOpened: true, nodes });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +219,35 @@ export class ScopesFiltersScene extends SceneObjectBase<ScopesFiltersSceneState>
|
|||||||
this.setState({ isOpened: false });
|
this.setState({ isOpened: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private closeNodes(nodes: NodesMap): NodesMap {
|
||||||
|
return Object.entries(nodes).reduce<NodesMap>((acc, [id, node]) => {
|
||||||
|
acc[id] = {
|
||||||
|
...node,
|
||||||
|
isExpanded: false,
|
||||||
|
nodes: this.closeNodes(node.nodes),
|
||||||
|
};
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private expandNodes(nodes: NodesMap, path: string[]): NodesMap {
|
||||||
|
nodes = { ...nodes };
|
||||||
|
let currentNodes = nodes;
|
||||||
|
|
||||||
|
for (let i = 0; i < path.length; i++) {
|
||||||
|
const nodeId = path[i];
|
||||||
|
|
||||||
|
currentNodes[nodeId] = {
|
||||||
|
...currentNodes[nodeId],
|
||||||
|
isExpanded: true,
|
||||||
|
};
|
||||||
|
currentNodes = currentNodes[nodeId].nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
private getTreeScopes(): TreeScope[] {
|
private getTreeScopes(): TreeScope[] {
|
||||||
return this.state.scopes.map(({ scope, path }) => ({
|
return this.state.scopes.map(({ scope, path }) => ({
|
||||||
scopeName: scope.metadata.name,
|
scopeName: scope.metadata.name,
|
||||||
|
@ -181,6 +181,17 @@ describe('ScopesScene', () => {
|
|||||||
expect(getApplicationsSlothVoteTrackerSelect()).toBeInTheDocument();
|
expect(getApplicationsSlothVoteTrackerSelect()).toBeInTheDocument();
|
||||||
expect(queryApplicationsClustersTitle()).not.toBeInTheDocument();
|
expect(queryApplicationsClustersTitle()).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Opens to a selected scope', async () => {
|
||||||
|
await userEvents.click(getFiltersInput());
|
||||||
|
await userEvents.click(getApplicationsExpand());
|
||||||
|
await userEvents.click(getApplicationsSlothPictureFactorySelect());
|
||||||
|
await userEvents.click(getApplicationsExpand());
|
||||||
|
await userEvents.click(getClustersExpand());
|
||||||
|
await userEvents.click(getFiltersApply());
|
||||||
|
await userEvents.click(getFiltersInput());
|
||||||
|
expect(queryApplicationsSlothPictureFactoryTitle()).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Filters', () => {
|
describe('Filters', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user