Merge pull request #407 from getmaxun/sort-run
feat: sort functionality for runs table data
This commit is contained in:
@@ -62,6 +62,7 @@
|
|||||||
"delete": "Löschen",
|
"delete": "Löschen",
|
||||||
"settings": "Einstellungen",
|
"settings": "Einstellungen",
|
||||||
"search": "Ausführungen suchen...",
|
"search": "Ausführungen suchen...",
|
||||||
|
"sort_tooltip": "Zum Sortieren klicken",
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"no_runs": "Keine Ausführungen gefunden. Bitte versuchen Sie es erneut.",
|
"no_runs": "Keine Ausführungen gefunden. Bitte versuchen Sie es erneut.",
|
||||||
"delete_success": "Ausführung erfolgreich gelöscht"
|
"delete_success": "Ausführung erfolgreich gelöscht"
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
"delete":"Delete",
|
"delete":"Delete",
|
||||||
"settings":"Settings",
|
"settings":"Settings",
|
||||||
"search":"Search Runs...",
|
"search":"Search Runs...",
|
||||||
|
"sort_tooltip": "Click to sort",
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"no_runs": "No runs found. Please try again.",
|
"no_runs": "No runs found. Please try again.",
|
||||||
"delete_success": "Run deleted successfully"
|
"delete_success": "Run deleted successfully"
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
"delete": "Eliminar",
|
"delete": "Eliminar",
|
||||||
"settings": "Ajustes",
|
"settings": "Ajustes",
|
||||||
"search": "Buscar ejecuciones...",
|
"search": "Buscar ejecuciones...",
|
||||||
|
"sort_tooltip": "Haga clic para ordenar",
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"no_runs": "No se encontraron ejecuciones. Por favor, inténtelo de nuevo.",
|
"no_runs": "No se encontraron ejecuciones. Por favor, inténtelo de nuevo.",
|
||||||
"delete_success": "Ejecución eliminada con éxito"
|
"delete_success": "Ejecución eliminada con éxito"
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
"delete": "削除",
|
"delete": "削除",
|
||||||
"settings": "設定",
|
"settings": "設定",
|
||||||
"search": "実行を検索...",
|
"search": "実行を検索...",
|
||||||
|
"sort_tooltip": "クリックして並べ替え",
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"no_runs": "実行が見つかりません。もう一度お試しください。",
|
"no_runs": "実行が見つかりません。もう一度お試しください。",
|
||||||
"delete_success": "実行が正常に削除されました"
|
"delete_success": "実行が正常に削除されました"
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
"delete": "删除",
|
"delete": "删除",
|
||||||
"settings": "设置",
|
"settings": "设置",
|
||||||
"search": "搜索运行记录...",
|
"search": "搜索运行记录...",
|
||||||
|
"sort_tooltip": "点击排序",
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"no_runs": "未找到运行记录。请重试。",
|
"no_runs": "未找到运行记录。请重试。",
|
||||||
"delete_success": "运行记录删除成功"
|
"delete_success": "运行记录删除成功"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import TableContainer from '@mui/material/TableContainer';
|
|||||||
import TableHead from '@mui/material/TableHead';
|
import TableHead from '@mui/material/TableHead';
|
||||||
import TablePagination from '@mui/material/TablePagination';
|
import TablePagination from '@mui/material/TablePagination';
|
||||||
import TableRow from '@mui/material/TableRow';
|
import TableRow from '@mui/material/TableRow';
|
||||||
import { Accordion, AccordionSummary, AccordionDetails, Typography, Box, TextField, CircularProgress } from '@mui/material';
|
import { Accordion, AccordionSummary, AccordionDetails, Typography, Box, TextField, CircularProgress, Tooltip } from '@mui/material';
|
||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
import SearchIcon from '@mui/icons-material/Search';
|
import SearchIcon from '@mui/icons-material/Search';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
@@ -17,6 +17,7 @@ import { useGlobalInfoStore } from "../../context/globalInfo";
|
|||||||
import { getStoredRuns } from "../../api/storage";
|
import { getStoredRuns } from "../../api/storage";
|
||||||
import { RunSettings } from "./RunSettings";
|
import { RunSettings } from "./RunSettings";
|
||||||
import { CollapsibleRow } from "./ColapsibleRow";
|
import { CollapsibleRow } from "./ColapsibleRow";
|
||||||
|
import { ArrowDownward, ArrowUpward, UnfoldMore } from '@mui/icons-material';
|
||||||
|
|
||||||
export const columns: readonly Column[] = [
|
export const columns: readonly Column[] = [
|
||||||
{ id: 'runStatus', label: 'Status', minWidth: 80 },
|
{ id: 'runStatus', label: 'Status', minWidth: 80 },
|
||||||
@@ -27,6 +28,15 @@ export const columns: readonly Column[] = [
|
|||||||
{ id: 'delete', label: 'Delete', minWidth: 80 },
|
{ id: 'delete', label: 'Delete', minWidth: 80 },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
type SortDirection = 'asc' | 'desc' | 'none';
|
||||||
|
|
||||||
|
interface AccordionSortConfig {
|
||||||
|
[robotMetaId: string]: {
|
||||||
|
field: keyof Data | null;
|
||||||
|
direction: SortDirection;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
interface Column {
|
interface Column {
|
||||||
id: 'runStatus' | 'name' | 'startedAt' | 'finishedAt' | 'delete' | 'settings';
|
id: 'runStatus' | 'name' | 'startedAt' | 'finishedAt' | 'delete' | 'settings';
|
||||||
label: string;
|
label: string;
|
||||||
@@ -69,6 +79,26 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const [accordionSortConfigs, setAccordionSortConfigs] = useState<AccordionSortConfig>({});
|
||||||
|
|
||||||
|
const handleSort = useCallback((columnId: keyof Data, robotMetaId: string) => {
|
||||||
|
setAccordionSortConfigs(prevConfigs => {
|
||||||
|
const currentConfig = prevConfigs[robotMetaId] || { field: null, direction: 'none' };
|
||||||
|
const newDirection: SortDirection =
|
||||||
|
currentConfig.field !== columnId ? 'asc' :
|
||||||
|
currentConfig.direction === 'none' ? 'asc' :
|
||||||
|
currentConfig.direction === 'asc' ? 'desc' : 'none';
|
||||||
|
|
||||||
|
return {
|
||||||
|
...prevConfigs,
|
||||||
|
[robotMetaId]: {
|
||||||
|
field: newDirection === 'none' ? null : columnId,
|
||||||
|
direction: newDirection,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const translatedColumns = useMemo(() =>
|
const translatedColumns = useMemo(() =>
|
||||||
columns.map(column => ({
|
columns.map(column => ({
|
||||||
...column,
|
...column,
|
||||||
@@ -157,12 +187,12 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
}, [notify, t, fetchRuns]);
|
}, [notify, t, fetchRuns]);
|
||||||
|
|
||||||
// Filter rows based on search term
|
// Filter rows based on search term
|
||||||
const filteredRows = useMemo(() =>
|
const filteredRows = useMemo(() => {
|
||||||
rows.filter((row) =>
|
let result = rows.filter((row) =>
|
||||||
row.name.toLowerCase().includes(searchTerm.toLowerCase())
|
row.name.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
),
|
);
|
||||||
[rows, searchTerm]
|
return result;
|
||||||
);
|
}, [rows, searchTerm]);
|
||||||
|
|
||||||
// Group filtered rows by robot meta id
|
// Group filtered rows by robot meta id
|
||||||
const groupedRows = useMemo(() =>
|
const groupedRows = useMemo(() =>
|
||||||
@@ -176,11 +206,39 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
[filteredRows]
|
[filteredRows]
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderTableRows = useCallback((data: Data[]) => {
|
const parseDateString = (dateStr: string): Date => {
|
||||||
|
try {
|
||||||
|
if (dateStr.includes('PM') || dateStr.includes('AM')) {
|
||||||
|
return new Date(dateStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Date(dateStr.replace(/(\d+)\/(\d+)\//, '$2/$1/'))
|
||||||
|
} catch {
|
||||||
|
return new Date(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderTableRows = useCallback((data: Data[], robotMetaId: string) => {
|
||||||
const start = page * rowsPerPage;
|
const start = page * rowsPerPage;
|
||||||
const end = start + rowsPerPage;
|
const end = start + rowsPerPage;
|
||||||
|
|
||||||
|
let sortedData = [...data];
|
||||||
|
const sortConfig = accordionSortConfigs[robotMetaId];
|
||||||
|
|
||||||
return data
|
if (sortConfig?.field === 'startedAt' || sortConfig?.field === 'finishedAt') {
|
||||||
|
if (sortConfig.direction !== 'none') {
|
||||||
|
sortedData.sort((a, b) => {
|
||||||
|
const dateA = parseDateString(a[sortConfig.field!]);
|
||||||
|
const dateB = parseDateString(b[sortConfig.field!]);
|
||||||
|
|
||||||
|
return sortConfig.direction === 'asc'
|
||||||
|
? dateA.getTime() - dateB.getTime()
|
||||||
|
: dateB.getTime() - dateA.getTime();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortedData
|
||||||
.slice(start, end)
|
.slice(start, end)
|
||||||
.map((row) => (
|
.map((row) => (
|
||||||
<CollapsibleRow
|
<CollapsibleRow
|
||||||
@@ -193,7 +251,33 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
runningRecordingName={runningRecordingName}
|
runningRecordingName={runningRecordingName}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
}, [page, rowsPerPage, runId, runningRecordingName, currentInterpretationLog, abortRunHandler, handleDelete]);
|
}, [page, rowsPerPage, runId, runningRecordingName, currentInterpretationLog, abortRunHandler, handleDelete, accordionSortConfigs]);
|
||||||
|
|
||||||
|
const renderSortIcon = useCallback((column: Column, robotMetaId: string) => {
|
||||||
|
const sortConfig = accordionSortConfigs[robotMetaId];
|
||||||
|
if (column.id !== 'startedAt' && column.id !== 'finishedAt') return null;
|
||||||
|
|
||||||
|
if (sortConfig?.field !== column.id) {
|
||||||
|
return (
|
||||||
|
<UnfoldMore
|
||||||
|
fontSize="small"
|
||||||
|
sx={{
|
||||||
|
opacity: 0.3,
|
||||||
|
transition: 'opacity 0.2s',
|
||||||
|
'.MuiTableCell-root:hover &': {
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortConfig.direction === 'asc'
|
||||||
|
? <ArrowUpward fontSize="small" />
|
||||||
|
: sortConfig.direction === 'desc'
|
||||||
|
? <ArrowDownward fontSize="small" />
|
||||||
|
: <UnfoldMore fontSize="small" />;
|
||||||
|
}, [accordionSortConfigs]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -221,10 +305,10 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<TableContainer component={Paper} sx={{ width: '100%', overflow: 'hidden' }}>
|
<TableContainer component={Paper} sx={{ width: '100%', overflow: 'hidden' }}>
|
||||||
{Object.entries(groupedRows).map(([id, data]) => (
|
{Object.entries(groupedRows).map(([robotMetaId, data]) => (
|
||||||
<Accordion
|
<Accordion
|
||||||
key={id}
|
key={robotMetaId}
|
||||||
onChange={(event, isExpanded) => handleAccordionChange(id, isExpanded)}
|
onChange={(event, isExpanded) => handleAccordionChange(robotMetaId, isExpanded)}
|
||||||
TransitionProps={{ unmountOnExit: true }} // Optimize accordion rendering
|
TransitionProps={{ unmountOnExit: true }} // Optimize accordion rendering
|
||||||
>
|
>
|
||||||
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||||
@@ -239,15 +323,50 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
<TableCell
|
<TableCell
|
||||||
key={column.id}
|
key={column.id}
|
||||||
align={column.align}
|
align={column.align}
|
||||||
style={{ minWidth: column.minWidth }}
|
style={{
|
||||||
|
minWidth: column.minWidth,
|
||||||
|
cursor: column.id === 'startedAt' || column.id === 'finishedAt' ? 'pointer' : 'default'
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
if (column.id === 'startedAt' || column.id === 'finishedAt') {
|
||||||
|
handleSort(column.id, robotMetaId);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{column.label}
|
<Tooltip
|
||||||
|
title={
|
||||||
|
(column.id === 'startedAt' || column.id === 'finishedAt')
|
||||||
|
? t('runstable.sort_tooltip')
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Box sx={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 1,
|
||||||
|
'&:hover': {
|
||||||
|
'& .sort-icon': {
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
{column.label}
|
||||||
|
<Box className="sort-icon" sx={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
opacity: accordionSortConfigs[robotMetaId]?.field === column.id ? 1 : 0.3,
|
||||||
|
transition: 'opacity 0.2s'
|
||||||
|
}}>
|
||||||
|
{renderSortIcon(column, robotMetaId)}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Tooltip>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
))}
|
))}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{renderTableRows(data)}
|
{renderTableRows(data, robotMetaId)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</AccordionDetails>
|
</AccordionDetails>
|
||||||
|
|||||||
Reference in New Issue
Block a user