mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-31 11:59:10 +00:00
refactor: improve memoisation on table rows
This commit is contained in:
committed by
Carlos Valente
parent
c8bae76121
commit
ab8da07518
+17
-15
@@ -1,7 +1,7 @@
|
|||||||
import { Table, flexRender } from '@tanstack/react-table';
|
import { Table, flexRender } from '@tanstack/react-table';
|
||||||
import { EntryId, OntimeEntry, RGBColour, SupportedEntry } from 'ontime-types';
|
import { EntryId, OntimeEntry, RGBColour, SupportedEntry } from 'ontime-types';
|
||||||
import { colourToHex, cssOrHexToColour } from 'ontime-utils';
|
import { colourToHex, cssOrHexToColour } from 'ontime-utils';
|
||||||
import { CSSProperties, useMemo } from 'react';
|
import { CSSProperties, memo, useMemo } from 'react';
|
||||||
import { IoEllipsisHorizontal } from 'react-icons/io5';
|
import { IoEllipsisHorizontal } from 'react-icons/io5';
|
||||||
|
|
||||||
import IconButton from '../../../../common/components/buttons/IconButton';
|
import IconButton from '../../../../common/components/buttons/IconButton';
|
||||||
@@ -30,7 +30,8 @@ interface EventRowProps {
|
|||||||
hasCursor?: boolean;
|
hasCursor?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function EventRow({
|
export default memo(EventRow);
|
||||||
|
function EventRow({
|
||||||
rowId,
|
rowId,
|
||||||
id,
|
id,
|
||||||
eventIndex,
|
eventIndex,
|
||||||
@@ -55,24 +56,25 @@ export default function EventRow({
|
|||||||
|
|
||||||
const openMenu = useCuesheetTableMenu((store) => store.openMenu);
|
const openMenu = useCuesheetTableMenu((store) => store.openMenu);
|
||||||
|
|
||||||
const { color, backgroundColor } = getAccessibleColour(colour);
|
const { rowBgColour, backgroundColor, mutedText } = useMemo(() => {
|
||||||
const tmpColour = cssOrHexToColour(color) as RGBColour; // we know this to be a correct colour
|
const accessible = getAccessibleColour(colour);
|
||||||
const mutedText = colourToHex({ ...tmpColour, alpha: tmpColour.alpha * 0.8 });
|
const tmpColour = cssOrHexToColour(accessible.color) as RGBColour;
|
||||||
|
|
||||||
const rowBgColour: string | undefined = useMemo(() => {
|
let rowBgColour: string | undefined;
|
||||||
if (isLoaded) {
|
if (isLoaded) {
|
||||||
return '#087A27'; // $active-green
|
rowBgColour = '#087A27'; // $active-green
|
||||||
} else if (colour) {
|
} else if (colour) {
|
||||||
// the colour is user defined and might be invalid
|
const accessibleBg = cssOrHexToColour(accessible.backgroundColor);
|
||||||
const accessibleBackgroundColor = cssOrHexToColour(getAccessibleColour(colour).backgroundColor);
|
if (accessibleBg !== null) {
|
||||||
if (accessibleBackgroundColor !== null) {
|
rowBgColour = colourToHex({ ...accessibleBg, alpha: accessibleBg.alpha * 0.25 });
|
||||||
return colourToHex({
|
|
||||||
...accessibleBackgroundColor,
|
|
||||||
alpha: accessibleBackgroundColor.alpha * 0.25,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
return {
|
||||||
|
rowBgColour,
|
||||||
|
backgroundColor: accessible.backgroundColor,
|
||||||
|
mutedText: colourToHex({ ...tmpColour, alpha: tmpColour.alpha * 0.8 }),
|
||||||
|
};
|
||||||
}, [colour, isLoaded]);
|
}, [colour, isLoaded]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Table, flexRender } from '@tanstack/react-table';
|
import { Table, flexRender } from '@tanstack/react-table';
|
||||||
import { EntryId, SupportedEntry } from 'ontime-types';
|
import { EntryId, SupportedEntry } from 'ontime-types';
|
||||||
import { CSSProperties } from 'react';
|
import { CSSProperties, memo } from 'react';
|
||||||
import { IoEllipsisHorizontal } from 'react-icons/io5';
|
import { IoEllipsisHorizontal } from 'react-icons/io5';
|
||||||
|
|
||||||
import IconButton from '../../../../common/components/buttons/IconButton';
|
import IconButton from '../../../../common/components/buttons/IconButton';
|
||||||
@@ -20,7 +20,8 @@ interface GroupRowProps {
|
|||||||
hasCursor?: boolean;
|
hasCursor?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GroupRow({
|
export default memo(GroupRow);
|
||||||
|
function GroupRow({
|
||||||
groupId,
|
groupId,
|
||||||
colour,
|
colour,
|
||||||
rowId,
|
rowId,
|
||||||
|
|||||||
+9
-13
@@ -1,7 +1,7 @@
|
|||||||
import { Table, flexRender } from '@tanstack/react-table';
|
import { Table, flexRender } from '@tanstack/react-table';
|
||||||
import { EntryId, SupportedEntry } from 'ontime-types';
|
import { EntryId, SupportedEntry } from 'ontime-types';
|
||||||
import { colourToHex, cssOrHexToColour } from 'ontime-utils';
|
import { colourToHex, cssOrHexToColour } from 'ontime-utils';
|
||||||
import { CSSProperties } from 'react';
|
import { CSSProperties, memo, useMemo } from 'react';
|
||||||
import { IoEllipsisHorizontal } from 'react-icons/io5';
|
import { IoEllipsisHorizontal } from 'react-icons/io5';
|
||||||
|
|
||||||
import IconButton from '../../../../common/components/buttons/IconButton';
|
import IconButton from '../../../../common/components/buttons/IconButton';
|
||||||
@@ -25,7 +25,8 @@ interface MilestoneRowProps {
|
|||||||
hasCursor?: boolean;
|
hasCursor?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MilestoneRow({
|
export default memo(MilestoneRow);
|
||||||
|
function MilestoneRow({
|
||||||
entryId,
|
entryId,
|
||||||
isPast,
|
isPast,
|
||||||
parentBgColour,
|
parentBgColour,
|
||||||
@@ -45,17 +46,12 @@ export default function MilestoneRow({
|
|||||||
|
|
||||||
const openMenu = useCuesheetTableMenu((store) => store.openMenu);
|
const openMenu = useCuesheetTableMenu((store) => store.openMenu);
|
||||||
|
|
||||||
let rowBgColour: string | undefined;
|
const rowBgColour = useMemo(() => {
|
||||||
if (colour) {
|
if (!colour) return undefined;
|
||||||
// the colour is user defined and might be invalid
|
const accessibleBg = cssOrHexToColour(getAccessibleColour(colour).backgroundColor);
|
||||||
const accessibleBackgroundColor = cssOrHexToColour(getAccessibleColour(colour).backgroundColor);
|
if (accessibleBg === null) return undefined;
|
||||||
if (accessibleBackgroundColor !== null) {
|
return colourToHex({ ...accessibleBg, alpha: accessibleBg.alpha * 0.25 });
|
||||||
rowBgColour = colourToHex({
|
}, [colour]);
|
||||||
...accessibleBackgroundColor,
|
|
||||||
alpha: accessibleBackgroundColor.alpha * 0.25,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr
|
<tr
|
||||||
|
|||||||
Reference in New Issue
Block a user