|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +import { useMemo } from 'react' |
17 | 18 | import { useHistory } from 'react-router-dom' |
18 | 19 |
|
19 | | -import { useSearchString } from '@devtron-labs/devtron-fe-common-lib' |
| 20 | +import { FiltersTypeEnum, PaginationEnum, Table, useSearchString } from '@devtron-labs/devtron-fe-common-lib' |
20 | 21 |
|
21 | 22 | import { InteractiveCellText } from '@Components/common/helpers/InteractiveCellText/InteractiveCellText' |
22 | | -import { DeleteComponentsName } from '@Config/constantMessaging' |
23 | 23 |
|
24 | | -import { ConfigTableRowActionButton } from './ConfigTableRowActionButton' |
25 | | -import { ConfigurationsTabTypes } from './constants' |
26 | | -import { getConfigTabIcons, renderDefaultTag } from './notifications.util' |
27 | | -import { ConfigurationTableProps } from './types' |
| 24 | +import { ConfigurationRowActionButtonWrapper } from './ConfigTableRowActionButton' |
| 25 | +import { BASE_CONFIG, ConfigurationsTabTypes, SMTP_TABLE_COLUMNS } from './constants' |
| 26 | +import { renderDefaultTag } from './notifications.util' |
| 27 | +import { ConfigurationTableProps, SMTPConfigurationTableRowType } from './types' |
28 | 28 |
|
29 | 29 | export const SMTPConfigurationTable = ({ state, deleteClickHandler }: ConfigurationTableProps) => { |
30 | 30 | const { smtpConfigurationList } = state |
31 | 31 | const { searchParams } = useSearchString() |
32 | 32 | const history = useHistory() |
33 | 33 |
|
34 | | - const onClickEditRow = (configId) => () => { |
| 34 | + const onClickEditRow = (id: number) => () => { |
35 | 35 | const newParams = { |
36 | 36 | ...searchParams, |
37 | | - configId: configId.toString(), |
| 37 | + configId: id.toString(), |
38 | 38 | modal: ConfigurationsTabTypes.SMTP, |
39 | 39 | } |
40 | 40 | history.push({ |
41 | 41 | search: new URLSearchParams(newParams).toString(), |
42 | 42 | }) |
43 | 43 | } |
44 | 44 |
|
45 | | - return ( |
46 | | - <div className="smtp-config-container flex-grow-1"> |
47 | | - <div className="smtp-config-grid fs-12 fw-6 dc__uppercase cn-7 py-6 dc__gap-16 dc__border-bottom-n1 px-20 dc__position-sticky dc__top-0 bg__primary"> |
48 | | - <p className="icon-dim-24 m-0" /> |
49 | | - <p className="dc__truncate-text flex left m-0">Name</p> |
50 | | - <p className="dc__truncate-text flex left m-0">Host</p> |
51 | | - <p className="dc__truncate-text flex left m-0">Port</p> |
52 | | - <p className="dc__truncate-text flex left m-0">Sender' Email</p> |
53 | | - <p className="" aria-label="Action" /> |
54 | | - </div> |
55 | | - <div className="flex-grow-1"> |
56 | | - {smtpConfigurationList.map((smtpConfig) => ( |
57 | | - <div |
58 | | - data-testid={`smtp-container-${smtpConfig.name}`} |
59 | | - key={smtpConfig.id} |
60 | | - className="configuration-tab__table-row smtp-config-grid dc__gap-16 py-6 px-20 dc__hover-n50 h-100 dc__visible-hover dc__visible-hover--parent" |
61 | | - > |
62 | | - {getConfigTabIcons(ConfigurationsTabTypes.SMTP)} |
63 | | - <div |
64 | | - data-testid={`smtp-config-name-${smtpConfig.name}`} |
65 | | - className=" dc__truncate-text flexbox dc__gap-8" |
66 | | - > |
| 45 | + const tableRows = useMemo( |
| 46 | + () => |
| 47 | + smtpConfigurationList.map((smtpConfig) => ({ |
| 48 | + id: `${smtpConfig.id}`, |
| 49 | + data: { |
| 50 | + name: ( |
| 51 | + <div className="flex left dc__gap-8 py-10"> |
67 | 52 | <InteractiveCellText |
68 | 53 | text={smtpConfig.name} |
69 | 54 | onClickHandler={onClickEditRow(smtpConfig.id)} |
70 | 55 | /> |
71 | 56 | {renderDefaultTag(smtpConfig.isDefault)} |
72 | 57 | </div> |
73 | | - <InteractiveCellText |
74 | | - text={smtpConfig.host} |
75 | | - dataTestId={`smtp-config-host-${smtpConfig.host}`} |
76 | | - /> |
77 | | - <InteractiveCellText text={smtpConfig.port} /> |
78 | | - <InteractiveCellText text={smtpConfig.email} /> |
79 | | - <ConfigTableRowActionButton |
80 | | - onClickEditRow={onClickEditRow(smtpConfig.id)} |
81 | | - onClickDeleteRow={deleteClickHandler( |
82 | | - smtpConfig.id, |
83 | | - DeleteComponentsName.SMTPConfigurationTab, |
84 | | - )} |
85 | | - modal={ConfigurationsTabTypes.SMTP} |
86 | | - /> |
87 | | - </div> |
88 | | - ))} |
89 | | - </div> |
90 | | - </div> |
| 58 | + ), |
| 59 | + host: smtpConfig.host, |
| 60 | + port: smtpConfig.port.toString(), |
| 61 | + email: smtpConfig.email, |
| 62 | + }, |
| 63 | + })), |
| 64 | + [smtpConfigurationList], |
| 65 | + ) |
| 66 | + |
| 67 | + const onRowClick = (rowData) => { |
| 68 | + onClickEditRow(Number(rowData.id))() |
| 69 | + } |
| 70 | + |
| 71 | + return ( |
| 72 | + <Table<SMTPConfigurationTableRowType, FiltersTypeEnum.STATE> |
| 73 | + id="table__smtp-configuration" |
| 74 | + columns={SMTP_TABLE_COLUMNS} |
| 75 | + rows={tableRows} |
| 76 | + emptyStateConfig={{ |
| 77 | + noRowsConfig: { |
| 78 | + title: 'No SMTP Configurations Found', |
| 79 | + }, |
| 80 | + }} |
| 81 | + filtersVariant={FiltersTypeEnum.STATE} |
| 82 | + additionalFilterProps={{ |
| 83 | + initialSortKey: BASE_CONFIG[0].field, |
| 84 | + }} |
| 85 | + paginationVariant={PaginationEnum.NOT_PAGINATED} |
| 86 | + filter={null} |
| 87 | + rowStartIconConfig={{ |
| 88 | + name: 'ic-smtp', |
| 89 | + color: null, |
| 90 | + size: 24, |
| 91 | + }} |
| 92 | + rowActionOnHoverConfig={{ |
| 93 | + width: 100, |
| 94 | + Component: ConfigurationRowActionButtonWrapper, |
| 95 | + }} |
| 96 | + additionalProps={{ deleteClickHandler, modal: ConfigurationsTabTypes.SMTP }} |
| 97 | + onRowClick={onRowClick} |
| 98 | + /> |
91 | 99 | ) |
92 | 100 | } |
0 commit comments