mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-10 08:39:34 +00:00
refactor: extract edit element in table
This commit is contained in:
committed by
Carlos Valente
parent
2fc4e6da16
commit
c445c42f8a
@@ -32,24 +32,20 @@ $table-header-font-size: calc(1rem - 2px);
|
|||||||
|
|
||||||
.tableHeader,
|
.tableHeader,
|
||||||
.eventRow {
|
.eventRow {
|
||||||
|
.actionColumn {
|
||||||
|
width: calc(2rem + 0.5rem); // sm button size (--chakra-sizes-8) + 2 * padding
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
.indexColumn {
|
.indexColumn {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: end;
|
justify-content: end;
|
||||||
|
|
||||||
min-width: 3em; // allow for 3-digit numbers
|
min-width: 3em; // allow for 3-digit numbers
|
||||||
text-align: right;
|
|
||||||
font-weight: 400;
|
|
||||||
font-size: $table-header-font-size;
|
font-size: $table-header-font-size;
|
||||||
position: sticky;
|
|
||||||
left: 0;
|
|
||||||
z-index: 1;
|
|
||||||
background-color: $gray-1300; // will be overridden inline
|
background-color: $gray-1300; // will be overridden inline
|
||||||
}
|
}
|
||||||
|
|
||||||
.actionColumn {
|
|
||||||
width: calc(2rem + 0.5rem); // sm button size (--chakra-sizes-8) + 2 * padding
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tableHeader {
|
.tableHeader {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
import { IconButton, Menu, MenuButton } from '@chakra-ui/react';
|
import { Menu } from '@chakra-ui/react';
|
||||||
import { IoEllipsisHorizontal } from '@react-icons/all-files/io5/IoEllipsisHorizontal';
|
|
||||||
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from '@tanstack/react-table';
|
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from '@tanstack/react-table';
|
||||||
import Color from 'color';
|
import Color from 'color';
|
||||||
import {
|
import {
|
||||||
@@ -11,6 +10,7 @@ import {
|
|||||||
OntimeEvent,
|
OntimeEvent,
|
||||||
OntimeRundown,
|
OntimeRundown,
|
||||||
OntimeRundownEntry,
|
OntimeRundownEntry,
|
||||||
|
TimeField,
|
||||||
} from 'ontime-types';
|
} from 'ontime-types';
|
||||||
|
|
||||||
import { useEventAction } from '../../../common/hooks/useEventAction';
|
import { useEventAction } from '../../../common/hooks/useEventAction';
|
||||||
@@ -38,7 +38,7 @@ interface CuesheetTableProps {
|
|||||||
export default function CuesheetTable(props: CuesheetTableProps) {
|
export default function CuesheetTable(props: CuesheetTableProps) {
|
||||||
const { data, columns, showModal } = props;
|
const { data, columns, showModal } = props;
|
||||||
|
|
||||||
const { updateEvent } = useEventAction();
|
const { updateEvent, updateTimer } = useEventAction();
|
||||||
const { selectedEventId } = useSelectedEventId();
|
const { selectedEventId } = useSelectedEventId();
|
||||||
const { followSelected, hideDelays, hidePast, hideIndexColumn } = useCuesheetOptions();
|
const { followSelected, hideDelays, hidePast, hideIndexColumn } = useCuesheetOptions();
|
||||||
const { columnVisibility, columnOrder, columnSizing, resetColumnOrder, setColumnVisibility, setColumnSizing } =
|
const { columnVisibility, columnOrder, columnSizing, resetColumnOrder, setColumnVisibility, setColumnSizing } =
|
||||||
@@ -61,7 +61,7 @@ export default function CuesheetTable(props: CuesheetTableProps) {
|
|||||||
onColumnSizingChange: setColumnSizing,
|
onColumnSizingChange: setColumnSizing,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
meta: {
|
meta: {
|
||||||
handleUpdate: async (rowIndex: number, accessor: string, payload: string, isCustom = false) => {
|
handleUpdate: (rowIndex: number, accessor: string, payload: string, isCustom = false) => {
|
||||||
// check if value is the same
|
// check if value is the same
|
||||||
const event = data[rowIndex];
|
const event = data[rowIndex];
|
||||||
if (!event || !isOntimeEvent(event)) {
|
if (!event || !isOntimeEvent(event)) {
|
||||||
@@ -82,6 +82,10 @@ export default function CuesheetTable(props: CuesheetTableProps) {
|
|||||||
|
|
||||||
updateEvent({ id: event.id, [accessor]: payload });
|
updateEvent({ id: event.id, [accessor]: payload });
|
||||||
},
|
},
|
||||||
|
handleUpdateTimer: (eventId: string, field: TimeField, payload) => {
|
||||||
|
// the timer element already contains logic to avoid submitting a unchanged value
|
||||||
|
updateTimer(eventId, field, payload, true);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -166,15 +170,6 @@ export default function CuesheetTable(props: CuesheetTableProps) {
|
|||||||
colour={entry.colour}
|
colour={entry.colour}
|
||||||
showIndexColumn={!hideIndexColumn}
|
showIndexColumn={!hideIndexColumn}
|
||||||
>
|
>
|
||||||
<td>
|
|
||||||
<MenuButton
|
|
||||||
as={IconButton}
|
|
||||||
size='sm'
|
|
||||||
aria-label='Options'
|
|
||||||
icon={<IoEllipsisHorizontal />}
|
|
||||||
variant='ontime-subtle'
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
{row.getVisibleCells().map((cell) => {
|
{row.getVisibleCells().map((cell) => {
|
||||||
return (
|
return (
|
||||||
<td key={cell.id} style={{ width: cell.column.getSize(), backgroundColor: rowBgColour }}>
|
<td key={cell.id} style={{ width: cell.column.getSize(), backgroundColor: rowBgColour }}>
|
||||||
|
|||||||
+1
-1
@@ -23,8 +23,8 @@ export default function CuesheetHeader(props: CuesheetHeaderProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<tr key={headerGroup.id}>
|
<tr key={headerGroup.id}>
|
||||||
<th className={style.indexColumn}>{showIndexColumn && '#'}</th>
|
|
||||||
<th className={style.actionColumn} />
|
<th className={style.actionColumn} />
|
||||||
|
<th className={style.indexColumn}>{showIndexColumn && '#'}</th>
|
||||||
<SortableContext key={key} items={headerGroup.headers} strategy={horizontalListSortingStrategy}>
|
<SortableContext key={key} items={headerGroup.headers} strategy={horizontalListSortingStrategy}>
|
||||||
{headerGroup.headers.map((header) => {
|
{headerGroup.headers.map((header) => {
|
||||||
const width = header.getSize();
|
const width = header.getSize();
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { memo, MutableRefObject, PropsWithChildren, useLayoutEffect, useRef, useState } from 'react';
|
import { memo, MutableRefObject, PropsWithChildren, useLayoutEffect, useRef, useState } from 'react';
|
||||||
|
import { IconButton, MenuButton } from '@chakra-ui/react';
|
||||||
|
import { IoEllipsisHorizontal } from '@react-icons/all-files/io5/IoEllipsisHorizontal';
|
||||||
import Color from 'color';
|
import Color from 'color';
|
||||||
|
|
||||||
import { cx, getAccessibleColour } from '../../../../common/utils/styleUtils';
|
import { cx, getAccessibleColour } from '../../../../common/utils/styleUtils';
|
||||||
@@ -55,6 +57,15 @@ function EventRow(props: PropsWithChildren<EventRowProps>) {
|
|||||||
style={{ opacity: `${isPast ? '0.2' : '1'}` }}
|
style={{ opacity: `${isPast ? '0.2' : '1'}` }}
|
||||||
ref={selectedRef ?? ownRef}
|
ref={selectedRef ?? ownRef}
|
||||||
>
|
>
|
||||||
|
<td className={style.actionColumn}>
|
||||||
|
<MenuButton
|
||||||
|
as={IconButton}
|
||||||
|
size='sm'
|
||||||
|
aria-label='Options'
|
||||||
|
icon={<IoEllipsisHorizontal />}
|
||||||
|
variant='ontime-subtle'
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
<td className={style.indexColumn} style={{ backgroundColor, color: mutedText }}>
|
<td className={style.indexColumn} style={{ backgroundColor, color: mutedText }}>
|
||||||
{showIndexColumn && eventIndex}
|
{showIndexColumn && eventIndex}
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user