Repository: provectus/kafka-ui
Issue: Migrate Topic Settings page to the new version of table component
Labels: scope/frontend
type/refactoring
status/accepted


### Describe the solution you'd like
Migrate `src/components/Topics/Topic/Settings/Settings.tsx` to new version of tables  `src/components/common/NewTable/Table.tsx`

### Additional context
Topics -> Topic -> Settings




Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Settings/ConfigListItem.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Settings/ConfigListItem.tsx
deleted file mode 100644
index cc0b36caa05..00000000000
--- a/kafka-ui-react-app/src/components/Topics/Topic/Settings/ConfigListItem.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { TopicConfig } from 'generated-sources';
-import React from 'react';
-
-import * as S from './Settings.styled';
-
-export interface ListItemProps {
-  config: TopicConfig;
-}
-
-const ConfigListItem: React.FC<ListItemProps> = ({
-  config: { name, value, defaultValue },
-}) => {
-  const hasCustomValue = !!defaultValue && value !== defaultValue;
-
-  return (
-    <S.Row $hasCustomValue={hasCustomValue}>
-      <td>{name}</td>
-      <td>{value}</td>
-      <td title="Default Value">{hasCustomValue && defaultValue}</td>
-    </S.Row>
-  );
-};
-
-export default ConfigListItem;
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Settings/Settings.styled.ts b/kafka-ui-react-app/src/components/Topics/Topic/Settings/Settings.styled.ts
index 30aa0f2afe6..e11a2ba80b4 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/Settings/Settings.styled.ts
+++ b/kafka-ui-react-app/src/components/Topics/Topic/Settings/Settings.styled.ts
@@ -1,13 +1,14 @@
 import styled, { css } from 'styled-components';
 
-export const Row = styled.tr<{ $hasCustomValue?: boolean }>(
-  ({ theme, $hasCustomValue }) => css`
-    & > td {
-      font-weight: ${$hasCustomValue ? 500 : 400};
-      &:last-child {
-        color: ${theme.configList.color};
-        font-weight: 400;
-      }
-    }
+export const Value = styled.span<{ $hasCustomValue?: boolean }>(
+  ({ $hasCustomValue }) => css`
+    font-weight: ${$hasCustomValue ? 500 : 400};
+  `
+);
+
+export const DefaultValue = styled.span(
+  ({ theme }) => css`
+    color: ${theme.configList.color};
+    font-weight: 400;
   `
 );
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Settings/Settings.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Settings/Settings.tsx
index d7b553af9d5..001fc2c0090 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/Settings/Settings.tsx
+++ b/kafka-ui-react-app/src/components/Topics/Topic/Settings/Settings.tsx
@@ -1,31 +1,62 @@
 import React from 'react';
-import { Table } from 'components/common/table/Table/Table.styled';
-import TableHeaderCell from 'components/common/table/TableHeaderCell/TableHeaderCell';
+import Table from 'components/common/NewTable';
 import { RouteParamsClusterTopic } from 'lib/paths';
 import useAppParams from 'lib/hooks/useAppParams';
 import { useTopicConfig } from 'lib/hooks/api/topics';
+import { CellContext, ColumnDef } from '@tanstack/react-table';
+import { TopicConfig } from 'generated-sources';
 
-import ConfigListItem from './ConfigListItem';
+import * as S from './Settings.styled';
+
+const ValueCell: React.FC<CellContext<TopicConfig, unknown>> = ({
+  row,
+  renderValue,
+}) => {
+  const { defaultValue } = row.original;
+  const { value } = row.original;
+  const hasCustomValue = !!defaultValue && value !== defaultValue;
+
+  return (
+    <S.Value $hasCustomValue={hasCustomValue}>{renderValue<string>()}</S.Value>
+  );
+};
+
+const DefaultValueCell: React.FC<CellContext<TopicConfig, unknown>> = ({
+  row,
+  getValue,
+}) => {
+  const defaultValue = getValue<TopicConfig['defaultValue']>();
+  const { value } = row.original;
+  const hasCustomValue = !!defaultValue && value !== defaultValue;
+  return <S.DefaultValue>{hasCustomValue && defaultValue}</S.DefaultValue>;
+};
 
 const Settings: React.FC = () => {
   const props = useAppParams<RouteParamsClusterTopic>();
-  const { data } = useTopicConfig(props);
-  return (
-    <Table isFullwidth>
-      <thead>
-        <tr>
-          <TableHeaderCell title="Key" />
-          <TableHeaderCell title="Value" />
-          <TableHeaderCell title="Default Value" />
-        </tr>
-      </thead>
-      <tbody>
-        {data?.map((item) => (
-          <ConfigListItem key={item.name} config={item} />
-        ))}
-      </tbody>
-    </Table>
+  const { data = [] } = useTopicConfig(props);
+
+  const columns = React.useMemo<ColumnDef<TopicConfig>[]>(
+    () => [
+      {
+        header: 'Key',
+        accessorKey: 'name',
+        cell: ValueCell,
+      },
+      {
+        header: 'Value',
+        accessorKey: 'value',
+        cell: ValueCell,
+      },
+      {
+        header: 'Default Value',
+        accessorKey: 'defaultValue',
+        cell: DefaultValueCell,
+      },
+    ],
+    []
   );
+
+  return <Table columns={columns} data={data} />;
 };
 
 export default Settings;
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Settings/__test__/ConfigListItem.spec.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Settings/__test__/ConfigListItem.spec.tsx
deleted file mode 100644
index b363ff55337..00000000000
--- a/kafka-ui-react-app/src/components/Topics/Topic/Settings/__test__/ConfigListItem.spec.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-import React from 'react';
-import { render } from 'lib/testHelpers';
-import { screen } from '@testing-library/react';
-import ConfigListItem, {
-  ListItemProps,
-} from 'components/Topics/Topic/Settings/ConfigListItem';
-
-const setupComponent = (props: ListItemProps) => {
-  render(
-    <table>
-      <tbody>
-        <ConfigListItem {...props} />
-      </tbody>
-    </table>
-  );
-};
-
-const getName = () => screen.getByText('someName');
-const getValue = () => screen.getByText('someValue');
-
-it('renders with CustomValue', () => {
-  setupComponent({
-    config: {
-      name: 'someName',
-      value: 'someValue',
-      defaultValue: 'someDefaultValue',
-    },
-  });
-  expect(getName()).toBeInTheDocument();
-  expect(getName()).toHaveStyle('font-weight: 500');
-  expect(getValue()).toBeInTheDocument();
-  expect(getValue()).toHaveStyle('font-weight: 500');
-  expect(screen.getByText('someDefaultValue')).toBeInTheDocument();
-});
-
-it('renders without CustomValue', () => {
-  setupComponent({
-    config: { name: 'someName', value: 'someValue', defaultValue: 'someValue' },
-  });
-  expect(getName()).toBeInTheDocument();
-  expect(getName()).toHaveStyle('font-weight: 400');
-  expect(getValue()).toBeInTheDocument();
-  expect(getValue()).toHaveStyle('font-weight: 400');
-  expect(screen.getByTitle('Default Value')).toHaveTextContent('');
-});
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Settings/__test__/Settings.spec.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Settings/__test__/Settings.spec.tsx
index cf5236ffa15..c2aa9a93e5d 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/Settings/__test__/Settings.spec.tsx
+++ b/kafka-ui-react-app/src/components/Topics/Topic/Settings/__test__/Settings.spec.tsx
@@ -13,11 +13,8 @@ jest.mock('lib/hooks/api/topics', () => ({
   useTopicConfig: jest.fn(),
 }));
 
-jest.mock('components/Topics/Topic/Settings/ConfigListItem', () => () => (
-  <tr>
-    <td>ConfigListItemMock</td>
-  </tr>
-));
+const getName = () => screen.getByText('compression.type');
+const getValue = () => screen.getByText('producer');
 
 describe('Settings', () => {
   const renderComponent = () => {
@@ -37,9 +34,10 @@ describe('Settings', () => {
     renderComponent();
   });
 
-  it('should check it returns null if no config is passed', () => {
-    expect(screen.getByRole('table')).toBeInTheDocument();
-    const items = screen.getAllByText('ConfigListItemMock');
-    expect(items.length).toEqual(topicConfigPayload.length);
+  it('renders without CustomValue', () => {
+    expect(getName()).toBeInTheDocument();
+    expect(getName()).toHaveStyle('font-weight: 400');
+    expect(getValue()).toBeInTheDocument();
+    expect(getValue()).toHaveStyle('font-weight: 400');
   });
 });


Test patch: