Skip to content

Commit 4127ab5

Browse files
Merge branch '7.x' into backport/7.x/pr-76572
2 parents 344f785 + a0be161 commit 4127ab5

81 files changed

Lines changed: 1881 additions & 564 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { parseEsError } from './es_error_parser';
20+
21+
describe('ES error parser', () => {
22+
test('should return all the cause of the error', () => {
23+
const esError = `{
24+
"error": {
25+
"reason": "Houston we got a problem",
26+
"caused_by": {
27+
"reason": "First reason",
28+
"caused_by": {
29+
"reason": "Second reason",
30+
"caused_by": {
31+
"reason": "Third reason"
32+
}
33+
}
34+
}
35+
}
36+
}`;
37+
38+
const parsedError = parseEsError(esError);
39+
expect(parsedError.message).toEqual('Houston we got a problem');
40+
expect(parsedError.cause).toEqual(['First reason', 'Second reason', 'Third reason']);
41+
});
42+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
interface ParsedError {
21+
message: string;
22+
cause: string[];
23+
}
24+
25+
const getCause = (obj: any = {}, causes: string[] = []): string[] => {
26+
const updated = [...causes];
27+
28+
if (obj.caused_by) {
29+
updated.push(obj.caused_by.reason);
30+
31+
// Recursively find all the "caused by" reasons
32+
return getCause(obj.caused_by, updated);
33+
}
34+
35+
return updated.filter(Boolean);
36+
};
37+
38+
export const parseEsError = (err: string): ParsedError => {
39+
try {
40+
const { error } = JSON.parse(err);
41+
const cause = getCause(error);
42+
return {
43+
message: error.reason,
44+
cause,
45+
};
46+
} catch (e) {
47+
return {
48+
message: err,
49+
cause: [],
50+
};
51+
}
52+
};

src/plugins/es_ui_shared/__packages_do_not_import__/errors/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919

2020
export { isEsError } from './is_es_error';
2121
export { handleEsError } from './handle_es_error';
22+
export { parseEsError } from './es_error_parser';

src/plugins/es_ui_shared/__packages_do_not_import__/global_flyout/global_flyout.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const GlobalFlyoutProvider: React.FC = ({ children }) => {
5454
const [showFlyout, setShowFlyout] = useState(false);
5555
const [activeContent, setActiveContent] = useState<Content<any> | undefined>(undefined);
5656

57-
const { id, Component, props, flyoutProps } = activeContent ?? {};
57+
const { id, Component, props, flyoutProps, cleanUpFunc } = activeContent ?? {};
5858

5959
const addContent: Context['addContent'] = useCallback((content) => {
6060
setActiveContent((prev) => {
@@ -77,11 +77,19 @@ export const GlobalFlyoutProvider: React.FC = ({ children }) => {
7777

7878
const removeContent: Context['removeContent'] = useCallback(
7979
(contentId: string) => {
80+
// Note: when we will actually deal with multi content then
81+
// there will be more logic here! :)
8082
if (contentId === id) {
83+
setActiveContent(undefined);
84+
85+
if (cleanUpFunc) {
86+
cleanUpFunc();
87+
}
88+
8189
closeFlyout();
8290
}
8391
},
84-
[id, closeFlyout]
92+
[id, closeFlyout, cleanUpFunc]
8593
);
8694

8795
const mergedFlyoutProps = useMemo(() => {
@@ -130,14 +138,6 @@ export const useGlobalFlyout = () => {
130138
const contents = useRef<Set<string> | undefined>(undefined);
131139
const { removeContent, addContent: addContentToContext } = ctx;
132140

133-
useEffect(() => {
134-
isMounted.current = true;
135-
136-
return () => {
137-
isMounted.current = false;
138-
};
139-
}, []);
140-
141141
const getContents = useCallback(() => {
142142
if (contents.current === undefined) {
143143
contents.current = new Set();
@@ -153,6 +153,14 @@ export const useGlobalFlyout = () => {
153153
[getContents, addContentToContext]
154154
);
155155

156+
useEffect(() => {
157+
isMounted.current = true;
158+
159+
return () => {
160+
isMounted.current = false;
161+
};
162+
}, []);
163+
156164
useEffect(() => {
157165
return () => {
158166
if (!isMounted.current) {

src/plugins/es_ui_shared/server/errors/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
* under the License.
1818
*/
1919

20-
export { isEsError, handleEsError } from '../../__packages_do_not_import__/errors';
20+
export { isEsError, handleEsError, parseEsError } from '../../__packages_do_not_import__/errors';

src/plugins/es_ui_shared/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
export { isEsError, handleEsError } from './errors';
20+
export { isEsError, handleEsError, parseEsError } from './errors';
2121

2222
/** dummy plugin*/
2323
export function plugin() {

x-pack/plugins/index_management/public/application/app_context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface AppDependencies {
3737
setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs'];
3838
uiSettings: CoreSetup['uiSettings'];
3939
urlGenerators: SharePluginStart['urlGenerators'];
40+
docLinks: CoreStart['docLinks'];
4041
}
4142

4243
export const AppContextProvider = ({

x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { setup as componentTemplateDetailsSetup } from './component_template_det
99

1010
export { nextTick, getRandomString, findTestSubject } from '@kbn/test/jest';
1111

12-
export { setupEnvironment, appDependencies } from './setup_environment';
12+
export { setupEnvironment, componentTemplatesDependencies } from './setup_environment';
1313

1414
export const pageHelpers = {
1515
componentTemplateList: { setup: componentTemplatesListSetup },

x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/setup_environment.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '../../../../../../../../../../src/core/public/mocks';
1616

1717
import { GlobalFlyout } from '../../../../../../../../../../src/plugins/es_ui_shared/public';
18+
import { AppContextProvider } from '../../../../../app_context';
1819
import { MappingsEditorProvider } from '../../../../mappings_editor';
1920
import { ComponentTemplatesProvider } from '../../../component_templates_context';
2021

@@ -24,7 +25,12 @@ import { API_BASE_PATH } from './constants';
2425
const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });
2526
const { GlobalFlyoutProvider } = GlobalFlyout;
2627

27-
export const appDependencies = {
28+
// We provide the minimum deps required to make the tests pass
29+
const appDependencies = {
30+
docLinks: {} as any,
31+
} as any;
32+
33+
export const componentTemplatesDependencies = {
2834
httpClient: (mockHttpClient as unknown) as HttpSetup,
2935
apiBasePath: API_BASE_PATH,
3036
trackMetric: () => {},
@@ -44,11 +50,14 @@ export const setupEnvironment = () => {
4450
};
4551

4652
export const WithAppDependencies = (Comp: any) => (props: any) => (
47-
<MappingsEditorProvider>
48-
<ComponentTemplatesProvider value={appDependencies}>
49-
<GlobalFlyoutProvider>
50-
<Comp {...props} />
51-
</GlobalFlyoutProvider>
52-
</ComponentTemplatesProvider>
53-
</MappingsEditorProvider>
53+
<AppContextProvider value={appDependencies}>
54+
<MappingsEditorProvider>
55+
<ComponentTemplatesProvider value={componentTemplatesDependencies}>
56+
<GlobalFlyoutProvider>
57+
<Comp {...props} />
58+
</GlobalFlyoutProvider>
59+
</ComponentTemplatesProvider>
60+
</MappingsEditorProvider>
61+
/
62+
</AppContextProvider>
5463
);

x-pack/plugins/index_management/public/application/components/component_templates/__jest__/index.ts

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

7-
export { appDependencies as componentTemplatesMockDependencies } from './client_integration/helpers';
7+
export { componentTemplatesDependencies as componentTemplatesMockDependencies } from './client_integration/helpers';

0 commit comments

Comments
 (0)