forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Move externalUrl helper out of React Context (ela…
…stic#78368) (elastic#78497) * Add new/simpler externalUrl helper and initialize it on renderApp - This uses a simple JS obj to store the enterpriseSearchUrl reference (once on plugin init) - This is vs. a class, which needs to be instantiated and passed around - the new obj can be imported flatly at any time - I also opted to not convert this into a Kea logic file - after some deliberation I decided against it because it felt really weird as one. It's not storing "state" per se that ever needs to be updated, it's simply a one-time set obj that contains helper functions. - There's also some hope that we might eventually not need this helper after the full migration, so the simpler it is to delete the better - Uses a getter & setter to ensure that we don't accidentally mutate said obj after initialization * Update all components using get*SearchUrl helpers * Update tests for updated components - Mostly just consists of mocking externalUrl and importing that mock * Remove old ExternalUrl class/context TODO in next commit: Address kibana_header_actions * Update Workplace Search Header Actions to use new externalUrl helper NOTE: this requires a temporary workaround of initializing externalUrl.enterpriseSearch in plugin.ts rather than in renderApp, because renderApp loads *after* the header app does. I plan on fixing this in a future PR so that setHeaderActionMenu is called AFTER renderApp has done loading (to ensure all the state in headerActions we need is available). Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
8dd6dcb
commit 2e3e63d
Showing
32 changed files
with
147 additions
and
169 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/enterprise_search/public/applications/__mocks__/enterprise_search_url.mock.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,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { externalUrl } from '../shared/enterprise_search_url'; | ||
|
||
externalUrl.enterpriseSearchUrl = 'http://localhost:3002'; |
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
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
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
42 changes: 42 additions & 0 deletions
42
...s/enterprise_search/public/applications/shared/enterprise_search_url/external_url.test.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,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { externalUrl, getEnterpriseSearchUrl, getAppSearchUrl, getWorkplaceSearchUrl } from './'; | ||
|
||
describe('Enterprise Search external URL helpers', () => { | ||
describe('getter/setter tests', () => { | ||
it('defaults to an empty string', () => { | ||
expect(externalUrl.enterpriseSearchUrl).toEqual(''); | ||
}); | ||
|
||
it('sets the internal enterpriseSearchUrl value', () => { | ||
externalUrl.enterpriseSearchUrl = 'http://localhost:3002'; | ||
expect(externalUrl.enterpriseSearchUrl).toEqual('http://localhost:3002'); | ||
}); | ||
|
||
it('does not allow mutating enterpriseSearchUrl once set', () => { | ||
externalUrl.enterpriseSearchUrl = 'hello world'; | ||
expect(externalUrl.enterpriseSearchUrl).toEqual('http://localhost:3002'); | ||
}); | ||
}); | ||
|
||
describe('function helpers', () => { | ||
it('generates a public Enterprise Search URL', () => { | ||
expect(getEnterpriseSearchUrl()).toEqual('http://localhost:3002'); | ||
expect(getEnterpriseSearchUrl('/login')).toEqual('http://localhost:3002/login'); | ||
}); | ||
|
||
it('generates a public App Search URL', () => { | ||
expect(getAppSearchUrl()).toEqual('http://localhost:3002/as'); | ||
expect(getAppSearchUrl('/path')).toEqual('http://localhost:3002/as/path'); | ||
}); | ||
|
||
it('generates a public Workplace Search URL', () => { | ||
expect(getWorkplaceSearchUrl()).toEqual('http://localhost:3002/ws'); | ||
expect(getWorkplaceSearchUrl('/path')).toEqual('http://localhost:3002/ws/path'); | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...lugins/enterprise_search/public/applications/shared/enterprise_search_url/external_url.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,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/** | ||
* NOTE: The externalUrl obj holds the reference to externalUrl, which should | ||
* only ever be updated once on plugin init. We're using a getter and setter | ||
* here to ensure it isn't accidentally mutated. | ||
* | ||
* Someday (8.x+), when our UI is entirely on Kibana and no longer on | ||
* Enterprise Search's standalone UI, we can potentially deprecate this helper. | ||
*/ | ||
export const externalUrl = { | ||
_enterpriseSearchUrl: '', | ||
get enterpriseSearchUrl() { | ||
return this._enterpriseSearchUrl; | ||
}, | ||
set enterpriseSearchUrl(value) { | ||
if (this._enterpriseSearchUrl) { | ||
// enterpriseSearchUrl is set once on plugin init - we should not mutate it | ||
return; | ||
} | ||
this._enterpriseSearchUrl = value; | ||
}, | ||
}; | ||
|
||
export const getEnterpriseSearchUrl = (path: string = ''): string => { | ||
return externalUrl.enterpriseSearchUrl + path; | ||
}; | ||
export const getAppSearchUrl = (path: string = ''): string => { | ||
return getEnterpriseSearchUrl('/as' + path); | ||
}; | ||
export const getWorkplaceSearchUrl = (path: string = ''): string => { | ||
return getEnterpriseSearchUrl('/ws' + path); | ||
}; |
25 changes: 0 additions & 25 deletions
25
...ise_search/public/applications/shared/enterprise_search_url/generate_external_url.test.ts
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
...terprise_search/public/applications/shared/enterprise_search_url/generate_external_url.ts
This file was deleted.
Oops, something went wrong.
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.