forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 add legacy short URL locator
- Loading branch information
1 parent
395f6d8
commit bef580f
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/plugins/share/server/url_service/short_urls/relative_path_locator.ts
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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { SerializableState } from 'src/plugins/kibana_utils/common'; | ||
import type { KibanaLocation, LocatorDefinition } from '../../../common/url_service'; | ||
|
||
export interface RelativePathLocatorParams extends SerializableState { | ||
url: string; | ||
} | ||
|
||
export class RelativePathLocatorDefinition implements LocatorDefinition<RelativePathLocatorParams> { | ||
public readonly id = 'RELATIVE_PATH_LOCATOR'; | ||
|
||
public async getLocation(params: RelativePathLocatorParams): Promise<KibanaLocation> { | ||
const { url } = params; | ||
|
||
const match = url.match(/^.*\/app\/([^\/#]+)(.+)$/); | ||
|
||
if (!match) { | ||
throw new Error('Unexpected URL path.'); | ||
} | ||
|
||
const [, app, path] = match; | ||
|
||
if (!app || !path) { | ||
throw new Error('Could not parse URL path.'); | ||
} | ||
|
||
return { | ||
app, | ||
path, | ||
state: {}, | ||
}; | ||
} | ||
} |