Skip to content

Commit 0cbdd5b

Browse files
authored
Fix es_ui_shared eslint violations for useRequest hook (#72947) (#76328)
* Reconcile request helpers with eslint rules for React hooks. - Add clearer cleanup logic for unmounted components. - Align logic and comments in np_ready_request.ts and original request.ts. * Reorganize modules and convert tests to TS. - Split request.ts into send_request.ts and use_request.ts. - Convert test files into TS. - Relax SendRequestResponse type definition to type error as any instead of expecting an Error, since we weren't actually fulfilling this expectation. * Convert everything to hooks and add test coverage for request behavior. * Fix Watcher memoization bugs. # Conflicts: # .eslintrc.js
1 parent db3f0d6 commit 0cbdd5b

File tree

20 files changed

+930
-662
lines changed

20 files changed

+930
-662
lines changed

.eslintrc.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ module.exports = {
9494
'jsx-a11y/no-onchange': 'off',
9595
},
9696
},
97-
{
98-
files: ['src/plugins/es_ui_shared/**/*.{js,mjs,ts,tsx}'],
99-
rules: {
100-
'react-hooks/exhaustive-deps': 'off',
101-
},
102-
},
10397
{
10498
files: ['src/plugins/eui_utils/**/*.{js,mjs,ts,tsx}'],
10599
rules: {
@@ -131,25 +125,12 @@ module.exports = {
131125
'jsx-a11y/click-events-have-key-events': 'off',
132126
},
133127
},
134-
{
135-
files: ['x-pack/legacy/plugins/index_management/**/*.{js,mjs,ts,tsx}'],
136-
rules: {
137-
'react-hooks/exhaustive-deps': 'off',
138-
'react-hooks/rules-of-hooks': 'off',
139-
},
140-
},
141128
{
142129
files: ['x-pack/plugins/ml/**/*.{js,mjs,ts,tsx}'],
143130
rules: {
144131
'react-hooks/exhaustive-deps': 'off',
145132
},
146133
},
147-
{
148-
files: ['x-pack/legacy/plugins/snapshot_restore/**/*.{js,mjs,ts,tsx}'],
149-
rules: {
150-
'react-hooks/exhaustive-deps': 'off',
151-
},
152-
},
153134

154135
/**
155136
* Files that require Apache 2.0 headers, settings

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ export const useGlobalFlyout = () => {
160160
Array.from(getContents()).forEach(removeContent);
161161
}
162162
};
163+
// https://github.com/elastic/kibana/issues/73970
164+
/* eslint-disable-next-line react-hooks/exhaustive-deps */
163165
}, [removeContent]);
164166

165167
return { ...ctx, addContent };

src/plugins/es_ui_shared/public/components/json_editor/json_editor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export const JsonEditor = React.memo(
5252
isControlled,
5353
});
5454

55+
// https://github.com/elastic/kibana/issues/73971
56+
/* eslint-disable-next-line react-hooks/exhaustive-deps */
5557
const debouncedSetContent = useCallback(debounce(setContent, 300), [setContent]);
5658

5759
// We let the consumer control the validation and the error message.
@@ -76,6 +78,7 @@ export const JsonEditor = React.memo(
7678
debouncedSetContent(updated);
7779
}
7880
},
81+
/* eslint-disable-next-line react-hooks/exhaustive-deps */
7982
[isControlled]
8083
);
8184

src/plugins/es_ui_shared/public/components/json_editor/use_json.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export const useJson = <T extends object = { [key: string]: any }>({
8484
} else {
8585
didMount.current = true;
8686
}
87+
// https://github.com/elastic/kibana/issues/73971
88+
/* eslint-disable-next-line react-hooks/exhaustive-deps */
8789
}, [content]);
8890

8991
return {

src/plugins/es_ui_shared/public/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export {
3939
UseRequestResponse,
4040
sendRequest,
4141
useRequest,
42-
} from './request/np_ready_request';
42+
} from './request';
4343

4444
export { indices } from './indices';
4545

src/plugins/es_ui_shared/public/request/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,5 @@
1717
* under the License.
1818
*/
1919

20-
export {
21-
SendRequestConfig,
22-
SendRequestResponse,
23-
UseRequestConfig,
24-
UseRequestResponse,
25-
sendRequest,
26-
useRequest,
27-
} from './request';
20+
export { SendRequestConfig, SendRequestResponse, sendRequest } from './send_request';
21+
export { UseRequestConfig, UseRequestResponse, useRequest } from './use_request';

src/plugins/es_ui_shared/public/request/np_ready_request.ts

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

0 commit comments

Comments
 (0)