-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
542 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { BasePathSetup } from '../../base_path'; | ||
|
||
export interface ChromeNavLinkProperties { | ||
/** | ||
* A unique identifier for looking up links. | ||
*/ | ||
id: string; | ||
|
||
/** | ||
* Indicates whether or not this app is currently on the screen. | ||
* | ||
* NOTE: remove this when ApplicationService is implemented and managing apps. | ||
*/ | ||
active: boolean; | ||
|
||
/** | ||
* Disables a link from being clickable. | ||
* | ||
* NOTE: this is only used by the ML and Graph plugins currently. They use this field | ||
* to disable the nav link when the license is expired. | ||
*/ | ||
disabled: boolean; | ||
|
||
/** | ||
* Hides a link from the navigation. | ||
* | ||
* NOTE: remove this when ApplicationService is implemented. Instead, plugins should only | ||
* register an Application if needed. | ||
*/ | ||
hidden: boolean; | ||
|
||
/** | ||
* An ordinal used to sort nav links relative to one another for display. | ||
*/ | ||
order: number; | ||
|
||
/** | ||
* The title of the application. | ||
*/ | ||
title: string; | ||
|
||
/** | ||
* A tooltip shown when hovering over an app link. | ||
*/ | ||
tooltip: string; | ||
|
||
/** | ||
* The base URL used to open the root of an application. | ||
*/ | ||
appUrl: string; | ||
|
||
/** | ||
* A url that legacy apps can set to deep link into their applications. | ||
* | ||
* NOTE: Currently used by the "lastSubUrl" feature legacy/ui/chrome. This should | ||
* be removed once the ApplicationService is implemented and mounting apps. At that | ||
* time, each app can handle opening to the previous location when they are mounted. | ||
*/ | ||
url?: string; | ||
|
||
/** | ||
* A EUI iconType that will be used for the app's icon. This icon | ||
* takes precendence over the `icon` property. | ||
*/ | ||
euiIconType?: string; | ||
|
||
/** | ||
* A URL to an image file used as an icon. Used as a fallback | ||
* if `euiIconType` is not provided. | ||
*/ | ||
icon?: string; | ||
} | ||
|
||
export type NavLinkUpdateableFields = Partial< | ||
Pick<ChromeNavLinkProperties, 'active' | 'disabled' | 'hidden' | 'url'> | ||
>; | ||
|
||
export class NavLink { | ||
public readonly id: string; | ||
public readonly properties: Readonly<ChromeNavLinkProperties>; | ||
|
||
constructor(properties: ChromeNavLinkProperties, private readonly basePath: BasePathSetup) { | ||
if (!properties || !properties.id) { | ||
throw new Error('`id` is required.'); | ||
} | ||
|
||
this.id = properties.id; | ||
this.properties = Object.freeze(properties); | ||
} | ||
|
||
public update(newProps: NavLinkUpdateableFields) { | ||
return new NavLink({ ...this.properties, ...newProps }, this.basePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { sortBy } from 'lodash'; | ||
import { BehaviorSubject, ReplaySubject } from 'rxjs'; | ||
import { map, takeUntil } from 'rxjs/operators'; | ||
import { BasePathSetup } from '../../base_path'; | ||
import { ChromeNavLinkProperties, NavLink, NavLinkUpdateableFields } from './nav_link'; | ||
|
||
export class NavLinksService { | ||
private readonly stop$ = new ReplaySubject(1); | ||
|
||
public setup(basePath: BasePathSetup) { | ||
const navLinks$ = new BehaviorSubject<ReadonlyArray<NavLink>>([]); | ||
|
||
return { | ||
getNavLinks$: () => { | ||
return navLinks$.pipe( | ||
map(sortNavLinks), | ||
takeUntil(this.stop$) | ||
); | ||
}, | ||
|
||
add(navLink: ChromeNavLinkProperties) { | ||
navLinks$.next([...navLinks$.value, new NavLink(navLink, basePath)]); | ||
}, | ||
|
||
clear() { | ||
navLinks$.next([]); | ||
}, | ||
|
||
get(id: string) { | ||
const link = navLinks$.value.find(l => l.id === id); | ||
return link ? link.properties : undefined; | ||
}, | ||
|
||
getAll() { | ||
return sortNavLinks(navLinks$.value); | ||
}, | ||
|
||
exists(id: string) { | ||
return this.get(id) !== undefined; | ||
}, | ||
|
||
showOnly(id: string) { | ||
navLinks$.next(navLinks$.value.filter(link => link.id === id)); | ||
}, | ||
|
||
update(id: string, values: NavLinkUpdateableFields) { | ||
if (!this.exists(id)) { | ||
return; | ||
} | ||
|
||
navLinks$.next( | ||
navLinks$.value.map(link => { | ||
return link.id === id ? link.update(values) : link; | ||
}) | ||
); | ||
|
||
return this.get(id); | ||
}, | ||
}; | ||
} | ||
|
||
public stop() { | ||
this.stop$.next(); | ||
} | ||
} | ||
|
||
function sortNavLinks(navLinks: ReadonlyArray<NavLink>) { | ||
return sortBy(navLinks.map(link => link.properties), 'order'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.