From ec3eba612c9e78572099ec9290e5962313cd9811 Mon Sep 17 00:00:00 2001 From: Rajat Dabade Date: Wed, 1 Nov 2023 18:26:41 +0530 Subject: [PATCH] [Refactor]: Dynamic Columns PR (#3852) * fix: remove the space and fix the classname * refactor: made the dynamicColumnsTable-items responsive * fix: setcolumndata to a separate function * fix: handle invalid CreatedOrUpdateTime * fix: hyphenate classname and bme * refactor: move the implementation to separate component * refactor: removed the bydefault render * refactor: remove render * refactor: removed unwanted imports * fix: remove the space and fix the classname * refactor: made the dynamicColumnsTable-items responsive * fix: setcolumndata to a separate function * fix: handle invalid CreatedOrUpdateTime * fix: hyphenate classname and bme * refactor: move the implementation to separate component * refactor: removed the bydefault render * refactor: remove render * fix: the classname --- .../components/DropDown/DropDown.styles.scss | 6 +-- frontend/src/components/DropDown/DropDown.tsx | 10 ++--- .../ResizeTable/DynamicColumnTable.syles.scss | 8 ++++ .../ResizeTable/DynamicColumnTable.tsx | 30 ++++++------- .../TableComponent/DateComponent.tsx | 15 +++++++ .../TableComponent/{Date.tsx => Time.tsx} | 21 +++------ frontend/src/components/ResizeTable/types.ts | 11 +++++ .../ResizeTable/{unit.ts => utils.ts} | 24 ++++++++++- .../TableRenderer/LabelColumn.styles.scss | 15 ++++--- .../components/TableRenderer/LabelColumn.tsx | 43 +++++++------------ .../TableRenderer/TagWithToolTip.tsx | 36 ++++++++++++++++ .../container/ListAlertRules/ListAlert.tsx | 4 +- .../src/container/ListOfDashboard/index.tsx | 4 +- 13 files changed, 144 insertions(+), 83 deletions(-) create mode 100644 frontend/src/components/ResizeTable/TableComponent/DateComponent.tsx rename frontend/src/components/ResizeTable/TableComponent/{Date.tsx => Time.tsx} (50%) rename frontend/src/components/ResizeTable/{unit.ts => utils.ts} (74%) create mode 100644 frontend/src/components/TableRenderer/TagWithToolTip.tsx diff --git a/frontend/src/components/DropDown/DropDown.styles.scss b/frontend/src/components/DropDown/DropDown.styles.scss index 3527c1385a..232b349545 100644 --- a/frontend/src/components/DropDown/DropDown.styles.scss +++ b/frontend/src/components/DropDown/DropDown.styles.scss @@ -1,11 +1,11 @@ -.Dropdown-button { +.dropdown-button { color: #fff; } -.Dropdown-button--dark { +.dropdown-button--dark { color: #000; } -.Dropdown-icon { +.dropdown-icon { font-size: 1.2rem; } \ No newline at end of file diff --git a/frontend/src/components/DropDown/DropDown.tsx b/frontend/src/components/DropDown/DropDown.tsx index c76ff8daec..c29fbdd15b 100644 --- a/frontend/src/components/DropDown/DropDown.tsx +++ b/frontend/src/components/DropDown/DropDown.tsx @@ -1,7 +1,7 @@ import './DropDown.styles.scss'; import { EllipsisOutlined } from '@ant-design/icons'; -import { Button, Dropdown, MenuProps, Space } from 'antd'; +import { Button, Dropdown, MenuProps } from 'antd'; import { useIsDarkMode } from 'hooks/useDarkMode'; function DropDown({ element }: { element: JSX.Element[] }): JSX.Element { @@ -15,15 +15,13 @@ function DropDown({ element }: { element: JSX.Element[] }): JSX.Element { ); return ( - + ); diff --git a/frontend/src/components/ResizeTable/DynamicColumnTable.syles.scss b/frontend/src/components/ResizeTable/DynamicColumnTable.syles.scss index 30bccd87e3..2bd0606abd 100644 --- a/frontend/src/components/ResizeTable/DynamicColumnTable.syles.scss +++ b/frontend/src/components/ResizeTable/DynamicColumnTable.syles.scss @@ -14,4 +14,12 @@ width: 10.625rem; justify-content: space-between; align-items: center; +} + +@media (max-width: 768px) { + .dynamicColumnsTable-items { + flex-direction: column; + width: auto; + text-align: center; + } } \ No newline at end of file diff --git a/frontend/src/components/ResizeTable/DynamicColumnTable.tsx b/frontend/src/components/ResizeTable/DynamicColumnTable.tsx index 93e3673743..385734f11d 100644 --- a/frontend/src/components/ResizeTable/DynamicColumnTable.tsx +++ b/frontend/src/components/ResizeTable/DynamicColumnTable.tsx @@ -9,7 +9,11 @@ import { popupContainer } from 'utils/selectPopupContainer'; import ResizeTable from './ResizeTable'; import { DynamicColumnTableProps } from './types'; -import { getVisibleColumns, setVisibleColumns } from './unit'; +import { + getNewColumnData, + getVisibleColumns, + setVisibleColumns, +} from './utils'; function DynamicColumnTable({ tablesource, @@ -51,22 +55,14 @@ function DynamicColumnTable({ index, checked, }); - setColumnsData((prevColumns) => { - if (checked && dynamicColumns) { - return prevColumns - ? [ - ...prevColumns.slice(0, prevColumns.length - 1), - dynamicColumns[index], - prevColumns[prevColumns.length - 1], - ] - : undefined; - } - return prevColumns && dynamicColumns - ? prevColumns.filter( - (column) => dynamicColumns[index].title !== column.title, - ) - : undefined; - }); + setColumnsData((prevColumns) => + getNewColumnData({ + checked, + index, + prevColumns, + dynamicColumns, + }), + ); }; const items: MenuProps['items'] = diff --git a/frontend/src/components/ResizeTable/TableComponent/DateComponent.tsx b/frontend/src/components/ResizeTable/TableComponent/DateComponent.tsx new file mode 100644 index 0000000000..87c5c57420 --- /dev/null +++ b/frontend/src/components/ResizeTable/TableComponent/DateComponent.tsx @@ -0,0 +1,15 @@ +import { Typography } from 'antd'; + +import Time from './Time'; + +function DateComponent( + CreatedOrUpdateTime: string | number | Date, +): JSX.Element { + if (CreatedOrUpdateTime === null) { + return - ; + } + + return