@grafana/data#NavModel TypeScript Examples
The following examples show how to use
@grafana/data#NavModel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FolderSettingsPage.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {} as NavModel,
folderUid: '1234',
folder: {
id: 0,
uid: '1234',
title: 'loading',
canSave: true,
url: 'url',
hasChanged: false,
version: 1,
permissions: [],
},
getFolderByUid: jest.fn(),
setFolderTitle: mockToolkitActionCreator(setFolderTitle),
saveFolder: jest.fn(),
deleteFolder: jest.fn(),
};
Object.assign(props, propOverrides);
const wrapper = shallow(<FolderSettingsPage {...props} />);
const instance = wrapper.instance() as FolderSettingsPage;
return {
wrapper,
instance,
};
}
Example #2
Source File: common.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function createNavModel(title: string, ...tabs: string[]): NavModel {
const node: NavModelItem = {
id: title,
text: title,
icon: 'fa fa-fw fa-warning',
subTitle: 'subTitle',
url: title,
children: [],
breadcrumbs: [],
};
const children = [];
for (const tab of tabs) {
children.push({
id: tab,
icon: 'icon',
subTitle: 'subTitle',
url: title,
text: title,
active: false,
});
}
children[0].active = true;
node.children = children;
return {
node: node,
main: node,
};
}
Example #3
Source File: UsersListPage.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {
main: {
text: 'Configuration',
},
node: {
text: 'Users',
},
} as NavModel,
users: [] as OrgUser[],
invitees: [] as Invitee[],
searchQuery: '',
externalUserMngInfo: '',
loadInvitees: jest.fn(),
loadUsers: jest.fn(),
updateUser: jest.fn(),
removeUser: jest.fn(),
setUsersSearchQuery: mockToolkitActionCreator(setUsersSearchQuery),
hasFetched: false,
};
Object.assign(props, propOverrides);
const wrapper = shallow(<UsersListPage {...props} />);
const instance = wrapper.instance() as UsersListPage;
return {
wrapper,
instance,
};
}
Example #4
Source File: navModel.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function getTeamLoadingNav(pageName: string): NavModel {
const main = buildNavModel({
avatarUrl: 'public/img/user_profile.png',
id: 1,
name: 'Loading',
email: 'loading',
memberCount: 0,
permission: TeamPermissionLevel.Member,
});
let node: NavModelItem;
// find active page
for (const child of main.children) {
if (child.id.indexOf(pageName) > 0) {
child.active = true;
node = child;
break;
}
}
return {
main: main,
node: node,
};
}
Example #5
Source File: TeamPages.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
hideTabsFromNonTeamAdmin = (navModel: NavModel, isSignedInUserTeamAdmin: boolean) => {
if (!isSignedInUserTeamAdmin && navModel.main && navModel.main.children) {
navModel.main.children
.filter(navItem => !this.textsAreEqual(navItem.text, PageTypes.Members))
.map(navItem => {
navItem.hideFromTabs = true;
});
}
return navModel;
};
Example #6
Source File: TeamPages.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {} as NavModel,
teamId: 1,
loadTeam: jest.fn(),
loadTeamMembers: jest.fn(),
pageName: 'members',
team: {} as Team,
members: [] as TeamMember[],
editorsCanAdmin: false,
signedInUser: {
id: 1,
isGrafanaAdmin: false,
orgRole: OrgRole.Viewer,
} as User,
};
Object.assign(props, propOverrides);
const wrapper = shallow(<TeamPages {...props} />);
const instance = wrapper.instance();
return {
wrapper,
instance,
};
}
Example #7
Source File: TeamList.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {
main: {
text: 'Configuration',
},
node: {
text: 'Team List',
},
} as NavModel,
teams: [] as Team[],
loadTeams: jest.fn(),
deleteTeam: jest.fn(),
setSearchQuery: mockToolkitActionCreator(setSearchQuery),
searchQuery: '',
teamsCount: 0,
hasFetched: false,
editorsCanAdmin: false,
signedInUser: {
id: 1,
orgRole: OrgRole.Viewer,
} as User,
};
Object.assign(props, propOverrides);
const wrapper = shallow(<TeamList {...props} />);
const instance = wrapper.instance() as TeamList;
return {
wrapper,
instance,
};
}
Example #8
Source File: PluginPage.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
export function getLoadingNav(): NavModel {
const node = {
text: 'Loading...',
icon: 'icon-gf icon-gf-panel',
};
return {
node: node,
main: node,
};
}
Example #9
Source File: PluginListPage.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {
main: {
text: 'Configuration',
},
node: {
text: 'Plugins',
},
} as NavModel,
plugins: [] as PluginMeta[],
searchQuery: '',
setPluginsSearchQuery: mockToolkitActionCreator(setPluginsSearchQuery),
setPluginsLayoutMode: mockToolkitActionCreator(setPluginsLayoutMode),
layoutMode: LayoutModes.Grid,
loadPlugins: jest.fn(),
hasFetched: false,
};
Object.assign(props, propOverrides);
return shallow(<PluginListPage {...props} />);
}
Example #10
Source File: OrgDetailsPage.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
organization: {} as Organization,
navModel: {
main: {
text: 'Configuration',
},
node: {
text: 'Org details',
},
} as NavModel,
loadOrganization: jest.fn(),
setOrganizationName: mockToolkitActionCreator(setOrganizationName),
updateOrganization: jest.fn(),
};
Object.assign(props, propOverrides);
return shallow(<OrgDetailsPage {...props} />);
}
Example #11
Source File: navModel.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function getLoadingNav(tabIndex: number): NavModel {
const main = buildNavModel({
id: 1,
uid: 'loading',
title: 'Loading',
url: 'url',
canSave: false,
version: 0,
});
main.children[tabIndex].active = true;
return {
main: main,
node: main.children[tabIndex],
};
}
Example #12
Source File: nav_model_srv.ts From grafana-chinese with Apache License 2.0 | 6 votes |
getNav(...args: Array<string | number>) {
let children = this.navItems;
const nav = {
breadcrumbs: [],
} as NavModel;
for (const id of args) {
// if its a number then it's the index to use for main
if (_.isNumber(id)) {
nav.main = nav.breadcrumbs[id];
break;
}
const node: any = _.find(children, { id: id });
nav.breadcrumbs.push(node);
nav.node = node;
nav.main = node;
children = node.children;
}
if (nav.main.children) {
for (const item of nav.main.children) {
item.active = false;
if (item.url === nav.node.url) {
item.active = true;
}
}
}
return nav;
}
Example #13
Source File: DataSourceSettingsPage.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {} as NavModel,
dataSource: getMockDataSource(),
dataSourceMeta: getMockPlugin(),
pageId: 1,
deleteDataSource: jest.fn(),
loadDataSource: jest.fn(),
setDataSourceName,
updateDataSource: jest.fn(),
initDataSourceSettings: jest.fn(),
testDataSource: jest.fn(),
setIsDefault,
dataSourceLoaded,
query: {},
...propOverrides,
};
return shallow(<DataSourceSettingsPage {...props} />);
}
Example #14
Source File: NewDataSourcePage.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
export function getNavModel(): NavModel {
const main = {
icon: 'gicon gicon-add-datasources',
id: 'datasource-new',
text: '添加数据源',
href: 'datasources/new',
subTitle: '选择数据源类型',
};
return {
main: main,
node: main,
};
}
Example #15
Source File: DataSourcesListPage.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
dataSources: [] as DataSourceSettings[],
layoutMode: LayoutModes.Grid,
loadDataSources: jest.fn(),
navModel: {
main: {
text: 'Configuration',
},
node: {
text: 'Data Sources',
},
} as NavModel,
dataSourcesCount: 0,
searchQuery: '',
setDataSourcesSearchQuery,
setDataSourcesLayoutMode,
hasFetched: false,
};
Object.assign(props, propOverrides);
return shallow(<DataSourcesListPage {...props} />);
}
Example #16
Source File: DataSourceDashboards.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {} as NavModel,
dashboards: [] as PluginDashboard[],
dataSource: {} as DataSourceSettings,
pageId: 1,
importDashboard: jest.fn(),
loadDataSource: jest.fn(),
loadPluginDashboards: jest.fn(),
removeDashboard: jest.fn(),
isLoading: false,
};
Object.assign(props, propOverrides);
return shallow(<DataSourceDashboards {...props} />);
}
Example #17
Source File: ApiKeysPage.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {
main: {
text: 'Configuration',
},
node: {
text: 'Api Keys',
},
} as NavModel,
apiKeys: [] as ApiKey[],
searchQuery: '',
hasFetched: false,
loadApiKeys: jest.fn(),
deleteApiKey: jest.fn(),
setSearchQuery: mockToolkitActionCreator(setSearchQuery),
addApiKey: jest.fn(),
apiKeysCount: 0,
includeExpired: false,
};
Object.assign(props, propOverrides);
const wrapper = shallow(<ApiKeysPage {...props} />);
const instance = wrapper.instance() as ApiKeysPage;
return {
wrapper,
instance,
};
}
Example #18
Source File: AlertRuleList.test.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
setup = (propOverrides?: object) => {
const props: Props = {
navModel: {} as NavModel,
alertRules: [] as AlertRule[],
updateLocation: mockToolkitActionCreator(updateLocation),
getAlertRulesAsync: jest.fn(),
setSearchQuery: mockToolkitActionCreator(setSearchQuery),
togglePauseAlertRule: jest.fn(),
stateFilter: '',
search: '',
isLoading: false,
};
Object.assign(props, propOverrides);
const wrapper = shallow(<AlertRuleList {...props} />);
return {
wrapper,
instance: wrapper.instance() as AlertRuleList,
};
}
Example #19
Source File: navModel.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function getNavModel(navIndex: NavIndex, id: string, fallback?: NavModel): NavModel {
if (navIndex[id]) {
const node = navIndex[id];
const main = {
...node.parentItem,
};
main.children = main.children.map(item => {
return {
...item,
active: item.url === node.url,
};
});
return {
node: node,
main: main,
};
}
if (fallback) {
return fallback;
}
return getNotFoundModel();
}
Example #20
Source File: navModel.ts From grafana-chinese with Apache License 2.0 | 6 votes |
function getNotFoundModel(): NavModel {
const node: NavModelItem = {
id: 'not-found',
text: 'Page not found',
icon: 'fa fa-fw fa-warning',
subTitle: '404 Error',
url: 'not-found',
};
return {
node: node,
main: node,
};
}
Example #21
Source File: nav_model_srv.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function getWarningNav(text: string, subTitle?: string): NavModel {
const node = {
text,
subTitle,
icon: 'fa fa-fw fa-warning',
};
return {
breadcrumbs: [node],
node: node,
main: node,
};
}
Example #22
Source File: navModel.ts From grafana-chinese with Apache License 2.0 | 5 votes |
export function getDataSourceLoadingNav(pageName: string): NavModel {
const main = buildNavModel(
{
access: '',
basicAuth: false,
basicAuthUser: '',
basicAuthPassword: '',
withCredentials: false,
database: '',
id: 1,
isDefault: false,
jsonData: { authType: 'credentials', defaultRegion: 'eu-west-2' },
name: 'Loading',
orgId: 1,
password: '',
readOnly: false,
type: 'Loading',
typeLogoUrl: 'public/img/icn-datasource.svg',
url: '',
user: '',
},
{
meta: {
id: '1',
type: PluginType.datasource,
name: '',
info: {
author: {
name: '',
url: '',
},
description: '',
links: [{ name: '', url: '' }],
logos: {
large: '',
small: '',
},
screenshots: [],
updated: '',
version: '',
},
includes: [],
module: '',
baseUrl: '',
},
} as GenericDataSourcePlugin
);
let node: NavModelItem;
// find active page
for (const child of main.children) {
if (child.id.indexOf(pageName) > 0) {
child.active = true;
node = child;
break;
}
}
return {
main: main,
node: node,
};
}
Example #23
Source File: AppRootPage.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
onNavChanged = (nav: NavModel) => {
this.setState({ nav });
};
Example #24
Source File: navModel.ts From grafana-chinese with Apache License 2.0 | 5 votes |
getTitleFromNavModel = (navModel: NavModel) => {
return `${navModel.main.text}${navModel.node.text ? ': ' + navModel.node.text : ''}`;
}
Example #25
Source File: nav_model_srv.ts From grafana-chinese with Apache License 2.0 | 5 votes |
export function getNotFoundNav(): NavModel {
return getWarningNav('Page not found', '404 Error');
}
Example #26
Source File: PluginPage.tsx From grafana-chinese with Apache License 2.0 | 4 votes |
function getPluginTabsNav(
plugin: GrafanaPlugin,
appSubUrl: string,
path: string,
query: UrlQueryMap,
isAdmin: boolean
): { defaultPage: string; nav: NavModel } {
const { meta } = plugin;
let defaultPage: string;
const pages: NavModelItem[] = [];
if (true) {
pages.push({
text: 'Readme',
icon: 'fa fa-fw fa-file-text-o',
url: `${appSubUrl}${path}?page=${PAGE_ID_README}`,
id: PAGE_ID_README,
});
}
// We allow non admins to see plugins but only their readme. Config is hidden even though the API needs to be
// public for plugins to work properly.
if (isAdmin) {
// Only show Config/Pages for app
if (meta.type === PluginType.app) {
// Legacy App Config
if (plugin.angularConfigCtrl) {
pages.push({
text: 'Config',
icon: 'gicon gicon-cog',
url: `${appSubUrl}${path}?page=${PAGE_ID_CONFIG_CTRL}`,
id: PAGE_ID_CONFIG_CTRL,
});
defaultPage = PAGE_ID_CONFIG_CTRL;
}
if (plugin.configPages) {
for (const page of plugin.configPages) {
pages.push({
text: page.title,
icon: page.icon,
url: `${appSubUrl}${path}?page=${page.id}`,
id: page.id,
});
if (!defaultPage) {
defaultPage = page.id;
}
}
}
// Check for the dashboard pages
if (find(meta.includes, { type: PluginIncludeType.dashboard })) {
pages.push({
text: 'Dashboards',
icon: 'gicon gicon-dashboard',
url: `${appSubUrl}${path}?page=${PAGE_ID_DASHBOARDS}`,
id: PAGE_ID_DASHBOARDS,
});
}
}
}
if (!defaultPage) {
defaultPage = pages[0].id; // the first tab
}
const node = {
text: meta.name,
img: meta.info.logos.large,
subTitle: meta.info.author.name,
breadcrumbs: [{ title: 'Plugins', url: 'plugins' }],
url: `${appSubUrl}${path}`,
children: setActivePage(query.page as string, pages, defaultPage),
};
return {
defaultPage,
nav: {
node: node,
main: node,
},
};
}