mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-18 16:07:10 +00:00
* feat: removed ellipsis prop * feat: prevent unnecessary save calls * feat: fix dashboard detail resize icon * feat: adjusted resizable header - set minConstraint * feat: fixed dashboard vanishing issue * feat: removed dependency causing maximum callstack warning * feat: corrected the list edit view render issue and resize handler fix * feat: style fix * feat: removed comments * fix: updated test cases * feat: updated the test cases --------- Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
110 lines
2.7 KiB
TypeScript
110 lines
2.7 KiB
TypeScript
import './QueryTable.styles.scss';
|
|
|
|
import { ResizeTable } from 'components/ResizeTable';
|
|
import Download from 'container/Download/Download';
|
|
import { IServiceName } from 'container/MetricsApplication/Tabs/types';
|
|
import {
|
|
createTableColumnsFromQuery,
|
|
RowData,
|
|
} from 'lib/query/createTableColumnsFromQuery';
|
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
import { useParams } from 'react-router-dom';
|
|
|
|
import { QueryTableProps } from './QueryTable.intefaces';
|
|
import { createDownloadableData } from './utils';
|
|
|
|
export function QueryTable({
|
|
queryTableData,
|
|
query,
|
|
renderActionCell,
|
|
modifyColumns,
|
|
renderColumnCell,
|
|
downloadOption,
|
|
columns,
|
|
dataSource,
|
|
sticky,
|
|
searchTerm,
|
|
widgetId,
|
|
...props
|
|
}: QueryTableProps): JSX.Element {
|
|
const { isDownloadEnabled = false, fileName = '' } = downloadOption || {};
|
|
const { servicename: encodedServiceName } = useParams<IServiceName>();
|
|
const servicename = decodeURIComponent(encodedServiceName);
|
|
const { loading } = props;
|
|
const { columns: newColumns, dataSource: newDataSource } = useMemo(() => {
|
|
if (columns && dataSource) {
|
|
return { columns, dataSource };
|
|
}
|
|
return createTableColumnsFromQuery({
|
|
query,
|
|
queryTableData,
|
|
renderActionCell,
|
|
renderColumnCell,
|
|
});
|
|
}, [
|
|
columns,
|
|
dataSource,
|
|
query,
|
|
queryTableData,
|
|
renderActionCell,
|
|
renderColumnCell,
|
|
]);
|
|
|
|
const downloadableData = createDownloadableData(newDataSource);
|
|
|
|
const tableColumns = modifyColumns ? modifyColumns(newColumns) : newColumns;
|
|
|
|
const paginationConfig = {
|
|
pageSize: 10,
|
|
showSizeChanger: false,
|
|
hideOnSinglePage: true,
|
|
};
|
|
|
|
const [filterTable, setFilterTable] = useState<RowData[] | null>(null);
|
|
|
|
const onTableSearch = useCallback(
|
|
(value?: string): void => {
|
|
const filterTable = newDataSource.filter((o) =>
|
|
Object.keys(o).some((k) =>
|
|
String(o[k])
|
|
.toLowerCase()
|
|
.includes(value?.toLowerCase() || ''),
|
|
),
|
|
);
|
|
|
|
setFilterTable(filterTable);
|
|
},
|
|
[newDataSource],
|
|
);
|
|
|
|
useEffect(() => {
|
|
onTableSearch(searchTerm);
|
|
}, [newDataSource, onTableSearch, searchTerm]);
|
|
|
|
return (
|
|
<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={filterTable === null ? newDataSource : filterTable}
|
|
scroll={{ x: 'max-content' }}
|
|
pagination={paginationConfig}
|
|
widgetId={widgetId}
|
|
shouldPersistColumnWidths
|
|
sticky={sticky}
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
{...props}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|