Files
Andrej Ocenas 5e2ac24890 Sidecar: Add split view and basic APIs for extensions (#91648)
* Add split view and basic APIs to extensions

* Add comments

* Update public/app/AppWrapper.tsx

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>

* Moved the .grafana-app element and deduplicate some code

* Remove the provider variants of usePluginLinks/Components

* Change buildPluginSectionNav

* Update comment

* Use eventBus

* Remove non existent exports

* refactor: use a sidecar service to encapsulate the state

* Don't wrap single app in split wrapper

* Use hook splitter

* Remove inline styles

* Type the style props from useSplitter

* Move the overflow style changes to appWrapper

* Deduplicate some common top level providers

* Move modals

* Move routes wrappers to it's own file

* Use better css and add comments

* Remove query rows app extension point

* Fix test

---------

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
2024-09-09 14:45:05 +02:00

96 lines
2.6 KiB
TypeScript

import { NavModelItem } from '@grafana/data';
import { HOME_NAV_ID } from 'app/core/reducers/navModel';
import { buildPluginSectionNav } from './utils';
describe('buildPluginSectionNav', () => {
const app1: NavModelItem = {
text: 'App1',
id: 'plugin-page-app1',
url: '/a/plugin1',
children: [
{
text: 'page1',
url: '/a/plugin1/page1',
},
{
text: 'page2',
url: '/a/plugin1/page2',
},
{
text: 'page3',
url: '/a/plugin1/page3',
children: [
{
text: 'page4',
url: '/a/plugin1/page3/page4',
},
],
},
],
};
const appsSection = {
text: 'apps',
id: 'apps',
children: [app1],
};
const home = {
id: HOME_NAV_ID,
text: 'Home',
};
const adminSection: NavModelItem = {
text: 'Admin',
id: 'admin',
children: [],
parentItem: home,
};
const standalonePluginPage = {
id: 'standalone-plugin-page-/a/app2/config',
text: 'Standalone page',
parentItem: adminSection,
};
adminSection.children = [standalonePluginPage];
app1.parentItem = appsSection;
it('Should return return section nav', () => {
const result = buildPluginSectionNav('/a/plugin1/page1', appsSection);
expect(result?.main.text).toBe('apps');
});
it('Should set active page', () => {
const result = buildPluginSectionNav('/a/plugin1/page2', appsSection);
expect(result?.main.children![0].children![1].active).toBe(true);
expect(result?.node.text).toBe('page2');
});
it('Should only set the most specific match as active (not the parents)', () => {
const result = buildPluginSectionNav('/a/plugin1/page2', appsSection);
expect(result?.main.children![0].children![1].active).toBe(true);
expect(result?.main.children![0].active).not.toBe(true); // Parent should not be active
});
it('Should set app section to active', () => {
const result = buildPluginSectionNav('/a/plugin1', appsSection);
expect(result?.main.children![0].active).toBe(true);
expect(result?.node.text).toBe('App1');
});
it('Should handle standalone page', () => {
const result = buildPluginSectionNav('/a/app2/config', adminSection);
expect(result?.main.text).toBe('Admin');
expect(result?.node.text).toBe('Standalone page');
});
it('Should set nested active page', () => {
const result = buildPluginSectionNav('/a/plugin1/page3/page4', appsSection);
expect(result?.main.children![0].children![2].children![0].active).toBe(true);
expect(result?.node.text).toBe('page4');
});
});