2023-11-01 17:53:31 +05:30
|
|
|
import './QueryTable.styles.scss';
|
|
|
|
|
|
2023-06-23 10:15:09 +03:00
|
|
|
import { ResizeTable } from 'components/ResizeTable';
|
2023-11-01 17:53:31 +05:30
|
|
|
import Download from 'container/Download/Download';
|
|
|
|
|
import { IServiceName } from 'container/MetricsApplication/Tabs/types';
|
2023-07-06 17:32:21 +03:00
|
|
|
import { createTableColumnsFromQuery } from 'lib/query/createTableColumnsFromQuery';
|
2023-06-23 10:15:09 +03:00
|
|
|
import { useMemo } from 'react';
|
2023-11-01 17:53:31 +05:30
|
|
|
import { useParams } from 'react-router-dom';
|
2023-06-23 10:15:09 +03:00
|
|
|
|
|
|
|
|
import { QueryTableProps } from './QueryTable.intefaces';
|
2023-11-01 17:53:31 +05:30
|
|
|
import { createDownloadableData } from './utils';
|
2023-06-23 10:15:09 +03:00
|
|
|
|
|
|
|
|
export function QueryTable({
|
|
|
|
|
queryTableData,
|
|
|
|
|
query,
|
|
|
|
|
renderActionCell,
|
2023-07-04 08:24:34 +03:00
|
|
|
modifyColumns,
|
2023-07-25 15:45:51 +05:30
|
|
|
renderColumnCell,
|
2023-11-01 17:53:31 +05:30
|
|
|
downloadOption,
|
2023-11-23 15:32:06 +05:30
|
|
|
columns,
|
|
|
|
|
dataSource,
|
2023-06-23 10:15:09 +03:00
|
|
|
...props
|
|
|
|
|
}: QueryTableProps): JSX.Element {
|
2023-11-01 17:53:31 +05:30
|
|
|
const { isDownloadEnabled = false, fileName = '' } = downloadOption || {};
|
|
|
|
|
const { servicename } = useParams<IServiceName>();
|
|
|
|
|
const { loading } = props;
|
2023-11-23 15:32:06 +05:30
|
|
|
const { columns: newColumns, dataSource: newDataSource } = useMemo(() => {
|
|
|
|
|
if (columns && dataSource) {
|
|
|
|
|
return { columns, dataSource };
|
|
|
|
|
}
|
|
|
|
|
return createTableColumnsFromQuery({
|
|
|
|
|
query,
|
|
|
|
|
queryTableData,
|
|
|
|
|
renderActionCell,
|
|
|
|
|
renderColumnCell,
|
|
|
|
|
});
|
|
|
|
|
}, [
|
|
|
|
|
columns,
|
|
|
|
|
dataSource,
|
|
|
|
|
query,
|
|
|
|
|
queryTableData,
|
|
|
|
|
renderActionCell,
|
|
|
|
|
renderColumnCell,
|
|
|
|
|
]);
|
2023-06-23 10:15:09 +03:00
|
|
|
|
2023-11-23 15:32:06 +05:30
|
|
|
const downloadableData = createDownloadableData(newDataSource);
|
2023-11-01 17:53:31 +05:30
|
|
|
|
2023-11-23 15:32:06 +05:30
|
|
|
const tableColumns = modifyColumns ? modifyColumns(newColumns) : newColumns;
|
2023-07-04 08:24:34 +03:00
|
|
|
|
2023-06-23 10:15:09 +03:00
|
|
|
return (
|
2023-11-01 17:53:31 +05:30
|
|
|
<div className="query-table">
|
|
|
|
|
{isDownloadEnabled && (
|
|
|
|
|
<div className="query-table--download">
|
|
|
|
|
<Download
|
|
|
|
|
data={downloadableData}
|
|
|
|
|
fileName={`${fileName}-${servicename}`}
|
|
|
|
|
isLoading={loading as boolean}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<ResizeTable
|
|
|
|
|
columns={tableColumns}
|
|
|
|
|
tableLayout="fixed"
|
|
|
|
|
dataSource={dataSource}
|
|
|
|
|
scroll={{ x: true }}
|
|
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2023-06-23 10:15:09 +03:00
|
|
|
);
|
|
|
|
|
}
|