Skip to content

Commit 137aadb

Browse files
[Enterprise Search] Upgrade to Kea 2.2-rc.4 (#76206)
* Add Kea 2.20.rc.3 * Remove Kea declarations * Convert AppLogic files to use new syntax - Utilizes MakeLogicType to type the logic file and remove bespoke typings - Use object syntax for actions and reducers, instead of functions - Add return types to actions in interface - Remove interfaces from component (Kea does this automagically now) - Also renamed IAppLogic* to IApp* * Convert Workplace Search Overview files to use new syntax - Utilizes MakeLogicType to type the logic file and remove bespoke typings - Use object syntax for actions and reducers, instead of functions - Add return types to actions in interface - Remove interfaces from component (Kea does this automagically now) - Also renamed mockLogic* to mockApp* * Convert HttpLogic files to use new syntax - Utilizes MakeLogicType to type the logic file and remove bespoke typings - Use object syntax for actions and reducers, instead of functions - Add return types to actions in interface - Remove interfaces from component (Kea does this automagically now) - Also renamed IHttpLogic* to IHttp* * Convert FlashMessages files to use new syntax - Utilizes MakeLogicType to type the logic file and remove bespoke typings - Use object syntax for actions and reducers, instead of functions - Add return types to actions in interface - Remove interfaces from component (Kea does this automagically now) * Remove hand-rolled Kea types Bye-bye pretty code * Upgrade to rc4 per author From Kea author: “I’d suggest upgrading to rc.4 before merging though, as I seem to have committed some optional chaining operators ("?.") into the compiled JS output, which will cause errors if anyone is using an older browser. You can also wait for 2.2.0 final, but that might still be a week or more away…” Co-authored-by: Elastic Machine <[email protected]>
1 parent 9b59122 commit 137aadb

File tree

23 files changed

+97
-181
lines changed

23 files changed

+97
-181
lines changed

x-pack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
"jsdom": "13.1.0",
196196
"jsondiffpatch": "0.4.1",
197197
"jsts": "^1.6.2",
198-
"kea": "^2.0.1",
198+
"kea": "2.2.0-rc.4",
199199
"loader-utils": "^1.2.3",
200200
"lz-string": "^1.4.4",
201201
"madge": "3.4.4",

x-pack/plugins/enterprise_search/public/applications/app_search/app_logic.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { kea } from 'kea';
7+
import { kea, MakeLogicType } from 'kea';
88

99
import { IInitialAppData } from '../../../common/types';
10-
import { IKeaLogic } from '../shared/types';
1110

12-
export interface IAppLogicValues {
11+
export interface IAppValues {
1312
hasInitialized: boolean;
1413
}
15-
export interface IAppLogicActions {
14+
export interface IAppActions {
1615
initializeAppData(props: IInitialAppData): void;
1716
}
1817

19-
export const AppLogic = kea({
20-
actions: (): IAppLogicActions => ({
18+
export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
19+
actions: {
2120
initializeAppData: (props) => props,
22-
}),
23-
reducers: () => ({
21+
},
22+
reducers: {
2423
hasInitialized: [
2524
false,
2625
{
2726
initializeAppData: () => true,
2827
},
2928
],
30-
}),
31-
}) as IKeaLogic<IAppLogicValues, IAppLogicActions>;
29+
},
30+
});

x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { useActions, useValues } from 'kea';
1111
import { i18n } from '@kbn/i18n';
1212

1313
import { KibanaContext, IKibanaContext } from '../index';
14-
import { HttpLogic, IHttpLogicValues } from '../shared/http';
15-
import { AppLogic, IAppLogicActions, IAppLogicValues } from './app_logic';
14+
import { HttpLogic } from '../shared/http';
15+
import { AppLogic } from './app_logic';
1616
import { IInitialAppData } from '../../../common/types';
1717

1818
import { APP_SEARCH_PLUGIN } from '../../../common/constants';
@@ -48,9 +48,9 @@ export const AppSearchUnconfigured: React.FC = () => (
4848
);
4949

5050
export const AppSearchConfigured: React.FC<IInitialAppData> = (props) => {
51-
const { hasInitialized } = useValues(AppLogic) as IAppLogicValues;
52-
const { initializeAppData } = useActions(AppLogic) as IAppLogicActions;
53-
const { errorConnecting } = useValues(HttpLogic) as IHttpLogicValues;
51+
const { hasInitialized } = useValues(AppLogic);
52+
const { initializeAppData } = useActions(AppLogic);
53+
const { errorConnecting } = useValues(HttpLogic);
5454

5555
useEffect(() => {
5656
if (!hasInitialized) initializeAppData(props);

x-pack/plugins/enterprise_search/public/applications/kea.d.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React, { Fragment } from 'react';
88
import { useValues } from 'kea';
99
import { EuiCallOut, EuiCallOutProps, EuiSpacer } from '@elastic/eui';
1010

11-
import { FlashMessagesLogic, IFlashMessagesValues } from './flash_messages_logic';
11+
import { FlashMessagesLogic } from './flash_messages_logic';
1212

1313
const FLASH_MESSAGE_TYPES = {
1414
success: { color: 'success' as EuiCallOutProps['color'], icon: 'check' },
@@ -18,7 +18,7 @@ const FLASH_MESSAGE_TYPES = {
1818
};
1919

2020
export const FlashMessages: React.FC = ({ children }) => {
21-
const { messages } = useValues(FlashMessagesLogic) as IFlashMessagesValues;
21+
const { messages } = useValues(FlashMessagesLogic);
2222

2323
// If we have no messages to display, do not render the element at all
2424
if (!messages.length) return null;

x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { kea } from 'kea';
7+
import { kea, MakeLogicType } from 'kea';
88
import { ReactNode } from 'react';
99
import { History } from 'history';
1010

11-
import { IKeaLogic, TKeaReducers, IKeaParams } from '../types';
12-
1311
export interface IFlashMessage {
1412
type: 'success' | 'info' | 'warning' | 'error';
1513
message: ReactNode;
@@ -22,27 +20,27 @@ export interface IFlashMessagesValues {
2220
historyListener: Function | null;
2321
}
2422
export interface IFlashMessagesActions {
25-
setFlashMessages(messages: IFlashMessage | IFlashMessage[]): void;
23+
setFlashMessages(messages: IFlashMessage | IFlashMessage[]): { messages: IFlashMessage[] };
2624
clearFlashMessages(): void;
27-
setQueuedMessages(messages: IFlashMessage | IFlashMessage[]): void;
25+
setQueuedMessages(messages: IFlashMessage | IFlashMessage[]): { messages: IFlashMessage[] };
2826
clearQueuedMessages(): void;
29-
listenToHistory(history: History): void;
30-
setHistoryListener(historyListener: Function): void;
27+
listenToHistory(history: History): History;
28+
setHistoryListener(historyListener: Function): { historyListener: Function };
3129
}
3230

3331
const convertToArray = (messages: IFlashMessage | IFlashMessage[]) =>
3432
!Array.isArray(messages) ? [messages] : messages;
3533

36-
export const FlashMessagesLogic = kea({
37-
actions: (): IFlashMessagesActions => ({
34+
export const FlashMessagesLogic = kea<MakeLogicType<IFlashMessagesValues, IFlashMessagesActions>>({
35+
actions: {
3836
setFlashMessages: (messages) => ({ messages: convertToArray(messages) }),
3937
clearFlashMessages: () => null,
4038
setQueuedMessages: (messages) => ({ messages: convertToArray(messages) }),
4139
clearQueuedMessages: () => null,
4240
listenToHistory: (history) => history,
4341
setHistoryListener: (historyListener) => ({ historyListener }),
44-
}),
45-
reducers: (): TKeaReducers<IFlashMessagesValues, IFlashMessagesActions> => ({
42+
},
43+
reducers: {
4644
messages: [
4745
[],
4846
{
@@ -63,8 +61,8 @@ export const FlashMessagesLogic = kea({
6361
setHistoryListener: (_, { historyListener }) => historyListener,
6462
},
6563
],
66-
}),
67-
listeners: ({ values, actions }): Partial<IFlashMessagesActions> => ({
64+
},
65+
listeners: ({ values, actions }) => ({
6866
listenToHistory: (history) => {
6967
// On React Router navigation, clear previous flash messages and load any queued messages
7068
const unlisten = history.listen(() => {
@@ -81,7 +79,4 @@ export const FlashMessagesLogic = kea({
8179
if (removeHistoryListener) removeHistoryListener();
8280
},
8381
}),
84-
} as IKeaParams<IFlashMessagesValues, IFlashMessagesActions>) as IKeaLogic<
85-
IFlashMessagesValues,
86-
IFlashMessagesActions
87-
>;
82+
});

x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_provider.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@ import React, { useEffect } from 'react';
88
import { useValues, useActions } from 'kea';
99
import { History } from 'history';
1010

11-
import {
12-
FlashMessagesLogic,
13-
IFlashMessagesValues,
14-
IFlashMessagesActions,
15-
} from './flash_messages_logic';
11+
import { FlashMessagesLogic } from './flash_messages_logic';
1612

1713
interface IFlashMessagesProviderProps {
1814
history: History;
1915
}
2016

2117
export const FlashMessagesProvider: React.FC<IFlashMessagesProviderProps> = ({ history }) => {
22-
const { historyListener } = useValues(FlashMessagesLogic) as IFlashMessagesValues;
23-
const { listenToHistory } = useActions(FlashMessagesLogic) as IFlashMessagesActions;
18+
const { historyListener } = useValues(FlashMessagesLogic);
19+
const { listenToHistory } = useActions(FlashMessagesLogic);
2420

2521
useEffect(() => {
2622
if (!historyListener) listenToHistory(history);

x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,36 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { kea } from 'kea';
7+
import { kea, MakeLogicType } from 'kea';
88

99
import { HttpSetup } from 'src/core/public';
1010

11-
import { IKeaLogic, IKeaParams, TKeaReducers } from '../../shared/types';
12-
13-
export interface IHttpLogicValues {
11+
export interface IHttpValues {
1412
http: HttpSetup;
1513
httpInterceptors: Function[];
1614
errorConnecting: boolean;
1715
}
18-
export interface IHttpLogicActions {
19-
initializeHttp({ http, errorConnecting }: { http: HttpSetup; errorConnecting?: boolean }): void;
16+
export interface IHttpActions {
17+
initializeHttp({
18+
http,
19+
errorConnecting,
20+
}: {
21+
http: HttpSetup;
22+
errorConnecting?: boolean;
23+
}): { http: HttpSetup; errorConnecting?: boolean };
2024
initializeHttpInterceptors(): void;
21-
setHttpInterceptors(httpInterceptors: Function[]): void;
22-
setErrorConnecting(errorConnecting: boolean): void;
25+
setHttpInterceptors(httpInterceptors: Function[]): { httpInterceptors: Function[] };
26+
setErrorConnecting(errorConnecting: boolean): { errorConnecting: boolean };
2327
}
2428

25-
export const HttpLogic = kea({
26-
actions: (): IHttpLogicActions => ({
29+
export const HttpLogic = kea<MakeLogicType<IHttpValues, IHttpActions>>({
30+
actions: {
2731
initializeHttp: ({ http, errorConnecting }) => ({ http, errorConnecting }),
2832
initializeHttpInterceptors: () => null,
2933
setHttpInterceptors: (httpInterceptors) => ({ httpInterceptors }),
3034
setErrorConnecting: (errorConnecting) => ({ errorConnecting }),
31-
}),
32-
reducers: (): TKeaReducers<IHttpLogicValues, IHttpLogicActions> => ({
35+
},
36+
reducers: {
3337
http: [
3438
(null as unknown) as HttpSetup,
3539
{
@@ -49,7 +53,7 @@ export const HttpLogic = kea({
4953
setErrorConnecting: (_, { errorConnecting }) => errorConnecting,
5054
},
5155
],
52-
}),
56+
},
5357
listeners: ({ values, actions }) => ({
5458
initializeHttpInterceptors: () => {
5559
const httpInterceptors = [];
@@ -80,7 +84,4 @@ export const HttpLogic = kea({
8084
});
8185
},
8286
}),
83-
} as IKeaParams<IHttpLogicValues, IHttpLogicActions>) as IKeaLogic<
84-
IHttpLogicValues,
85-
IHttpLogicActions
86-
>;
87+
});

x-pack/plugins/enterprise_search/public/applications/shared/http/http_provider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import { useActions } from 'kea';
99

1010
import { HttpSetup } from 'src/core/public';
1111

12-
import { HttpLogic, IHttpLogicActions } from './http_logic';
12+
import { HttpLogic } from './http_logic';
1313

1414
interface IHttpProviderProps {
1515
http: HttpSetup;
1616
errorConnecting?: boolean;
1717
}
1818

1919
export const HttpProvider: React.FC<IHttpProviderProps> = (props) => {
20-
const { initializeHttp, initializeHttpInterceptors } = useActions(HttpLogic) as IHttpLogicActions;
20+
const { initializeHttp, initializeHttpInterceptors } = useActions(HttpLogic);
2121

2222
useEffect(() => {
2323
initializeHttp(props);

x-pack/plugins/enterprise_search/public/applications/shared/http/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export { HttpLogic, IHttpLogicValues, IHttpLogicActions } from './http_logic';
7+
export { HttpLogic, IHttpValues, IHttpActions } from './http_logic';
88
export { HttpProvider } from './http_provider';

0 commit comments

Comments
 (0)