mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-19 22:24:11 +00:00
refactor: create hash of table state
This commit is contained in:
committed by
Carlos Valente
parent
9566fadbbb
commit
133b3aa819
@@ -104,7 +104,7 @@ export default function CuesheetTable(props: CuesheetTableProps) {
|
|||||||
<div ref={tableContainerRef} className={style.cuesheetContainer}>
|
<div ref={tableContainerRef} className={style.cuesheetContainer}>
|
||||||
<table className={style.cuesheet} id='cuesheet' {...listeners}>
|
<table className={style.cuesheet} id='cuesheet' {...listeners}>
|
||||||
<CuesheetHeader headerGroups={headerGroups} />
|
<CuesheetHeader headerGroups={headerGroups} />
|
||||||
<CuesheetBody rowModel={rowModel} selectedRef={selectedRef} table={table} columnSizing={columnSizing} />
|
<CuesheetBody rowModel={rowModel} selectedRef={selectedRef} table={table} />
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<CuesheetTableMenu showModal={showModal} />
|
<CuesheetTableMenu showModal={showModal} />
|
||||||
|
|||||||
+14
-5
@@ -16,16 +16,24 @@ interface CuesheetBodyProps {
|
|||||||
rowModel: RowModel<OntimeRundownEntry>;
|
rowModel: RowModel<OntimeRundownEntry>;
|
||||||
selectedRef: MutableRefObject<HTMLTableRowElement | null>;
|
selectedRef: MutableRefObject<HTMLTableRowElement | null>;
|
||||||
table: Table<OntimeRundownEntry>;
|
table: Table<OntimeRundownEntry>;
|
||||||
columnSizing: Record<string, number>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CuesheetBody(props: CuesheetBodyProps) {
|
export default function CuesheetBody(props: CuesheetBodyProps) {
|
||||||
const { rowModel, selectedRef, table, columnSizing } = props;
|
const { rowModel, selectedRef, table } = props;
|
||||||
|
|
||||||
const { selectedEventId } = useSelectedEventId();
|
const { selectedEventId } = useSelectedEventId();
|
||||||
const { hideDelays, hidePast } = useCuesheetOptions();
|
const { hideDelays, hidePast } = useCuesheetOptions();
|
||||||
|
|
||||||
const getColumnCount = lazyEvaluate(() => table.getVisibleFlatColumns().length);
|
const getVisibleColumns = lazyEvaluate(() => table.getVisibleFlatColumns());
|
||||||
|
const getColumnHash = lazyEvaluate(() => {
|
||||||
|
let columnHash = '';
|
||||||
|
const columns = getVisibleColumns();
|
||||||
|
|
||||||
|
for (let i = 0; i < columns.length; i++) {
|
||||||
|
columnHash += `${columns[i].getIndex()}-${columns[i].getSize()} `;
|
||||||
|
}
|
||||||
|
return columnHash;
|
||||||
|
});
|
||||||
|
|
||||||
let eventIndex = 0;
|
let eventIndex = 0;
|
||||||
// for the first event, it will be past if there is something selected
|
// for the first event, it will be past if there is something selected
|
||||||
@@ -41,7 +49,7 @@ export default function CuesheetBody(props: CuesheetBodyProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOntimeBlock(entry)) {
|
if (isOntimeBlock(entry)) {
|
||||||
const columnCount = getColumnCount();
|
const columnCount = getVisibleColumns().length;
|
||||||
return <BlockRow columnCount={columnCount} key={key} title={entry.title} hidePast={isPast && hidePast} />;
|
return <BlockRow columnCount={columnCount} key={key} title={entry.title} hidePast={isPast && hidePast} />;
|
||||||
}
|
}
|
||||||
if (isOntimeDelay(entry)) {
|
if (isOntimeDelay(entry)) {
|
||||||
@@ -58,6 +66,7 @@ export default function CuesheetBody(props: CuesheetBodyProps) {
|
|||||||
if (isOntimeEvent(entry)) {
|
if (isOntimeEvent(entry)) {
|
||||||
eventIndex++;
|
eventIndex++;
|
||||||
const isSelected = key === selectedEventId;
|
const isSelected = key === selectedEventId;
|
||||||
|
const columnHash = getColumnHash();
|
||||||
|
|
||||||
if (isPast && hidePast) {
|
if (isPast && hidePast) {
|
||||||
return null;
|
return null;
|
||||||
@@ -87,7 +96,7 @@ export default function CuesheetBody(props: CuesheetBodyProps) {
|
|||||||
selectedRef={isSelected ? selectedRef : undefined}
|
selectedRef={isSelected ? selectedRef : undefined}
|
||||||
rowBgColour={rowBgColour}
|
rowBgColour={rowBgColour}
|
||||||
table={table}
|
table={table}
|
||||||
columnSizing={columnSizing}
|
columnHash={columnHash}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ interface EventRowProps {
|
|||||||
rowBgColour?: string;
|
rowBgColour?: string;
|
||||||
table: Table<OntimeRundownEntry>;
|
table: Table<OntimeRundownEntry>;
|
||||||
/** hack to force re-rendering of the row when the column sizes change */
|
/** hack to force re-rendering of the row when the column sizes change */
|
||||||
columnSizing: Record<string, number>;
|
columnHash: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default memo(EventRow, (prevProps, nextProps) => {
|
export default memo(EventRow, (prevProps, nextProps) => {
|
||||||
@@ -35,8 +35,7 @@ export default memo(EventRow, (prevProps, nextProps) => {
|
|||||||
prevProps.isPast === nextProps.isPast &&
|
prevProps.isPast === nextProps.isPast &&
|
||||||
prevProps.selectedRef === nextProps.selectedRef &&
|
prevProps.selectedRef === nextProps.selectedRef &&
|
||||||
prevProps.rowBgColour === nextProps.rowBgColour &&
|
prevProps.rowBgColour === nextProps.rowBgColour &&
|
||||||
prevProps.table === nextProps.table &&
|
prevProps.columnHash === nextProps.columnHash
|
||||||
prevProps.columnSizing === nextProps.columnSizing
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user