Skip to content

Commit

Permalink
Expose options to customize the route matching
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed May 28, 2021
1 parent a4f6d43 commit ef44d0b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,42 @@ To register a solution's navigation structure you'll first need to ensure your s
],
```

Now within your solution's **public** plugin `setup` lifecycle method you can call the `registerSections` method, this will register your solution's specific navigation structure with the overall Observability navigation registry. E.g.
Now within your solution's **public** plugin `setup` lifecycle method you can
call the `registerSections` method, this will register your solution's specific
navigation structure with the overall Observability navigation registry.

The `registerSections` function takes an `Observable` of an array of
`NavigationSection`s. Each section can be defined as

```typescript
export interface NavigationSection {
// the label of the section, should be translated
label: string | undefined;
// the key to sort by in ascending order relative to other entries
sortKey: number;
// the entries to render inside the section
entries: NavigationEntry[];
}
```

Each entry inside of a navigation section is defined as

```typescript
export interface NavigationEntry {
// the label of the menu entry, should be translated
label: string;
// the kibana app id
app: string;
// the path after the application prefix corresponding to this entry
path: string;
// whether to only match when the full path matches, defaults to `false`
matchFullPath?: boolean;
// whether to ignore trailing slashes, defaults to `true`
ignoreTrailingSlash?: boolean;
}
```

A registration might therefore look like the following:

```typescript
// x-pack/plugins/example_plugin/public/plugin.ts
Expand All @@ -27,6 +62,7 @@ export class Plugin implements PluginClass {
label: 'A solution section',
sortKey: 200,
entries: [
{ label: 'Home Page', app: 'exampleA', path: '/', matchFullPath: true },
{ label: 'Example Page', app: 'exampleA', path: '/example' },
{ label: 'Another Example Page', app: 'exampleA', path: '/another-example' },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export function ObservabilityPageTemplate({
entry.app === currentAppId &&
matchPath(currentPath, {
path: entry.path,
exact: !!entry.matchFullPath,
strict: !entry.ignoreTrailingSlash,
}) != null;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ export interface NavigationSection {
}

export interface NavigationEntry {
// the label of the menu entry, should be internationalized
label: string;
// the kibana app id
app: string;
// the path after the application prefix corresponding to this entry
path: string;
// whether to only match when the full path matches, defaults to `false`
matchFullPath?: boolean;
// whether to ignore trailing slashes, defaults to `true`
ignoreTrailingSlash?: boolean;
}

export interface NavigationRegistry {
Expand Down

0 comments on commit ef44d0b

Please sign in to comment.