-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Convert our
public_url
route to config_data
a…
…nd collect initialAppData (#75616) * [Setup] DRY out stripTrailingSlash helper - DRYs out repeated code - This will be used by an upcoming server/ endpoint change, hence why it's in common * [Setup] DRY out initial app data types to common/types - In preparation for upcoming server logic that will need to reuse these types + DRY out and clean up workplace_search types - remove unused supportEligible - remove currentUser - unneeded in Kibana * Update callEnterpriseSearchConfigAPI to parse and fetch new expected data * Remove /public_url API for /config_data * Remove getPublicUrl in favor of directly calling the new /config_data API from public/plugin + set returned initialData in this.data * Set up product apps to be passed initial data as props * Fix for Kea/redux state not resetting between AS<->WS nav - resetContext at the top level only gets called once total on first plugin load and never after, causing navigating between WS and AS to crash when both have Kea - this fixes the issue - moves redux Provider to top level app as well * Add very basic Kea logic file to App Search * Finish AppSearchConfigured tests & set up kea+useEffect mocks * [Cleanup] DRY out repeated mock initialAppData to a reusable defaults constant
- Loading branch information
Showing
31 changed files
with
573 additions
and
211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './initial_app_data'; |
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/enterprise_search/common/__mocks__/initial_app_data.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,45 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const DEFAULT_INITIAL_APP_DATA = { | ||
readOnlyMode: false, | ||
ilmEnabled: true, | ||
configuredLimits: { | ||
maxDocumentByteSize: 102400, | ||
maxEnginesPerMetaEngine: 15, | ||
}, | ||
appSearch: { | ||
accountId: 'some-id-string', | ||
onBoardingComplete: true, | ||
role: { | ||
id: 'account_id:somestring|user_oid:somestring', | ||
roleType: 'owner', | ||
ability: { | ||
accessAllEngines: true, | ||
destroy: ['session'], | ||
manage: ['account_credentials', 'account_engines'], // etc | ||
edit: ['LocoMoco::Account'], // etc | ||
view: ['Engine'], // etc | ||
credentialTypes: ['admin', 'private', 'search'], | ||
availableRoleTypes: ['owner', 'admin'], | ||
}, | ||
}, | ||
}, | ||
workplaceSearch: { | ||
organization: { | ||
name: 'ACME Donuts', | ||
defaultOrgName: 'My Organization', | ||
}, | ||
fpAccount: { | ||
id: 'some-id-string', | ||
groups: ['Default', 'Cats'], | ||
isAdmin: true, | ||
canCreatePersonalSources: true, | ||
isCurated: false, | ||
viewedOnboardingPage: true, | ||
}, | ||
}, | ||
}; |
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/enterprise_search/common/strip_trailing_slash/index.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,17 @@ | ||
/* | ||
* 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 { stripTrailingSlash } from './'; | ||
|
||
describe('Strip Trailing Slash helper', () => { | ||
it('strips trailing slashes', async () => { | ||
expect(stripTrailingSlash('http://trailing.slash/')).toEqual('http://trailing.slash'); | ||
}); | ||
|
||
it('does nothing is there is no trailing slash', async () => { | ||
expect(stripTrailingSlash('http://ok.url')).toEqual('http://ok.url'); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/enterprise_search/common/strip_trailing_slash/index.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,13 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Small helper for stripping trailing slashes from URLs or paths | ||
* (usually ones that come in from React Router or API endpoints) | ||
*/ | ||
export const stripTrailingSlash = (url: string): string => { | ||
return url && url.endsWith('/') ? url.slice(0, -1) : url; | ||
}; |
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/enterprise_search/common/types/app_search.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,25 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export interface IAccount { | ||
accountId: string; | ||
onBoardingComplete: boolean; | ||
role: IRole; | ||
} | ||
|
||
export interface IRole { | ||
id: string; | ||
roleType: string; | ||
ability: { | ||
accessAllEngines: boolean; | ||
destroy: string[]; | ||
manage: string[]; | ||
edit: string[]; | ||
view: string[]; | ||
credentialTypes: string[]; | ||
availableRoleTypes: string[]; | ||
}; | ||
} |
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,24 @@ | ||
/* | ||
* 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 { IAccount as IAppSearchAccount } from './app_search'; | ||
import { IAccount as IWorkplaceSearchAccount, IOrganization } from './workplace_search'; | ||
|
||
export interface IInitialAppData { | ||
readOnlyMode?: boolean; | ||
ilmEnabled?: boolean; | ||
configuredLimits?: IConfiguredLimits; | ||
appSearch?: IAppSearchAccount; | ||
workplaceSearch?: { | ||
organization: IOrganization; | ||
fpAccount: IWorkplaceSearchAccount; | ||
}; | ||
} | ||
|
||
export interface IConfiguredLimits { | ||
maxDocumentByteSize: number; | ||
maxEnginesPerMetaEngine: number; | ||
} |
19 changes: 19 additions & 0 deletions
19
x-pack/plugins/enterprise_search/common/types/workplace_search.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,19 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export interface IAccount { | ||
id: string; | ||
groups: string[]; | ||
isAdmin: boolean; | ||
isCurated: boolean; | ||
canCreatePersonalSources: boolean; | ||
viewedOnboardingPage: boolean; | ||
} | ||
|
||
export interface IOrganization { | ||
name: string; | ||
defaultOrgName: string; | ||
} |
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/enterprise_search/public/applications/__mocks__/kea.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,24 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
jest.mock('kea', () => ({ | ||
...(jest.requireActual('kea') as object), | ||
useValues: jest.fn(() => ({})), | ||
useActions: jest.fn(() => ({})), | ||
})); | ||
|
||
/** | ||
* Example usage within a component test: | ||
* | ||
* import '../../../__mocks__/kea'; // Must come before kea's import, adjust relative path as needed | ||
* | ||
* import { useActions, useValues } from 'kea'; | ||
* | ||
* it('some test', () => { | ||
* (useValues as jest.Mock).mockImplementationOnce(() => ({ someValue: 'hello' })); | ||
* (useActions as jest.Mock).mockImplementationOnce(() => ({ someAction: () => 'world' })); | ||
* }); | ||
*/ |
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
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/enterprise_search/public/applications/app_search/app_logic.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,35 @@ | ||
/* | ||
* 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 { resetContext } from 'kea'; | ||
|
||
import { DEFAULT_INITIAL_APP_DATA } from '../../../common/__mocks__'; | ||
import { AppLogic } from './app_logic'; | ||
|
||
describe('AppLogic', () => { | ||
beforeEach(() => { | ||
resetContext({}); | ||
AppLogic.mount(); | ||
}); | ||
|
||
const DEFAULT_VALUES = { | ||
hasInitialized: false, | ||
}; | ||
|
||
it('has expected default values', () => { | ||
expect(AppLogic.values).toEqual(DEFAULT_VALUES); | ||
}); | ||
|
||
describe('initializeAppData()', () => { | ||
it('sets values based on passed props', () => { | ||
AppLogic.actions.initializeAppData(DEFAULT_INITIAL_APP_DATA); | ||
|
||
expect(AppLogic.values).toEqual({ | ||
hasInitialized: true, | ||
}); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/enterprise_search/public/applications/app_search/app_logic.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,31 @@ | ||
/* | ||
* 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 { kea } from 'kea'; | ||
|
||
import { IInitialAppData } from '../../../common/types'; | ||
import { IKeaLogic } from '../shared/types'; | ||
|
||
export interface IAppLogicValues { | ||
hasInitialized: boolean; | ||
} | ||
export interface IAppLogicActions { | ||
initializeAppData(props: IInitialAppData): void; | ||
} | ||
|
||
export const AppLogic = kea({ | ||
actions: (): IAppLogicActions => ({ | ||
initializeAppData: (props) => props, | ||
}), | ||
reducers: () => ({ | ||
hasInitialized: [ | ||
false, | ||
{ | ||
initializeAppData: () => true, | ||
}, | ||
], | ||
}), | ||
}) as IKeaLogic<IAppLogicValues, IAppLogicActions>; |
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.