-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Enterprise Search] Adds app logic file to Workplace Search #76009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6a7d4aa
Add new Workplace Search initial data properties
scottybollinger 2b9928b
Add app logic
scottybollinger b5592c9
Refactor index to match App Search
scottybollinger 72738ec
Remove ‘Logic’ from interface names
scottybollinger a27b277
Extract initial data from WS into interface
scottybollinger 2b87252
Destructuring FTW
scottybollinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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/workplace_search/app_logic.test.ts
This file contains hidden or 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, | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/enterprise_search/public/applications/workplace_search/app_logic.ts
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * 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 { IWorkplaceSearchInitialData } from '../../../common/types/workplace_search'; | ||
| import { IKeaLogic } from '../shared/types'; | ||
|
|
||
| export interface IAppValues extends IWorkplaceSearchInitialData { | ||
| hasInitialized: boolean; | ||
| } | ||
| export interface IAppActions { | ||
| initializeAppData(props: IInitialAppData): void; | ||
| } | ||
|
|
||
| export const AppLogic = kea({ | ||
| actions: (): IAppActions => ({ | ||
| initializeAppData: ({ workplaceSearch }) => workplaceSearch, | ||
| }), | ||
| reducers: () => ({ | ||
| hasInitialized: [ | ||
| false, | ||
| { | ||
| initializeAppData: () => true, | ||
| }, | ||
| ], | ||
| }), | ||
| }) as IKeaLogic<IAppValues, IAppActions>; |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,13 +4,14 @@ | |
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React, { useContext } from 'react'; | ||
| import React, { useContext, useEffect } from 'react'; | ||
| import { Route, Redirect, Switch } from 'react-router-dom'; | ||
| import { useValues } from 'kea'; | ||
| import { useActions, useValues } from 'kea'; | ||
|
|
||
| import { IInitialAppData } from '../../../common/types'; | ||
| import { KibanaContext, IKibanaContext } from '../index'; | ||
| import { HttpLogic, IHttpLogicValues } from '../shared/http'; | ||
| import { AppLogic, IAppActions, IAppValues } from './app_logic'; | ||
| import { Layout } from '../shared/layout'; | ||
| import { WorkplaceSearchNav } from './components/layout/nav'; | ||
|
|
||
|
|
@@ -20,21 +21,19 @@ import { SetupGuide } from './views/setup_guide'; | |
| import { ErrorState } from './views/error_state'; | ||
| import { Overview } from './views/overview'; | ||
|
|
||
| export const WorkplaceSearch: React.FC<IInitialAppData> = () => { | ||
| export const WorkplaceSearch: React.FC<IInitialAppData> = (props) => { | ||
| const { config } = useContext(KibanaContext) as IKibanaContext; | ||
| return !config.host ? <WorkplaceSearchUnconfigured /> : <WorkplaceSearchConfigured {...props} />; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 Glad you liked this pattern I used in App Search! |
||
| }; | ||
|
|
||
| export const WorkplaceSearchConfigured: React.FC<IInitialAppData> = (props) => { | ||
| const { hasInitialized } = useValues(AppLogic) as IAppValues; | ||
| const { initializeAppData } = useActions(AppLogic) as IAppActions; | ||
|
Comment on lines
+30
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder to self: I should update App Search's |
||
| const { errorConnecting } = useValues(HttpLogic) as IHttpLogicValues; | ||
|
|
||
| if (!config.host) | ||
| return ( | ||
| <Switch> | ||
| <Route exact path={SETUP_GUIDE_PATH}> | ||
| <SetupGuide /> | ||
| </Route> | ||
| <Route> | ||
| <Redirect to={SETUP_GUIDE_PATH} /> | ||
| </Route> | ||
| </Switch> | ||
| ); | ||
| useEffect(() => { | ||
| if (!hasInitialized) initializeAppData(props); | ||
| }, [hasInitialized]); | ||
|
|
||
| return ( | ||
| <Switch> | ||
|
|
@@ -61,3 +60,14 @@ export const WorkplaceSearch: React.FC<IInitialAppData> = () => { | |
| </Switch> | ||
| ); | ||
| }; | ||
|
|
||
| export const WorkplaceSearchUnconfigured: React.FC = () => ( | ||
| <Switch> | ||
| <Route exact path={SETUP_GUIDE_PATH}> | ||
| <SetupGuide /> | ||
| </Route> | ||
| <Route> | ||
| <Redirect to={SETUP_GUIDE_PATH} /> | ||
| </Route> | ||
| </Switch> | ||
| ); | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hidden routes, with navigation, also have an
ErrorState