refactor: enhance RunsTable component layout
This commit is contained in:
@@ -1,34 +1,67 @@
|
|||||||
import * as React from 'react';
|
import * as React from "react";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from "react-i18next";
|
||||||
import Paper from '@mui/material/Paper';
|
import Paper from "@mui/material/Paper";
|
||||||
import Table from '@mui/material/Table';
|
import Table from "@mui/material/Table";
|
||||||
import TableBody from '@mui/material/TableBody';
|
import TableBody from "@mui/material/TableBody";
|
||||||
import TableCell from '@mui/material/TableCell';
|
import TableCell from "@mui/material/TableCell";
|
||||||
import TableContainer from '@mui/material/TableContainer';
|
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, Tooltip } from '@mui/material';
|
import {
|
||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
Accordion,
|
||||||
import SearchIcon from '@mui/icons-material/Search';
|
AccordionSummary,
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
AccordionDetails,
|
||||||
|
Typography,
|
||||||
|
Box,
|
||||||
|
TextField,
|
||||||
|
CircularProgress,
|
||||||
|
Tooltip,
|
||||||
|
} from "@mui/material";
|
||||||
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||||
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { useGlobalInfoStore } from "../../context/globalInfo";
|
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';
|
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: 'name', label: 'Name', minWidth: 80 },
|
id: "runStatus",
|
||||||
{ id: 'startedAt', label: 'Started At', minWidth: 80 },
|
label: "Status",
|
||||||
{ id: 'finishedAt', label: 'Finished At', minWidth: 80 },
|
minWidth: 80,
|
||||||
{ id: 'settings', label: 'Settings', minWidth: 80 },
|
maxWidth: 120,
|
||||||
{ id: 'delete', label: 'Delete', minWidth: 80 },
|
flexGrow: 1,
|
||||||
|
},
|
||||||
|
{ id: "name", label: "Name", minWidth: 120, maxWidth: 250, flexGrow: 3 },
|
||||||
|
{
|
||||||
|
id: "startedAt",
|
||||||
|
label: "Started At",
|
||||||
|
minWidth: 120,
|
||||||
|
maxWidth: 180,
|
||||||
|
flexGrow: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "finishedAt",
|
||||||
|
label: "Finished At",
|
||||||
|
minWidth: 120,
|
||||||
|
maxWidth: 180,
|
||||||
|
flexGrow: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "settings",
|
||||||
|
label: "Settings",
|
||||||
|
minWidth: 80,
|
||||||
|
maxWidth: 120,
|
||||||
|
flexGrow: 1,
|
||||||
|
},
|
||||||
|
{ id: "delete", label: "Delete", minWidth: 80, maxWidth: 100, flexGrow: 1 },
|
||||||
];
|
];
|
||||||
|
|
||||||
type SortDirection = 'asc' | 'desc' | 'none';
|
type SortDirection = "asc" | "desc" | "none";
|
||||||
|
|
||||||
interface AccordionSortConfig {
|
interface AccordionSortConfig {
|
||||||
[robotMetaId: string]: {
|
[robotMetaId: string]: {
|
||||||
@@ -38,10 +71,10 @@ interface AccordionSortConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Column {
|
interface Column {
|
||||||
id: 'runStatus' | 'name' | 'startedAt' | 'finishedAt' | 'delete' | 'settings';
|
id: "runStatus" | "name" | "startedAt" | "finishedAt" | "delete" | "settings";
|
||||||
label: string;
|
label: string;
|
||||||
minWidth?: number;
|
minWidth?: number;
|
||||||
align?: 'right';
|
align?: "right";
|
||||||
format?: (value: string) => string;
|
format?: (value: string) => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,110 +114,145 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
currentInterpretationLog,
|
currentInterpretationLog,
|
||||||
abortRunHandler,
|
abortRunHandler,
|
||||||
runId,
|
runId,
|
||||||
runningRecordingName
|
runningRecordingName,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const getUrlParams = () => {
|
const getUrlParams = () => {
|
||||||
const match = location.pathname.match(/\/runs\/([^\/]+)(?:\/run\/([^\/]+))?/);
|
const match = location.pathname.match(
|
||||||
|
/\/runs\/([^\/]+)(?:\/run\/([^\/]+))?/
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
robotMetaId: match?.[1] || null,
|
robotMetaId: match?.[1] || null,
|
||||||
urlRunId: match?.[2] || null
|
urlRunId: match?.[2] || null,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const { robotMetaId: urlRobotMetaId, urlRunId } = getUrlParams();
|
const { robotMetaId: urlRobotMetaId, urlRunId } = getUrlParams();
|
||||||
|
|
||||||
const isAccordionExpanded = useCallback((currentRobotMetaId: string) => {
|
const isAccordionExpanded = useCallback(
|
||||||
return currentRobotMetaId === urlRobotMetaId;
|
(currentRobotMetaId: string) => {
|
||||||
}, [urlRobotMetaId]);
|
return currentRobotMetaId === urlRobotMetaId;
|
||||||
|
},
|
||||||
|
[urlRobotMetaId]
|
||||||
|
);
|
||||||
|
|
||||||
const [accordionPage, setAccordionPage] = useState(0);
|
const [accordionPage, setAccordionPage] = useState(0);
|
||||||
const [accordionsPerPage, setAccordionsPerPage] = useState(10);
|
const [accordionsPerPage, setAccordionsPerPage] = useState(10);
|
||||||
const [accordionSortConfigs, setAccordionSortConfigs] = useState<AccordionSortConfig>({});
|
const [accordionSortConfigs, setAccordionSortConfigs] =
|
||||||
|
useState<AccordionSortConfig>({});
|
||||||
|
|
||||||
const handleSort = useCallback((columnId: keyof Data, robotMetaId: string) => {
|
const handleSort = useCallback(
|
||||||
setAccordionSortConfigs(prevConfigs => {
|
(columnId: keyof Data, robotMetaId: string) => {
|
||||||
const currentConfig = prevConfigs[robotMetaId] || { field: null, direction: 'none' };
|
setAccordionSortConfigs((prevConfigs) => {
|
||||||
const newDirection: SortDirection =
|
const currentConfig = prevConfigs[robotMetaId] || {
|
||||||
currentConfig.field !== columnId ? 'asc' :
|
field: null,
|
||||||
currentConfig.direction === 'none' ? 'asc' :
|
direction: "none",
|
||||||
currentConfig.direction === 'asc' ? 'desc' : 'none';
|
};
|
||||||
|
const newDirection: SortDirection =
|
||||||
|
currentConfig.field !== columnId
|
||||||
|
? "asc"
|
||||||
|
: currentConfig.direction === "none"
|
||||||
|
? "asc"
|
||||||
|
: currentConfig.direction === "asc"
|
||||||
|
? "desc"
|
||||||
|
: "none";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...prevConfigs,
|
...prevConfigs,
|
||||||
[robotMetaId]: {
|
[robotMetaId]: {
|
||||||
field: newDirection === 'none' ? null : columnId,
|
field: newDirection === "none" ? null : columnId,
|
||||||
direction: newDirection,
|
direction: newDirection,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}, []);
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const translatedColumns = useMemo(() =>
|
const translatedColumns = useMemo(
|
||||||
columns.map(column => ({
|
() =>
|
||||||
...column,
|
columns.map((column) => ({
|
||||||
label: t(`runstable.${column.id}`, column.label)
|
...column,
|
||||||
})),
|
label: t(`runstable.${column.id}`, column.label),
|
||||||
|
})),
|
||||||
[t]
|
[t]
|
||||||
);
|
);
|
||||||
|
|
||||||
const [rows, setRows] = useState<Data[]>([]);
|
const [rows, setRows] = useState<Data[]>([]);
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
|
|
||||||
const [paginationStates, setPaginationStates] = useState<PaginationState>({});
|
const [paginationStates, setPaginationStates] = useState<PaginationState>({});
|
||||||
|
|
||||||
const { notify, rerenderRuns, setRerenderRuns } = useGlobalInfoStore();
|
const { notify, rerenderRuns, setRerenderRuns } = useGlobalInfoStore();
|
||||||
|
|
||||||
const handleAccordionChange = useCallback((robotMetaId: string, isExpanded: boolean) => {
|
const handleAccordionChange = useCallback(
|
||||||
navigate(isExpanded ? `/runs/${robotMetaId}` : '/runs');
|
(robotMetaId: string, isExpanded: boolean) => {
|
||||||
}, [navigate]);
|
navigate(isExpanded ? `/runs/${robotMetaId}` : "/runs");
|
||||||
|
},
|
||||||
|
[navigate]
|
||||||
|
);
|
||||||
|
|
||||||
const handleAccordionPageChange = useCallback((event: unknown, newPage: number) => {
|
const handleAccordionPageChange = useCallback(
|
||||||
setAccordionPage(newPage);
|
(event: unknown, newPage: number) => {
|
||||||
}, []);
|
setAccordionPage(newPage);
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const handleAccordionsPerPageChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleAccordionsPerPageChange = useCallback(
|
||||||
setAccordionsPerPage(+event.target.value);
|
(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setAccordionPage(0);
|
setAccordionsPerPage(+event.target.value);
|
||||||
}, []);
|
setAccordionPage(0);
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const handleChangePage = useCallback((robotMetaId: string, newPage: number) => {
|
const handleChangePage = useCallback(
|
||||||
setPaginationStates(prev => ({
|
(robotMetaId: string, newPage: number) => {
|
||||||
...prev,
|
setPaginationStates((prev) => ({
|
||||||
[robotMetaId]: {
|
...prev,
|
||||||
...prev[robotMetaId],
|
[robotMetaId]: {
|
||||||
page: newPage
|
...prev[robotMetaId],
|
||||||
|
page: newPage,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleChangeRowsPerPage = useCallback(
|
||||||
|
(robotMetaId: string, newRowsPerPage: number) => {
|
||||||
|
setPaginationStates((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[robotMetaId]: {
|
||||||
|
page: 0, // Reset to first page when changing rows per page
|
||||||
|
rowsPerPage: newRowsPerPage,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const getPaginationState = useCallback(
|
||||||
|
(robotMetaId: string) => {
|
||||||
|
const defaultState = { page: 0, rowsPerPage: 10 };
|
||||||
|
|
||||||
|
if (!paginationStates[robotMetaId]) {
|
||||||
|
setTimeout(() => {
|
||||||
|
setPaginationStates((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[robotMetaId]: defaultState,
|
||||||
|
}));
|
||||||
|
}, 0);
|
||||||
|
return defaultState;
|
||||||
}
|
}
|
||||||
}));
|
return paginationStates[robotMetaId];
|
||||||
}, []);
|
},
|
||||||
|
[paginationStates]
|
||||||
const handleChangeRowsPerPage = useCallback((robotMetaId: string, newRowsPerPage: number) => {
|
);
|
||||||
setPaginationStates(prev => ({
|
|
||||||
...prev,
|
|
||||||
[robotMetaId]: {
|
|
||||||
page: 0, // Reset to first page when changing rows per page
|
|
||||||
rowsPerPage: newRowsPerPage
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const getPaginationState = useCallback((robotMetaId: string) => {
|
|
||||||
const defaultState = { page: 0, rowsPerPage: 10 };
|
|
||||||
|
|
||||||
if (!paginationStates[robotMetaId]) {
|
|
||||||
setTimeout(() => {
|
|
||||||
setPaginationStates(prev => ({
|
|
||||||
...prev,
|
|
||||||
[robotMetaId]: defaultState
|
|
||||||
}));
|
|
||||||
}, 0);
|
|
||||||
return defaultState;
|
|
||||||
}
|
|
||||||
return paginationStates[robotMetaId];
|
|
||||||
}, [paginationStates]);
|
|
||||||
|
|
||||||
const debouncedSearch = useCallback((fn: Function, delay: number) => {
|
const debouncedSearch = useCallback((fn: Function, delay: number) => {
|
||||||
let timeoutId: NodeJS.Timeout;
|
let timeoutId: NodeJS.Timeout;
|
||||||
@@ -194,20 +262,26 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleSearchChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleSearchChange = useCallback(
|
||||||
const debouncedSetSearch = debouncedSearch((value: string) => {
|
(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setSearchTerm(value);
|
const debouncedSetSearch = debouncedSearch((value: string) => {
|
||||||
setAccordionPage(0);
|
setSearchTerm(value);
|
||||||
setPaginationStates(prev => {
|
setAccordionPage(0);
|
||||||
const reset = Object.keys(prev).reduce((acc, robotId) => ({
|
setPaginationStates((prev) => {
|
||||||
...acc,
|
const reset = Object.keys(prev).reduce(
|
||||||
[robotId]: { ...prev[robotId], page: 0 }
|
(acc, robotId) => ({
|
||||||
}), {});
|
...acc,
|
||||||
return reset;
|
[robotId]: { ...prev[robotId], page: 0 },
|
||||||
});
|
}),
|
||||||
}, 300);
|
{}
|
||||||
debouncedSetSearch(event.target.value);
|
);
|
||||||
}, [debouncedSearch]);
|
return reset;
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
debouncedSetSearch(event.target.value);
|
||||||
|
},
|
||||||
|
[debouncedSearch]
|
||||||
|
);
|
||||||
|
|
||||||
const fetchRuns = useCallback(async () => {
|
const fetchRuns = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -219,10 +293,10 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
}));
|
}));
|
||||||
setRows(parsedRows);
|
setRows(parsedRows);
|
||||||
} else {
|
} else {
|
||||||
notify('error', t('runstable.notifications.no_runs'));
|
notify("error", t("runstable.notifications.no_runs"));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notify('error', t('runstable.notifications.fetch_error'));
|
notify("error", t("runstable.notifications.fetch_error"));
|
||||||
}
|
}
|
||||||
}, [notify, t]);
|
}, [notify, t]);
|
||||||
|
|
||||||
@@ -244,7 +318,7 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
|
|
||||||
const handleDelete = useCallback(() => {
|
const handleDelete = useCallback(() => {
|
||||||
setRows([]);
|
setRows([]);
|
||||||
notify('success', t('runstable.notifications.delete_success'));
|
notify("success", t("runstable.notifications.delete_success"));
|
||||||
fetchRuns();
|
fetchRuns();
|
||||||
}, [notify, t, fetchRuns]);
|
}, [notify, t, fetchRuns]);
|
||||||
|
|
||||||
@@ -258,11 +332,11 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
|
|
||||||
const parseDateString = (dateStr: string): Date => {
|
const parseDateString = (dateStr: string): Date => {
|
||||||
try {
|
try {
|
||||||
if (dateStr.includes('PM') || dateStr.includes('AM')) {
|
if (dateStr.includes("PM") || dateStr.includes("AM")) {
|
||||||
return new Date(dateStr);
|
return new Date(dateStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Date(dateStr.replace(/(\d+)\/(\d+)\//, '$2/$1/'))
|
return new Date(dateStr.replace(/(\d+)\/(\d+)\//, "$2/$1/"));
|
||||||
} catch {
|
} catch {
|
||||||
return new Date(0);
|
return new Date(0);
|
||||||
}
|
}
|
||||||
@@ -277,16 +351,18 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, Data[]>);
|
}, {} as Record<string, Data[]>);
|
||||||
|
|
||||||
Object.keys(groupedData).forEach(robotId => {
|
Object.keys(groupedData).forEach((robotId) => {
|
||||||
groupedData[robotId].sort((a, b) =>
|
groupedData[robotId].sort(
|
||||||
parseDateString(b.startedAt).getTime() - parseDateString(a.startedAt).getTime()
|
(a, b) =>
|
||||||
|
parseDateString(b.startedAt).getTime() -
|
||||||
|
parseDateString(a.startedAt).getTime()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const robotEntries = Object.entries(groupedData).map(([robotId, runs]) => ({
|
const robotEntries = Object.entries(groupedData).map(([robotId, runs]) => ({
|
||||||
robotId,
|
robotId,
|
||||||
runs,
|
runs,
|
||||||
latestRunDate: parseDateString(runs[0].startedAt).getTime()
|
latestRunDate: parseDateString(runs[0].startedAt).getTime(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
robotEntries.sort((a, b) => b.latestRunDate - a.latestRunDate);
|
robotEntries.sort((a, b) => b.latestRunDate - a.latestRunDate);
|
||||||
@@ -297,87 +373,125 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
}, {} as Record<string, Data[]>);
|
}, {} as Record<string, Data[]>);
|
||||||
}, [filteredRows]);
|
}, [filteredRows]);
|
||||||
|
|
||||||
const renderTableRows = useCallback((data: Data[], robotMetaId: string) => {
|
const renderTableRows = useCallback(
|
||||||
const { page, rowsPerPage } = getPaginationState(robotMetaId);
|
(data: Data[], robotMetaId: string) => {
|
||||||
const start = page * rowsPerPage;
|
const { page, rowsPerPage } = getPaginationState(robotMetaId);
|
||||||
const end = start + rowsPerPage;
|
const start = page * rowsPerPage;
|
||||||
|
const end = start + rowsPerPage;
|
||||||
|
|
||||||
let sortedData = [...data];
|
let sortedData = [...data];
|
||||||
const sortConfig = accordionSortConfigs[robotMetaId];
|
const sortConfig = accordionSortConfigs[robotMetaId];
|
||||||
|
|
||||||
if (sortConfig?.field === 'startedAt' || sortConfig?.field === 'finishedAt') {
|
if (
|
||||||
if (sortConfig.direction !== 'none') {
|
sortConfig?.field === "startedAt" ||
|
||||||
sortedData.sort((a, b) => {
|
sortConfig?.field === "finishedAt"
|
||||||
const dateA = parseDateString(a[sortConfig.field!]);
|
) {
|
||||||
const dateB = parseDateString(b[sortConfig.field!]);
|
if (sortConfig.direction !== "none") {
|
||||||
|
sortedData.sort((a, b) => {
|
||||||
|
const dateA = parseDateString(a[sortConfig.field!]);
|
||||||
|
const dateB = parseDateString(b[sortConfig.field!]);
|
||||||
|
|
||||||
return sortConfig.direction === 'asc'
|
return sortConfig.direction === "asc"
|
||||||
? dateA.getTime() - dateB.getTime()
|
? dateA.getTime() - dateB.getTime()
|
||||||
: dateB.getTime() - dateA.getTime();
|
: dateB.getTime() - dateA.getTime();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return sortedData
|
return sortedData
|
||||||
.slice(start, end)
|
.slice(start, end)
|
||||||
.map((row) => (
|
.map((row) => (
|
||||||
<CollapsibleRow
|
<CollapsibleRow
|
||||||
key={`row-${row.id}`}
|
key={`row-${row.id}`}
|
||||||
row={row}
|
row={row}
|
||||||
handleDelete={handleDelete}
|
handleDelete={handleDelete}
|
||||||
isOpen={urlRunId === row.runId || (runId === row.runId && runningRecordingName === row.name)}
|
isOpen={
|
||||||
currentLog={currentInterpretationLog}
|
urlRunId === row.runId ||
|
||||||
abortRunHandler={abortRunHandler}
|
(runId === row.runId && runningRecordingName === row.name)
|
||||||
runningRecordingName={runningRecordingName}
|
|
||||||
urlRunId={urlRunId}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
}, [paginationStates, 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
|
|
||||||
}
|
}
|
||||||
}}
|
currentLog={currentInterpretationLog}
|
||||||
/>
|
abortRunHandler={abortRunHandler}
|
||||||
);
|
runningRecordingName={runningRecordingName}
|
||||||
}
|
urlRunId={urlRunId}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
},
|
||||||
|
[
|
||||||
|
paginationStates,
|
||||||
|
runId,
|
||||||
|
runningRecordingName,
|
||||||
|
currentInterpretationLog,
|
||||||
|
abortRunHandler,
|
||||||
|
handleDelete,
|
||||||
|
accordionSortConfigs,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
return sortConfig.direction === 'asc'
|
const renderSortIcon = useCallback(
|
||||||
? <ArrowUpward fontSize="small" />
|
(column: Column, robotMetaId: string) => {
|
||||||
: sortConfig.direction === 'desc'
|
const sortConfig = accordionSortConfigs[robotMetaId];
|
||||||
? <ArrowDownward fontSize="small" />
|
if (column.id !== "startedAt" && column.id !== "finishedAt") return null;
|
||||||
: <UnfoldMore fontSize="small" />;
|
|
||||||
}, [accordionSortConfigs]);
|
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]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Box display="flex" justifyContent="space-between" alignItems="center" mb={2}>
|
<Box
|
||||||
|
display="flex"
|
||||||
|
justifyContent="space-between"
|
||||||
|
alignItems="center"
|
||||||
|
mb={2}
|
||||||
|
>
|
||||||
<Typography variant="h6" component="h2">
|
<Typography variant="h6" component="h2">
|
||||||
{t('runstable.runs', 'Runs')}
|
{t("runstable.runs", "Runs")}
|
||||||
</Typography>
|
</Typography>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
placeholder={t('runstable.search', 'Search runs...')}
|
placeholder={t("runstable.search", "Search runs...")}
|
||||||
onChange={handleSearchChange}
|
onChange={handleSearchChange}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: <SearchIcon sx={{ color: 'action.active', mr: 1 }} />
|
startAdornment: (
|
||||||
|
<SearchIcon sx={{ color: "action.active", mr: 1 }} />
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
sx={{ width: '250px' }}
|
sx={{ width: "250px" }}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<TableContainer component={Paper} sx={{ width: '100%', overflow: 'hidden' }}>
|
<TableContainer
|
||||||
|
component={Paper}
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
overflow: "auto",
|
||||||
|
"@media (max-width: 600px)": {
|
||||||
|
maxWidth: "calc(100vw - 32px)",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
{Object.entries(groupedRows)
|
{Object.entries(groupedRows)
|
||||||
.slice(
|
.slice(
|
||||||
accordionPage * accordionsPerPage,
|
accordionPage * accordionsPerPage,
|
||||||
@@ -386,11 +500,15 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
.map(([robotMetaId, data]) => (
|
.map(([robotMetaId, data]) => (
|
||||||
<Accordion
|
<Accordion
|
||||||
key={robotMetaId}
|
key={robotMetaId}
|
||||||
onChange={(event, isExpanded) => handleAccordionChange(robotMetaId, 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 />}>
|
||||||
<Typography variant="h6">{data[data.length - 1].name}</Typography>
|
<Typography variant="h6">
|
||||||
|
{data[data.length - 1].name}
|
||||||
|
</Typography>
|
||||||
</AccordionSummary>
|
</AccordionSummary>
|
||||||
<AccordionDetails>
|
<AccordionDetails>
|
||||||
<Table stickyHeader aria-label="sticky table">
|
<Table stickyHeader aria-label="sticky table">
|
||||||
@@ -403,38 +521,62 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
align={column.align}
|
align={column.align}
|
||||||
style={{
|
style={{
|
||||||
minWidth: column.minWidth,
|
minWidth: column.minWidth,
|
||||||
cursor: column.id === 'startedAt' || column.id === 'finishedAt' ? 'pointer' : 'default'
|
maxWidth: column.maxWidth,
|
||||||
|
width: `${
|
||||||
|
(column.flexGrow / totalFlexGrow) * 100
|
||||||
|
}%`,
|
||||||
|
cursor:
|
||||||
|
column.id === "startedAt" ||
|
||||||
|
column.id === "finishedAt"
|
||||||
|
? "pointer"
|
||||||
|
: "default",
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (column.id === 'startedAt' || column.id === 'finishedAt') {
|
if (
|
||||||
|
column.id === "startedAt" ||
|
||||||
|
column.id === "finishedAt"
|
||||||
|
) {
|
||||||
handleSort(column.id, robotMetaId);
|
handleSort(column.id, robotMetaId);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={
|
title={
|
||||||
(column.id === 'startedAt' || column.id === 'finishedAt')
|
column.id === "startedAt" ||
|
||||||
? t('runstable.sort_tooltip')
|
column.id === "finishedAt"
|
||||||
: ''
|
? t("runstable.sort_tooltip")
|
||||||
|
: ""
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Box sx={{
|
<Box
|
||||||
display: 'flex',
|
sx={{
|
||||||
alignItems: 'center',
|
display: "flex",
|
||||||
gap: 1,
|
alignItems: "center",
|
||||||
'&:hover': {
|
gap: 1,
|
||||||
'& .sort-icon': {
|
"&:hover": {
|
||||||
opacity: 1
|
"& .sort-icon": {
|
||||||
}
|
opacity: 1,
|
||||||
}
|
},
|
||||||
}}>
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
{column.label}
|
{column.label}
|
||||||
<Box className="sort-icon" sx={{
|
<Box
|
||||||
display: 'flex',
|
className="sort-icon"
|
||||||
alignItems: 'center',
|
sx={{
|
||||||
opacity: accordionSortConfigs[robotMetaId]?.field === column.id ? 1 : 0.3,
|
display: "flex",
|
||||||
transition: 'opacity 0.2s'
|
alignItems: "center",
|
||||||
}}>
|
opacity:
|
||||||
|
accordionSortConfigs[robotMetaId]?.field ===
|
||||||
|
column.id
|
||||||
|
? 1
|
||||||
|
: 0.3,
|
||||||
|
transition: "opacity 0.2s",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{renderSortIcon(column, robotMetaId)}
|
{renderSortIcon(column, robotMetaId)}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
@@ -443,9 +585,7 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
))}
|
))}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>{renderTableRows(data, robotMetaId)}</TableBody>
|
||||||
{renderTableRows(data, robotMetaId)}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
<TablePagination
|
<TablePagination
|
||||||
@@ -453,7 +593,9 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
count={data.length}
|
count={data.length}
|
||||||
rowsPerPage={getPaginationState(robotMetaId).rowsPerPage}
|
rowsPerPage={getPaginationState(robotMetaId).rowsPerPage}
|
||||||
page={getPaginationState(robotMetaId).page}
|
page={getPaginationState(robotMetaId).page}
|
||||||
onPageChange={(_, newPage) => handleChangePage(robotMetaId, newPage)}
|
onPageChange={(_, newPage) =>
|
||||||
|
handleChangePage(robotMetaId, newPage)
|
||||||
|
}
|
||||||
onRowsPerPageChange={(event) =>
|
onRowsPerPageChange={(event) =>
|
||||||
handleChangeRowsPerPage(robotMetaId, +event.target.value)
|
handleChangeRowsPerPage(robotMetaId, +event.target.value)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user