Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor]: Dynamic Columns PR #3852

Merged
merged 25 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ae5f98e
fix: remove the space and fix the classname
Oct 29, 2023
9d5dd81
refactor: made the dynamicColumnsTable-items responsive
Oct 29, 2023
8c0326b
fix: setcolumndata to a separate function
Oct 29, 2023
7b3ea93
fix: handle invalid CreatedOrUpdateTime
Oct 29, 2023
a789170
fix: hyphenate classname and bme
Oct 29, 2023
ae7c545
refactor: move the implementation to separate component
Oct 29, 2023
7defe6f
refactor: removed the bydefault render
Oct 29, 2023
c340d62
refactor: remove render
Oct 29, 2023
eba975b
Merge branch 'develop' into PRD-alertlist-refactor
Oct 31, 2023
7557af2
Merge branch 'develop' into PRD-alertlist-refactor
Nov 1, 2023
3ef3cb7
refactor: removed unwanted imports
Nov 1, 2023
c962889
Merge branch 'develop' into PRD-alertlist-refactor
Nov 1, 2023
5e9783e
fix: remove the space and fix the classname
Oct 29, 2023
55cd656
refactor: made the dynamicColumnsTable-items responsive
Oct 29, 2023
bd6ebdf
fix: setcolumndata to a separate function
Oct 29, 2023
12a4a83
fix: handle invalid CreatedOrUpdateTime
Oct 29, 2023
30fa79c
fix: hyphenate classname and bme
Oct 29, 2023
a9c9f58
refactor: move the implementation to separate component
Oct 29, 2023
2fbbb47
refactor: removed the bydefault render
Oct 29, 2023
62c7745
refactor: remove render
Oct 29, 2023
245b717
Merge branch 'PRD-alertlist-refactor' of https://github.com/SigNoz/si…
Nov 1, 2023
501fc54
fix: the classname
Nov 1, 2023
5a6f57d
Merge branch 'develop' into PRD-alertlist-refactor
Nov 1, 2023
269e02a
Merge branch 'develop' into PRD-alertlist-refactor
Nov 1, 2023
27e7ea2
Merge branch 'develop' into PRD-alertlist-refactor
Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/src/components/DropDown/DropDown.styles.scss
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 4 additions & 6 deletions frontend/src/components/DropDown/DropDown.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,15 +15,13 @@ function DropDown({ element }: { element: JSX.Element[] }): JSX.Element {
);

return (
<Dropdown menu={{ items }} className="Dropdown-container">
<Dropdown menu={{ items }}>
<Button
type="link"
className={!isDarkMode ? 'Dropdown-button--dark' : 'Dropdown-button'}
className={!isDarkMode ? 'dropdown-button--dark' : 'dropdown-button'}
onClick={(e): void => e.preventDefault()}
>
<Space>
<EllipsisOutlined className="Dropdown-icon" />
</Space>
<EllipsisOutlined className="dropdown-icon" />
</Button>
</Dropdown>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
30 changes: 13 additions & 17 deletions frontend/src/components/ResizeTable/DynamicColumnTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'] =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Typography } from 'antd';

import Time from './Time';

function DateComponent(
CreatedOrUpdateTime: string | number | Date,
): JSX.Element {
if (CreatedOrUpdateTime === null) {
return <Typography> - </Typography>;
}

return <Time CreatedOrUpdateTime={CreatedOrUpdateTime} />;
}

export default DateComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ import { Typography } from 'antd';
import convertDateToAmAndPm from 'lib/convertDateToAmAndPm';
import getFormattedDate from 'lib/getFormatedDate';

function DateComponent(
CreatedOrUpdateTime: string | number | Date,
): JSX.Element {
function Time({ CreatedOrUpdateTime }: DateProps): JSX.Element {
const time = new Date(CreatedOrUpdateTime);

const date = getFormattedDate(time);

const timeString = `${date} ${convertDateToAmAndPm(time)}`;

if (CreatedOrUpdateTime === null) {
return <Typography> - </Typography>;
}

return (
<Typography className="DateComponent-container">{timeString}</Typography>
);
return <Typography>{timeString}</Typography>;
}

export default DateComponent;
type DateProps = {
CreatedOrUpdateTime: string | number | Date;
};

export default Time;
11 changes: 11 additions & 0 deletions frontend/src/components/ResizeTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ export type SetVisibleColumnsProps = {
tablesource: typeof TableDataSource[keyof typeof TableDataSource];
dynamicColumns?: ColumnsType<any>;
};

type GetNewColumnDataProps = {
prevColumns?: ColumnsType;
checked: boolean;
dynamicColumns?: ColumnsType<any>;
index: number;
};

export type GetNewColumnDataFunction = (
props: GetNewColumnDataProps,
) => ColumnsType | undefined;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DynamicColumnsKey } from './contants';
import {
GetVisibleColumnProps,
GetNewColumnDataFunction,
GetVisibleColumnsFunction,
SetVisibleColumnsProps,
} from './types';
Expand All @@ -9,7 +9,7 @@ export const getVisibleColumns: GetVisibleColumnsFunction = ({
tablesource,
dynamicColumns,
columnsData,
}: GetVisibleColumnProps) => {
}) => {
let columnVisibilityData: { [key: string]: boolean };
try {
const storedData = localStorage.getItem(tablesource);
Expand Down Expand Up @@ -55,3 +55,23 @@ export const setVisibleColumns = ({
console.error(error);
}
};

export const getNewColumnData: GetNewColumnDataFunction = ({
prevColumns,
checked,
dynamicColumns,
index,
}) => {
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;
};
13 changes: 7 additions & 6 deletions frontend/src/components/TableRenderer/LabelColumn.styles.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.LabelColumn {
.LabelColumn-label-tag {
.label-column {

display: flex;
flex-wrap: wrap;

.label-column--tag {
white-space: normal;
margin: 0.2rem 0.2rem;
}

}
.labelColumn-popover {
margin: 0.5rem 0;
}
43 changes: 15 additions & 28 deletions frontend/src/components/TableRenderer/LabelColumn.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import './LabelColumn.styles.scss';

import { Popover, Tag, Tooltip } from 'antd';
import { Popover, Tag } from 'antd';
import { popupContainer } from 'utils/selectPopupContainer';

import { LabelColumnProps } from './TableRenderer.types';
import { getLabelRenderingValue } from './utils';
import TagWithToolTip from './TagWithToolTip';

function LabelColumn({ labels, value, color }: LabelColumnProps): JSX.Element {
const newLabels = labels.length > 3 ? labels.slice(0, 3) : labels;
const remainingLabels = labels.length > 3 ? labels.slice(3) : [];

return (
<div className="LabelColumn">
<div className="label-column">
{newLabels.map(
(label: string): JSX.Element => {
const tooltipTitle =
value && value[label] ? `${label}: ${value[label]}` : label;
return (
<Tooltip title={tooltipTitle} key={label}>
<Tag className="LabelColumn-label-tag" color={color}>
{getLabelRenderingValue(label, value && value[label])}
</Tag>
</Tooltip>
);
},
(label: string): JSX.Element => (
<TagWithToolTip key={label} label={label} color={color} value={value} />
),
)}
{remainingLabels.length > 0 && (
<Popover
Expand All @@ -33,25 +25,20 @@ function LabelColumn({ labels, value, color }: LabelColumnProps): JSX.Element {
content={
<div>
{labels.map(
(label: string): JSX.Element => {
const tooltipTitle =
value && value[label] ? `${label}: ${value[label]}` : label;
return (
<div className="labelColumn-popover" key={label}>
<Tooltip title={tooltipTitle}>
<Tag className="LabelColumn-label-tag" color={color}>
{getLabelRenderingValue(label, value && value[label])}
</Tag>
</Tooltip>
</div>
);
},
(label: string): JSX.Element => (
<TagWithToolTip
key={label}
label={label}
color={color}
value={value}
/>
),
)}
</div>
}
trigger="hover"
>
<Tag className="LabelColumn-label-tag" color={color}>
<Tag className="label-column--tag" color={color}>
+{remainingLabels.length}
</Tag>
</Popover>
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/components/TableRenderer/TagWithToolTip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Tag, Tooltip } from 'antd';

import { getLabelRenderingValue } from './utils';

function TagWithToolTip({
label,
value,
color,
}: TagWithToolTipProps): JSX.Element {
const tooltipTitle =
value && value[label] ? `${label}: ${value[label]}` : label;
return (
<div key={label}>
<Tooltip title={tooltipTitle}>
<Tag className="label-column--tag" color={color}>
{getLabelRenderingValue(label, value && value[label])}
</Tag>
</Tooltip>
</div>
);
}

type TagWithToolTipProps = {
label: string;
color?: string;
value?: {
[key: string]: string;
};
};

TagWithToolTip.defaultProps = {
value: undefined,
color: undefined,
};

export default TagWithToolTip;
4 changes: 1 addition & 3 deletions frontend/src/container/ListAlertRules/ListAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TableDataSource,
} from 'components/ResizeTable/contants';
import DynamicColumnTable from 'components/ResizeTable/DynamicColumnTable';
import DateComponent from 'components/ResizeTable/TableComponent/Date';
import DateComponent from 'components/ResizeTable/TableComponent/DateComponent';
import LabelColumn from 'components/TableRenderer/LabelColumn';
import TextToolTip from 'components/TextToolTip';
import { QueryParams } from 'constants/query';
Expand Down Expand Up @@ -149,7 +149,6 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
width: 80,
key: DynamicColumnsKey.CreatedBy,
align: 'center',
render: (value): JSX.Element => <div>{value}</div>,
},
{
title: 'Updated At',
Expand All @@ -171,7 +170,6 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
width: 80,
key: DynamicColumnsKey.UpdatedBy,
align: 'center',
render: (value): JSX.Element => <div>{value}</div>,
},
];

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/container/ListOfDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { Dashboard } from 'types/api/dashboard/getAll';
import AppReducer from 'types/reducer/app';
import { popupContainer } from 'utils/selectPopupContainer';

import DateComponent from '../../components/ResizeTable/TableComponent/Date';
import DateComponent from '../../components/ResizeTable/TableComponent/DateComponent';
import ImportJSON from './ImportJSON';
import { ButtonContainer, NewDashboardButton, TableContainer } from './styles';
import DeleteButton from './TableComponents/DeleteButton';
Expand Down Expand Up @@ -94,7 +94,6 @@ function ListOfAllDashboard(): JSX.Element {
dataIndex: 'createdBy',
width: 30,
key: DynamicColumnsKey.CreatedBy,
render: (value): JSX.Element => <div>{value}</div>,
},
{
title: 'Last Updated Time',
Expand All @@ -114,7 +113,6 @@ function ListOfAllDashboard(): JSX.Element {
dataIndex: 'lastUpdatedBy',
width: 30,
key: DynamicColumnsKey.UpdatedBy,
render: (value): JSX.Element => <div>{value}</div>,
},
];

Expand Down