Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 5 additions & 34 deletions frontend/src/components/dialogs/EditEnumDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ import {
useTheme
} from '@mui/material';
import {
ArrowDropDown,
ArrowDropUp,
Close as CloseIcon,
MoreHoriz,
SortByAlpha
UnfoldMore
} from '@mui/icons-material';
import {
getDialogTableHeight,
getPageSizeOptionsOnDialog,
getTableHeaderBackgroundColor,
getTableRowBackgroundColor,
moveDown,
movedRow,
moveUp,
removeRow,
replaceRow,
sortedRows,
Expand All @@ -35,7 +30,6 @@ import MaterialTable from '@material-table/core';
import PropTypes from 'prop-types';
import EditIconDialog from "./SelectIconDialog";
import {MessageBox} from "../utils/MessageBox";
import {getLastPageSizeOnDialog, setLastPageSizeOnDialog} from "../../utils/ConfigurationStorage";
import StyledIcon from "../utils/StyledIcon";
import DraggableBodyRow from "../utils/DraggableBodyRow";

Expand Down Expand Up @@ -96,8 +90,6 @@ export default function EditEnumDialog(props) {
{open: false, severity: 'error', title: '', message: ''});
const [open, setOpen] = useState(false);
const [data, setData] = useState(props.items != null ? props.items : []);
// the rows per page of the dialogs, remembered
const [pageSize, setPageSize] = useState(getLastPageSizeOnDialog);
// the Sort menu: sorts the items for good (the order of the list in the data); opened at the position of the
// button, because material-table renders its actions again and the button element itself doesn't stay
const [sortMenuPosition, setSortMenuPosition] = useState(null);
Expand Down Expand Up @@ -196,15 +188,9 @@ export default function EditEnumDialog(props) {
tableRef={tableRef}
columns={getColumns()}
data={data}
onRowsPerPageChange={size => {
setPageSize(size);
setLastPageSizeOnDialog(size);
}}
options={{
paging: true,
pageSize: pageSize,
paginationType: 'stepped',
pageSizeOptions: getPageSizeOptionsOnDialog(),
// one list without pages, so that any item can be dragged anywhere
paging: false,
actionsColumnIndex: -1,
selection: false,
filtering: false,
Expand Down Expand Up @@ -252,27 +238,12 @@ export default function EditEnumDialog(props) {
}}
actions={[
{
icon: () => <SortByAlpha/>,
icon: () => <UnfoldMore/>,
tooltip: 'Sort items',
isFreeAction: true,
disabled: data.length < 2,
onClick: openSortMenu
},
rowData => ({
icon: () => <ArrowDropDown/>,
tooltip: 'Move down',
onClick: (event, rowData) => setData(
moveDown(data, rowData.tableData.id)),
disabled: (rowData.tableData.id === data.length
- 1)
}),
rowData => ({
icon: () => <ArrowDropUp/>,
tooltip: 'Move up',
onClick: (event, rowData) => setData(
moveUp(data, rowData.tableData.id)),
disabled: (rowData.tableData.id === 0)
})
}
]}
/>
<Menu
Expand Down
18 changes: 0 additions & 18 deletions frontend/src/components/utils/ActionPropertiesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {
getTableBodyHeight,
getTableHeaderBackgroundColor,
getTableRowBackgroundColor,
moveDown,
movedRow,
moveUp,
withoutHeaderSorting,
removeRow,
replaceRow
Expand All @@ -16,8 +14,6 @@ import {
isItemChanged,
validateItem
} from "../../utils/JsonHelper";
import ArrowDropDown from "@mui/icons-material/ArrowDropDown";
import ArrowDropUp from "@mui/icons-material/ArrowDropUp";
import MaterialTable, {MTableEditField} from '@material-table/core';
import DraggableBodyRow from "./DraggableBodyRow";
import React, {useContext, useEffect, useState} from "react";
Expand Down Expand Up @@ -285,20 +281,6 @@ export default function ActionPropertiesTable(props) {
onMoveRow={(from, to) => setData(movedRow(data, from, to))}/>
}}
editable={getEditable()}
actions={[
rowData => ({
icon: ArrowDropDown,
tooltip: 'Move down',
onClick: (event, rowData) => setData(moveDown(data, rowData.tableData.id)),
disabled: (rowData.tableData.id === data.length - 1)
}),
rowData => ({
icon: ArrowDropUp,
tooltip: 'Move up',
onClick: (event, rowData) => setData(moveUp(data, rowData.tableData.id)),
disabled: (rowData.tableData.id === 0)
})
]}
/>
<MessageBox
config={messageBox}
Expand Down
19 changes: 0 additions & 19 deletions frontend/src/components/utils/ColumnsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import {
getTableBodyHeight,
getTableHeaderBackgroundColor,
getTableRowBackgroundColor,
moveDown,
movedRow,
moveUp,
withoutHeaderSorting,
removeRow,
replaceRow
Expand All @@ -15,7 +13,6 @@ import {
isItemChanged,
validateItem
} from "../../utils/JsonHelper";
import {ArrowDropDown, ArrowDropUp} from "@mui/icons-material";
import MaterialTable from '@material-table/core';
import DraggableBodyRow from "./DraggableBodyRow";
import React, {useEffect, useState} from "react";
Expand Down Expand Up @@ -231,22 +228,6 @@ export default function ColumnsTable(props) {
resolve();
}),
}}
actions={[
rowData => ({
icon: () => <ArrowDropDown/>,
tooltip: 'Move down',
onClick: (event, rowData) => setData(
moveDown(columns, rowData.tableData.id)),
disabled: (rowData.tableData.id === columns.length - 1)
}),
rowData => ({
icon: () => <ArrowDropUp/>,
tooltip: 'Move up',
onClick: (event, rowData) => setData(
moveUp(columns, rowData.tableData.id)),
disabled: (rowData.tableData.id === 0)
})
]}
/>
<MessageBox
config={messageBox}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/utils/DraggableBodyRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {useTheme} from '@mui/material';
// The position (in the data) of the row being dragged; one drag at a time, so shared by all the rows
let draggedIndex = null;

// A row of a material-table that can be dragged onto another row to move it there (besides the Move up/down arrows).
// A row of a material-table that can be dragged onto another row to move it there (the order of enum items, columns,
// properties, task actions).
// Use: components={{Row: props => <DraggableBodyRow {...props} onMoveRow={(from, to) => setData(movedRow(data, from, to))}/>}}
// Native HTML drag and drop: material-table passes the other props on to the <tr>. The row isn't draggable while a row
// is edited (the inputs need the mouse).
Expand Down
17 changes: 0 additions & 17 deletions frontend/src/components/utils/PropertiesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ import {
getTableBodyHeight,
getTableHeaderBackgroundColor,
getTableRowBackgroundColor,
moveDown,
movedRow,
moveUp,
withoutHeaderSorting,
removeRow,
replaceRow
} from "../../utils/MaterialTableHelper";
import SelectEnumDialog from "../dialogs/SelectEnumDialog";
import {isItemChanged, uuidV4, validateItem} from "../../utils/JsonHelper";
import {ArrowDropDown, ArrowDropUp} from "@mui/icons-material";
import MaterialTable from '@material-table/core';
import DraggableBodyRow from "./DraggableBodyRow";
import React, {useEffect, useState} from "react";
Expand Down Expand Up @@ -234,20 +231,6 @@ export default function PropertiesTable(props) {
}
}),
}}
actions={[
rowData => ({
icon: () => <ArrowDropDown/>,
tooltip: 'Move down',
onClick: (event, rowData) => setData(moveDown(data, rowData.tableData.id)),
disabled: (rowData.tableData.id === data.length - 1)
}),
rowData => ({
icon: () => <ArrowDropUp/>,
tooltip: 'Move up',
onClick: (event, rowData) => setData(moveUp(data, rowData.tableData.id)),
disabled: (rowData.tableData.id === 0)
})
]}
/>
<MessageBox
config={messageBox}
Expand Down
19 changes: 2 additions & 17 deletions frontend/src/utils/MaterialTableHelper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ export const getUserIcon = (rowData) => {
}
}

export const moveUp = (dataCollection, itemId) => {
return swappedArray(dataCollection, itemId, itemId - 1);
}

// A row edited or removed in a table whose rows are kept in a state: material-table 6 passes copies of the rows (with
// tableData) and leaves the objects of the state as they are, so the row is found by its position (tableData.index)
const withoutTableData = ({tableData, ...row}) => row;
Expand All @@ -224,10 +220,6 @@ export const replaceRow = (rows, oldData, newData) =>

export const removeRow = (rows, oldData) => rows.filter((row, index) => index !== oldData.tableData.index);

export const moveDown = (dataCollection, itemId) => {
return swappedArray(dataCollection, itemId, itemId + 1);
}

// Rows sorted for good by a text field: natural order ("item2" before "item10"), letters with diacritics in place, a
// stable sort (rows with the same value keep their order)
const naturalCollator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
Expand All @@ -246,17 +238,10 @@ export const movedRow = (rows, from, to) => {
return newRows;
}

// Columns of a table whose rows have an order of their own (Move up/down, dragging): the headers don't sort, because
// that would only sort the view, while the arrows and dragging move the rows in the data (options.sorting is not
// enough in material-table 6)
// Columns of a table whose rows have an order of their own (dragging): the headers don't sort, because that would only
// sort the view, while dragging moves the rows in the data (options.sorting is not enough in material-table 6)
export const withoutHeaderSorting = columns => columns.map(column => ({...column, sorting: false}));

function swappedArray(arr, index1, index2) {
const newArr = [...arr];
[newArr[index1], newArr[index2]] = [newArr[index2], newArr[index1]];
return newArr;
}

export const getTableHeight = () => {
// Total Height - Appbar (72) - Toolbar (64) - Footer (52)
const staticElements = 72 + 64 + 52 + 2;
Expand Down
Loading