Skip to content

Commit 94f9ce6

Browse files
authored
FE: Remove lodash lib (#301)
1 parent 475caa3 commit 94f9ce6

File tree

18 files changed

+173
-38
lines changed

18 files changed

+173
-38
lines changed

frontend/.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
{
7676
"props": true,
7777
"ignorePropertyModificationsFor": [
78-
"state"
78+
"state",
79+
"acc",
80+
"accumulator"
7981
]
8082
}
8183
],

frontend/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"classnames": "^2.2.6",
1818
"json-schema-faker": "^0.5.6",
1919
"jsonpath-plus": "^7.2.0",
20-
"lodash": "^4.17.21",
2120
"lossless-json": "^2.0.8",
2221
"pretty-ms": "7.0.1",
2322
"react": "^18.1.0",
@@ -62,7 +61,6 @@
6261
"@testing-library/jest-dom": "^5.16.5",
6362
"@testing-library/user-event": "^14.4.3",
6463
"@types/eventsource": "^1.1.8",
65-
"@types/lodash": "^4.14.172",
6664
"@types/lossless-json": "^1.0.1",
6765
"@types/node": "^20.11.17",
6866
"@types/react": "^18.0.9",

frontend/pnpm-lock.yaml

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const App: React.FC = () => {
9797
</Suspense>
9898
</ThemeProvider>
9999
</GlobalSettingsProvider>
100-
<ReactQueryDevtools initialIsOpen={false} />
100+
<ReactQueryDevtools initialIsOpen={false} position="bottom-right" />
101101
</QueryClientProvider>
102102
);
103103
};

frontend/src/components/Connect/Details/Actions/__tests__/Actions.spec.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@ import React from 'react';
22
import { render, WithRoute } from 'lib/testHelpers';
33
import { clusterConnectConnectorPath } from 'lib/paths';
44
import Actions from 'components/Connect/Details/Actions/Actions';
5-
import { ConnectorAction, ConnectorState } from 'generated-sources';
5+
import { Connector, ConnectorAction, ConnectorState } from 'generated-sources';
66
import { screen, waitFor } from '@testing-library/react';
77
import userEvent from '@testing-library/user-event';
88
import {
99
useConnector,
1010
useUpdateConnectorState,
1111
} from 'lib/hooks/api/kafkaConnect';
1212
import { connector } from 'lib/fixtures/kafkaConnect';
13-
import set from 'lodash/set';
13+
14+
function setConnectorStatus(con: Connector, state: ConnectorState) {
15+
return {
16+
...con,
17+
status: {
18+
...con,
19+
state,
20+
},
21+
};
22+
}
1423

1524
const mockHistoryPush = jest.fn();
1625
const deleteConnector = jest.fn();
@@ -66,7 +75,7 @@ describe('Actions', () => {
6675

6776
it('renders buttons when paused', async () => {
6877
(useConnector as jest.Mock).mockImplementation(() => ({
69-
data: set({ ...connector }, 'status.state', ConnectorState.PAUSED),
78+
data: setConnectorStatus(connector, ConnectorState.PAUSED),
7079
}));
7180
renderComponent();
7281
await afterClickRestartButton();
@@ -78,7 +87,7 @@ describe('Actions', () => {
7887

7988
it('renders buttons when failed', async () => {
8089
(useConnector as jest.Mock).mockImplementation(() => ({
81-
data: set({ ...connector }, 'status.state', ConnectorState.FAILED),
90+
data: setConnectorStatus(connector, ConnectorState.FAILED),
8291
}));
8392
renderComponent();
8493
await afterClickRestartButton();
@@ -90,7 +99,7 @@ describe('Actions', () => {
9099

91100
it('renders buttons when unassigned', async () => {
92101
(useConnector as jest.Mock).mockImplementation(() => ({
93-
data: set({ ...connector }, 'status.state', ConnectorState.UNASSIGNED),
102+
data: setConnectorStatus(connector, ConnectorState.UNASSIGNED),
94103
}));
95104
renderComponent();
96105
await afterClickRestartButton();
@@ -102,7 +111,7 @@ describe('Actions', () => {
102111

103112
it('renders buttons when running connector action', async () => {
104113
(useConnector as jest.Mock).mockImplementation(() => ({
105-
data: set({ ...connector }, 'status.state', ConnectorState.RUNNING),
114+
data: setConnectorStatus(connector, ConnectorState.RUNNING),
106115
}));
107116
renderComponent();
108117
await afterClickRestartButton();
@@ -115,7 +124,7 @@ describe('Actions', () => {
115124
describe('mutations', () => {
116125
beforeEach(() => {
117126
(useConnector as jest.Mock).mockImplementation(() => ({
118-
data: set({ ...connector }, 'status.state', ConnectorState.RUNNING),
127+
data: setConnectorStatus(connector, ConnectorState.RUNNING),
119128
}));
120129
});
121130

@@ -185,7 +194,7 @@ describe('Actions', () => {
185194
it('calls resumeConnector when resume button clicked', async () => {
186195
const resumeConnector = jest.fn();
187196
(useConnector as jest.Mock).mockImplementation(() => ({
188-
data: set({ ...connector }, 'status.state', ConnectorState.PAUSED),
197+
data: setConnectorStatus(connector, ConnectorState.PAUSED),
189198
}));
190199
(useUpdateConnectorState as jest.Mock).mockImplementation(() => ({
191200
mutateAsync: resumeConnector,

frontend/src/components/Connect/New/New.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { Button } from 'components/common/Button/Button';
1818
import PageHeading from 'components/common/PageHeading/PageHeading';
1919
import Heading from 'components/common/heading/Heading.styled';
2020
import { useConnects, useCreateConnector } from 'lib/hooks/api/kafkaConnect';
21-
import get from 'lodash/get';
2221
import { Connect } from 'generated-sources';
2322

2423
import * as S from './New.styled';
@@ -45,7 +44,7 @@ const New: React.FC = () => {
4544
mode: 'all',
4645
resolver: yupResolver(validationSchema),
4746
defaultValues: {
48-
connectName: get(connects, '0.name', ''),
47+
connectName: connects.length > 0 ? connects[0].name : '',
4948
name: '',
5049
config: '',
5150
},

frontend/src/components/ConsumerGroups/Details/Details.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ClusterContext from 'components/contexts/ClusterContext';
1111
import PageHeading from 'components/common/PageHeading/PageHeading';
1212
import * as Metrics from 'components/common/Metrics';
1313
import { Tag } from 'components/common/Tag/Tag.styled';
14-
import groupBy from 'lodash/groupBy';
14+
import groupBy from 'lib/functions/groupBy';
1515
import { Table } from 'components/common/table/Table/Table.styled';
1616
import getTagColor from 'components/common/Tag/getTagColor';
1717
import { Dropdown } from 'components/common/Dropdown';
@@ -48,7 +48,10 @@ const Details: React.FC = () => {
4848
navigate(clusterConsumerGroupResetRelativePath);
4949
};
5050

51-
const partitionsByTopic = groupBy(consumerGroup.data?.partitions, 'topic');
51+
const partitionsByTopic = groupBy(
52+
consumerGroup.data?.partitions || [],
53+
'topic'
54+
);
5255
const filteredPartitionsByTopic = Object.keys(partitionsByTopic).filter(
5356
(el) => el.includes(searchValue)
5457
);

frontend/src/components/Topics/Topic/Messages/Filters/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Partition, PollingMode, SeekType } from 'generated-sources';
2-
import compact from 'lodash/compact';
32
import { Option } from 'react-multi-select-component';
3+
import compact from 'lib/functions/compact';
44

55
export function isModeOptionWithInput(value: PollingMode) {
66
return (

frontend/src/components/Topics/Topic/SendMessage/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import jsf from 'json-schema-faker';
77
import Ajv, { DefinedError } from 'ajv/dist/2020';
88
import addFormats from 'ajv-formats';
9-
import upperFirst from 'lodash/upperFirst';
109

1110
jsf.option('fillProperties', false);
1211
jsf.option('alwaysFakeOptionals', true);
@@ -53,6 +52,10 @@ export const getSerdeOptions = (items: SerdeDescription[]) => {
5352
}, []);
5453
};
5554

55+
function upperFirst(str: string) {
56+
return str.charAt(0).toUpperCase() + str.slice(1);
57+
}
58+
5659
export const validateBySchema = (
5760
value: string,
5861
schema: string | undefined,

frontend/src/components/common/NewTable/utils/__test__/updateSortingState.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import updateSortingState from 'components/common/NewTable/utils/updateSortingState';
22
import { SortingState } from '@tanstack/react-table';
3-
import compact from 'lodash/compact';
3+
import compact from 'lib/functions/compact';
44

55
const updater = (previousState: SortingState): SortingState => {
66
return compact(

0 commit comments

Comments
 (0)