mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 20:15:53 +08:00
[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
This commit is contained in:
parent
b958a06ba0
commit
ec3eba612c
@ -1,11 +1,11 @@
|
|||||||
.Dropdown-button {
|
.dropdown-button {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.Dropdown-button--dark {
|
.dropdown-button--dark {
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.Dropdown-icon {
|
.dropdown-icon {
|
||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import './DropDown.styles.scss';
|
import './DropDown.styles.scss';
|
||||||
|
|
||||||
import { EllipsisOutlined } from '@ant-design/icons';
|
import { EllipsisOutlined } from '@ant-design/icons';
|
||||||
import { Button, Dropdown, MenuProps, Space } from 'antd';
|
import { Button, Dropdown, MenuProps } from 'antd';
|
||||||
import { useIsDarkMode } from 'hooks/useDarkMode';
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
||||||
|
|
||||||
function DropDown({ element }: { element: JSX.Element[] }): JSX.Element {
|
function DropDown({ element }: { element: JSX.Element[] }): JSX.Element {
|
||||||
@ -15,15 +15,13 @@ function DropDown({ element }: { element: JSX.Element[] }): JSX.Element {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown menu={{ items }} className="Dropdown-container">
|
<Dropdown menu={{ items }}>
|
||||||
<Button
|
<Button
|
||||||
type="link"
|
type="link"
|
||||||
className={!isDarkMode ? 'Dropdown-button--dark' : 'Dropdown-button'}
|
className={!isDarkMode ? 'dropdown-button--dark' : 'dropdown-button'}
|
||||||
onClick={(e): void => e.preventDefault()}
|
onClick={(e): void => e.preventDefault()}
|
||||||
>
|
>
|
||||||
<Space>
|
<EllipsisOutlined className="dropdown-icon" />
|
||||||
<EllipsisOutlined className="Dropdown-icon" />
|
|
||||||
</Space>
|
|
||||||
</Button>
|
</Button>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
);
|
);
|
||||||
|
@ -15,3 +15,11 @@
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.dynamicColumnsTable-items {
|
||||||
|
flex-direction: column;
|
||||||
|
width: auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,11 @@ import { popupContainer } from 'utils/selectPopupContainer';
|
|||||||
|
|
||||||
import ResizeTable from './ResizeTable';
|
import ResizeTable from './ResizeTable';
|
||||||
import { DynamicColumnTableProps } from './types';
|
import { DynamicColumnTableProps } from './types';
|
||||||
import { getVisibleColumns, setVisibleColumns } from './unit';
|
import {
|
||||||
|
getNewColumnData,
|
||||||
|
getVisibleColumns,
|
||||||
|
setVisibleColumns,
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
function DynamicColumnTable({
|
function DynamicColumnTable({
|
||||||
tablesource,
|
tablesource,
|
||||||
@ -51,22 +55,14 @@ function DynamicColumnTable({
|
|||||||
index,
|
index,
|
||||||
checked,
|
checked,
|
||||||
});
|
});
|
||||||
setColumnsData((prevColumns) => {
|
setColumnsData((prevColumns) =>
|
||||||
if (checked && dynamicColumns) {
|
getNewColumnData({
|
||||||
return prevColumns
|
checked,
|
||||||
? [
|
index,
|
||||||
...prevColumns.slice(0, prevColumns.length - 1),
|
prevColumns,
|
||||||
dynamicColumns[index],
|
dynamicColumns,
|
||||||
prevColumns[prevColumns.length - 1],
|
}),
|
||||||
]
|
);
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
return prevColumns && dynamicColumns
|
|
||||||
? prevColumns.filter(
|
|
||||||
(column) => dynamicColumns[index].title !== column.title,
|
|
||||||
)
|
|
||||||
: undefined;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const items: MenuProps['items'] =
|
const items: MenuProps['items'] =
|
||||||
|
@ -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;
|
@ -2,22 +2,15 @@ import { Typography } from 'antd';
|
|||||||
import convertDateToAmAndPm from 'lib/convertDateToAmAndPm';
|
import convertDateToAmAndPm from 'lib/convertDateToAmAndPm';
|
||||||
import getFormattedDate from 'lib/getFormatedDate';
|
import getFormattedDate from 'lib/getFormatedDate';
|
||||||
|
|
||||||
function DateComponent(
|
function Time({ CreatedOrUpdateTime }: DateProps): JSX.Element {
|
||||||
CreatedOrUpdateTime: string | number | Date,
|
|
||||||
): JSX.Element {
|
|
||||||
const time = new Date(CreatedOrUpdateTime);
|
const time = new Date(CreatedOrUpdateTime);
|
||||||
|
|
||||||
const date = getFormattedDate(time);
|
const date = getFormattedDate(time);
|
||||||
|
|
||||||
const timeString = `${date} ${convertDateToAmAndPm(time)}`;
|
const timeString = `${date} ${convertDateToAmAndPm(time)}`;
|
||||||
|
return <Typography>{timeString}</Typography>;
|
||||||
if (CreatedOrUpdateTime === null) {
|
|
||||||
return <Typography> - </Typography>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Typography className="DateComponent-container">{timeString}</Typography>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DateComponent;
|
type DateProps = {
|
||||||
|
CreatedOrUpdateTime: string | number | Date;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Time;
|
@ -30,3 +30,14 @@ export type SetVisibleColumnsProps = {
|
|||||||
tablesource: typeof TableDataSource[keyof typeof TableDataSource];
|
tablesource: typeof TableDataSource[keyof typeof TableDataSource];
|
||||||
dynamicColumns?: ColumnsType<any>;
|
dynamicColumns?: ColumnsType<any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type GetNewColumnDataProps = {
|
||||||
|
prevColumns?: ColumnsType;
|
||||||
|
checked: boolean;
|
||||||
|
dynamicColumns?: ColumnsType<any>;
|
||||||
|
index: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type GetNewColumnDataFunction = (
|
||||||
|
props: GetNewColumnDataProps,
|
||||||
|
) => ColumnsType | undefined;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { DynamicColumnsKey } from './contants';
|
import { DynamicColumnsKey } from './contants';
|
||||||
import {
|
import {
|
||||||
GetVisibleColumnProps,
|
GetNewColumnDataFunction,
|
||||||
GetVisibleColumnsFunction,
|
GetVisibleColumnsFunction,
|
||||||
SetVisibleColumnsProps,
|
SetVisibleColumnsProps,
|
||||||
} from './types';
|
} from './types';
|
||||||
@ -9,7 +9,7 @@ export const getVisibleColumns: GetVisibleColumnsFunction = ({
|
|||||||
tablesource,
|
tablesource,
|
||||||
dynamicColumns,
|
dynamicColumns,
|
||||||
columnsData,
|
columnsData,
|
||||||
}: GetVisibleColumnProps) => {
|
}) => {
|
||||||
let columnVisibilityData: { [key: string]: boolean };
|
let columnVisibilityData: { [key: string]: boolean };
|
||||||
try {
|
try {
|
||||||
const storedData = localStorage.getItem(tablesource);
|
const storedData = localStorage.getItem(tablesource);
|
||||||
@ -55,3 +55,23 @@ export const setVisibleColumns = ({
|
|||||||
console.error(error);
|
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;
|
||||||
|
};
|
@ -1,9 +1,10 @@
|
|||||||
.LabelColumn {
|
.label-column {
|
||||||
.LabelColumn-label-tag {
|
|
||||||
white-space: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
display: flex;
|
||||||
.labelColumn-popover {
|
flex-wrap: wrap;
|
||||||
margin: 0.5rem 0;
|
|
||||||
|
.label-column--tag {
|
||||||
|
white-space: normal;
|
||||||
|
margin: 0.2rem 0.2rem;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,29 +1,21 @@
|
|||||||
import './LabelColumn.styles.scss';
|
import './LabelColumn.styles.scss';
|
||||||
|
|
||||||
import { Popover, Tag, Tooltip } from 'antd';
|
import { Popover, Tag } from 'antd';
|
||||||
import { popupContainer } from 'utils/selectPopupContainer';
|
import { popupContainer } from 'utils/selectPopupContainer';
|
||||||
|
|
||||||
import { LabelColumnProps } from './TableRenderer.types';
|
import { LabelColumnProps } from './TableRenderer.types';
|
||||||
import { getLabelRenderingValue } from './utils';
|
import TagWithToolTip from './TagWithToolTip';
|
||||||
|
|
||||||
function LabelColumn({ labels, value, color }: LabelColumnProps): JSX.Element {
|
function LabelColumn({ labels, value, color }: LabelColumnProps): JSX.Element {
|
||||||
const newLabels = labels.length > 3 ? labels.slice(0, 3) : labels;
|
const newLabels = labels.length > 3 ? labels.slice(0, 3) : labels;
|
||||||
const remainingLabels = labels.length > 3 ? labels.slice(3) : [];
|
const remainingLabels = labels.length > 3 ? labels.slice(3) : [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="LabelColumn">
|
<div className="label-column">
|
||||||
{newLabels.map(
|
{newLabels.map(
|
||||||
(label: string): JSX.Element => {
|
(label: string): JSX.Element => (
|
||||||
const tooltipTitle =
|
<TagWithToolTip key={label} label={label} color={color} value={value} />
|
||||||
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>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)}
|
)}
|
||||||
{remainingLabels.length > 0 && (
|
{remainingLabels.length > 0 && (
|
||||||
<Popover
|
<Popover
|
||||||
@ -33,25 +25,20 @@ function LabelColumn({ labels, value, color }: LabelColumnProps): JSX.Element {
|
|||||||
content={
|
content={
|
||||||
<div>
|
<div>
|
||||||
{labels.map(
|
{labels.map(
|
||||||
(label: string): JSX.Element => {
|
(label: string): JSX.Element => (
|
||||||
const tooltipTitle =
|
<TagWithToolTip
|
||||||
value && value[label] ? `${label}: ${value[label]}` : label;
|
key={label}
|
||||||
return (
|
label={label}
|
||||||
<div className="labelColumn-popover" key={label}>
|
color={color}
|
||||||
<Tooltip title={tooltipTitle}>
|
value={value}
|
||||||
<Tag className="LabelColumn-label-tag" color={color}>
|
/>
|
||||||
{getLabelRenderingValue(label, value && value[label])}
|
),
|
||||||
</Tag>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
trigger="hover"
|
trigger="hover"
|
||||||
>
|
>
|
||||||
<Tag className="LabelColumn-label-tag" color={color}>
|
<Tag className="label-column--tag" color={color}>
|
||||||
+{remainingLabels.length}
|
+{remainingLabels.length}
|
||||||
</Tag>
|
</Tag>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
36
frontend/src/components/TableRenderer/TagWithToolTip.tsx
Normal file
36
frontend/src/components/TableRenderer/TagWithToolTip.tsx
Normal file
@ -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;
|
@ -9,7 +9,7 @@ import {
|
|||||||
TableDataSource,
|
TableDataSource,
|
||||||
} from 'components/ResizeTable/contants';
|
} from 'components/ResizeTable/contants';
|
||||||
import DynamicColumnTable from 'components/ResizeTable/DynamicColumnTable';
|
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 LabelColumn from 'components/TableRenderer/LabelColumn';
|
||||||
import TextToolTip from 'components/TextToolTip';
|
import TextToolTip from 'components/TextToolTip';
|
||||||
import { QueryParams } from 'constants/query';
|
import { QueryParams } from 'constants/query';
|
||||||
@ -149,7 +149,6 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
|
|||||||
width: 80,
|
width: 80,
|
||||||
key: DynamicColumnsKey.CreatedBy,
|
key: DynamicColumnsKey.CreatedBy,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
render: (value): JSX.Element => <div>{value}</div>,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Updated At',
|
title: 'Updated At',
|
||||||
@ -171,7 +170,6 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
|
|||||||
width: 80,
|
width: 80,
|
||||||
key: DynamicColumnsKey.UpdatedBy,
|
key: DynamicColumnsKey.UpdatedBy,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
render: (value): JSX.Element => <div>{value}</div>,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ import { Dashboard } from 'types/api/dashboard/getAll';
|
|||||||
import AppReducer from 'types/reducer/app';
|
import AppReducer from 'types/reducer/app';
|
||||||
import { popupContainer } from 'utils/selectPopupContainer';
|
import { popupContainer } from 'utils/selectPopupContainer';
|
||||||
|
|
||||||
import DateComponent from '../../components/ResizeTable/TableComponent/Date';
|
import DateComponent from '../../components/ResizeTable/TableComponent/DateComponent';
|
||||||
import ImportJSON from './ImportJSON';
|
import ImportJSON from './ImportJSON';
|
||||||
import { ButtonContainer, NewDashboardButton, TableContainer } from './styles';
|
import { ButtonContainer, NewDashboardButton, TableContainer } from './styles';
|
||||||
import DeleteButton from './TableComponents/DeleteButton';
|
import DeleteButton from './TableComponents/DeleteButton';
|
||||||
@ -94,7 +94,6 @@ function ListOfAllDashboard(): JSX.Element {
|
|||||||
dataIndex: 'createdBy',
|
dataIndex: 'createdBy',
|
||||||
width: 30,
|
width: 30,
|
||||||
key: DynamicColumnsKey.CreatedBy,
|
key: DynamicColumnsKey.CreatedBy,
|
||||||
render: (value): JSX.Element => <div>{value}</div>,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Last Updated Time',
|
title: 'Last Updated Time',
|
||||||
@ -114,7 +113,6 @@ function ListOfAllDashboard(): JSX.Element {
|
|||||||
dataIndex: 'lastUpdatedBy',
|
dataIndex: 'lastUpdatedBy',
|
||||||
width: 30,
|
width: 30,
|
||||||
key: DynamicColumnsKey.UpdatedBy,
|
key: DynamicColumnsKey.UpdatedBy,
|
||||||
render: (value): JSX.Element => <div>{value}</div>,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user