Skip to content

Commit 1e4c46b

Browse files
authored
fix(eslint): fix react-hooks/preserve-manual-memoization issues (#7617)
1 parent ffb0cea commit 1e4c46b

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

configs/eslint-config-compass/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const chaiFriendly = require('eslint-plugin-chai-friendly');
77

88
// TODO(COMPASS-9459): disabling a bunch of new rules to unblock automatic updates
99
const tempNewEslintRulesDisabled = {
10-
'react-hooks/preserve-manual-memoization': 'off',
1110
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
1211
};
1312

packages/compass-components/src/components/file-picker-dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ function FilePickerDialog({
397397
});
398398
onChange(files);
399399
},
400-
[onChange]
400+
[backend, onChange]
401401
);
402402

403403
const handleOpenFileInput = useCallback(() => {

packages/compass-crud/src/components/document-list.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,17 @@ const DocumentList: React.FunctionComponent<DocumentListProps> = (props) => {
432432
{}
433433
);
434434

435-
const onColumnWidthChange = useCallback((newColumnWidths) => {
436-
setColumnWidths({
437-
...columnWidths,
438-
...newColumnWidths,
439-
});
440-
}, []);
435+
const onColumnWidthChange = useCallback(
436+
(newColumnWidths: Record<string, number>) => {
437+
setColumnWidths((columnWidths) => {
438+
return {
439+
...columnWidths,
440+
...newColumnWidths,
441+
};
442+
});
443+
},
444+
[setColumnWidths]
445+
);
441446

442447
const renderContent = useCallback(
443448
(scrollTriggerRef: React.Ref<HTMLDivElement>) => {
@@ -523,6 +528,8 @@ const DocumentList: React.FunctionComponent<DocumentListProps> = (props) => {
523528
query,
524529
scrollRef,
525530
currentViewInitialScrollTop,
531+
columnWidths,
532+
onColumnWidthChange,
526533
]
527534
);
528535

packages/connection-form/src/components/advanced-options-tabs/ssh-tunnel-tab/proxy-and-ssh-tunnel-tab.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ChangeEvent } from 'react';
2-
import React, { useState, useCallback } from 'react';
2+
import React, { useState, useCallback, useMemo } from 'react';
33
import type { ConnectionOptions } from 'mongodb-data-service';
44
import {
55
Label,
@@ -125,17 +125,22 @@ function ProxyAndSshTunnelTab({
125125
connectionStringUrl,
126126
connectionOptions
127127
);
128-
129-
const options = [...tabOptions];
130128
const showProxySettings = useConnectionFormSetting('showProxySettings');
131-
if (showProxySettings) {
132-
options.push({
133-
title: 'Application-level Proxy',
134-
id: 'app-proxy',
135-
type: 'app-proxy',
136-
component: AppProxy,
137-
});
138-
}
129+
const options = useMemo(() => {
130+
if (showProxySettings) {
131+
return [
132+
...tabOptions,
133+
{
134+
title: 'Application-level Proxy',
135+
id: 'app-proxy',
136+
type: 'app-proxy',
137+
component: AppProxy,
138+
} as const,
139+
];
140+
} else {
141+
return [...tabOptions];
142+
}
143+
}, [showProxySettings]);
139144

140145
const selectedOptionIndex =
141146
options.findIndex((x) => x.type === selectedTunnelType) ?? 0;
@@ -177,15 +182,15 @@ function ProxyAndSshTunnelTab({
177182
);
178183

179184
const optionSelected = useCallback(
180-
(event: ChangeEvent<HTMLInputElement>) => {
181-
event.preventDefault();
182-
const item = options.find(({ id }) => id === event.target.value);
185+
(evt: ChangeEvent<HTMLInputElement>) => {
186+
evt.preventDefault();
187+
const item = options.find(({ id }) => id === evt.target.value);
183188
if (item) {
184189
handleOptionChanged(selectedOption.type, item.type);
185190
setSelectedOption(item);
186191
}
187192
},
188-
[selectedOption, handleOptionChanged]
193+
[handleOptionChanged, options, selectedOption.type]
189194
);
190195

191196
const TunnelContent = selectedOption.component;

0 commit comments

Comments
 (0)