Skip to content

Commit

Permalink
[Enterprise Search][tech debt] Add Kea logic paths for easier debuggi…
Browse files Browse the repository at this point in the history
…ng/defaults (#77698) (#77820)

* Add Kea logic paths for easier debugging/defaults

* PR feedback: prefer snake_case to match file names, use exact file name for last path key

* Document Kea + casing logic
  • Loading branch information
Constance authored Sep 17, 2020
1 parent 8c57188 commit 962bc17
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions x-pack/plugins/enterprise_search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ This plugin's goal is to provide a Kibana user interface to the Enterprise Searc
2. Update `config/kibana.dev.yml` with `enterpriseSearch.host: 'http://localhost:3002'`
3. For faster QA/development, run Enterprise Search on [elasticsearch-native auth](https://www.elastic.co/guide/en/app-search/current/security-and-users.html#app-search-self-managed-security-and-user-management-elasticsearch-native-realm) and log in as the `elastic` superuser on Kibana.

### Kea

Enterprise Search uses [Kea.js](https://github.com/keajs/kea) to manage our React/Redux state for us. Kea state is handled in our `*Logic` files and exposes [values](https://kea.js.org/docs/guide/concepts#values) and [actions](https://kea.js.org/docs/guide/concepts#actions) for our components to get and set state with.

#### Debugging Kea

To debug Kea state in-browser, Kea recommends [Redux Devtools](https://kea.js.org/docs/guide/debugging). To facilitate debugging, we use the [path](https://kea.js.org/docs/guide/debugging/#setting-the-path-manually) key with `snake_case`d paths. The path key should always end with the logic filename (e.g. `['enterprise_search', 'some_logic']`) to make it easy for devs to quickly find/jump to files via IDE tooling.

## Testing

### Unit tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface IAppActions {
}

export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
path: ['enterprise_search', 'app_search', 'app_logic'],
actions: {
initializeAppData: (props) => props,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const convertToArray = (messages: IFlashMessage | IFlashMessage[]) =>
!Array.isArray(messages) ? [messages] : messages;

export const FlashMessagesLogic = kea<MakeLogicType<IFlashMessagesValues, IFlashMessagesActions>>({
path: ['enterprise_search', 'flash_messages_logic'],
actions: {
setFlashMessages: (messages) => ({ messages: convertToArray(messages) }),
clearFlashMessages: () => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IHttpActions {
}

export const HttpLogic = kea<MakeLogicType<IHttpValues, IHttpActions>>({
path: ['enterprise_search', 'http_logic'],
actions: {
initializeHttp: (props) => props,
initializeHttpInterceptors: () => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IAppActions {
}

export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
path: ['enterprise_search', 'workplace_search', 'app_logic'],
actions: {
initializeAppData: ({ workplaceSearch, isFederatedAuth }) => ({
workplaceSearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface IOverviewValues extends IOverviewServerData {
}

export const OverviewLogic = kea<MakeLogicType<IOverviewValues, IOverviewActions>>({
path: ['enterprise_search', 'workplace_search', 'overview_logic'],
actions: {
setServerData: (serverData) => serverData,
initializeOverview: () => null,
Expand Down

0 comments on commit 962bc17

Please sign in to comment.