Skip to content

Commit

Permalink
refactor: settings in params
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Dec 15, 2024
1 parent 893a81e commit 1ff2720
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 115 deletions.
4 changes: 4 additions & 0 deletions apps/client/src/features/viewers/common/viewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export function getTimerByType(freezeEnd: boolean, timerObject?: TimerTypeParams
}
}

/**
* Parses a string to semantically verify if it represents a true value
* Used in the context of parsing search params and local storage items which can be strings or null
*/
export function isStringBoolean(text: string | null) {
if (text === null) {
return false;
Expand Down
16 changes: 8 additions & 8 deletions apps/client/src/views/cuesheet/Cuesheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CuesheetHeader from './cuesheet-table-elements/CuesheetHeader';
import DelayRow from './cuesheet-table-elements/DelayRow';
import EventRow from './cuesheet-table-elements/EventRow';
import CuesheetTableSettings from './cuesheet-table-settings/CuesheetTableSettings';
import { useCuesheetSettings } from './store/cuesheetSettingsStore';
import { useCuesheetOptions } from './cuesheet.options';
import useColumnManager from './useColumnManager';

import style from './Cuesheet.module.scss';
Expand All @@ -25,7 +25,7 @@ interface CuesheetProps {
}

export default function Cuesheet({ data, columns, handleUpdate, selectedId, currentBlockId }: CuesheetProps) {
const { followSelected, showDelayBlock, showPrevious, showIndexColumn } = useCuesheetSettings();
const { followSelected, hideDelays, hidePast, hideIndexColumn } = useCuesheetOptions();
const {
columnVisibility,
columnOrder,
Expand Down Expand Up @@ -102,7 +102,7 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId, curr
/>
<div ref={tableContainerRef} className={style.cuesheetContainer}>
<table className={style.cuesheet}>
<CuesheetHeader headerGroups={headerGroups} saveColumnOrder={reorder} showIndexColumn={showIndexColumn} />
<CuesheetHeader headerGroups={headerGroups} saveColumnOrder={reorder} showIndexColumn={!hideIndexColumn} />
<tbody>
{rowModel.rows.map((row) => {
const key = row.original.id;
Expand All @@ -112,17 +112,17 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId, curr
}

if (isOntimeBlock(row.original)) {
if (isPast && !showPrevious && key !== currentBlockId) {
if (isPast && hidePast && key !== currentBlockId) {
return null;
}
return <BlockRow key={key} title={row.original.title} />;
}
if (isOntimeDelay(row.original)) {
if (isPast && !showPrevious) {
if (isPast && hidePast) {
return null;
}
const delayVal = row.original.duration;
if (!showDelayBlock || delayVal === 0) {
if (hideDelays || delayVal === 0) {
return null;
}

Expand All @@ -132,7 +132,7 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId, curr
eventIndex++;
const isSelected = key === selectedId;

if (isPast && !showPrevious) {
if (isPast && hidePast) {
return null;
}

Expand All @@ -157,7 +157,7 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId, curr
selectedRef={isSelected ? selectedRef : undefined}
skip={row.original.skip}
colour={row.original.colour}
showIndexColumn={showIndexColumn}
showIndexColumn={!hideIndexColumn}
>
{row.getVisibleCells().map((cell) => {
return (
Expand Down
15 changes: 12 additions & 3 deletions apps/client/src/views/cuesheet/CuesheetPage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useCallback, useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
import { IconButton, useDisclosure } from '@chakra-ui/react';
import { IoApps } from '@react-icons/all-files/io5/IoApps';
import { IoSettingsOutline } from '@react-icons/all-files/io5/IoSettingsOutline';
import { CustomFieldLabel, isOntimeEvent } from 'ontime-types';

import ProductionNavigationMenu from '../../common/components/navigation-menu/ProductionNavigationMenu';
import EmptyPage from '../../common/components/state/EmptyPage';
import ViewParamsEditor from '../../common/components/view-params-editor/ViewParamsEditor';
import { useEventAction } from '../../common/hooks/useEventAction';
import { useCuesheet } from '../../common/hooks/useSocket';
import { useWindowTitle } from '../../common/hooks/useWindowTitle';
Expand All @@ -14,8 +16,8 @@ import { useFlatRundown } from '../../common/hooks-query/useRundown';
import { CuesheetOverview } from '../../features/overview/Overview';

import CuesheetProgress from './cuesheet-progress/CuesheetProgress';
import { useCuesheetSettings } from './store/cuesheetSettingsStore';
import Cuesheet from './Cuesheet';
import { cuesheetOptions } from './cuesheet.options';
import { makeCuesheetColumns } from './cuesheetCols';

import styles from './CuesheetPage.module.scss';
Expand All @@ -24,15 +26,21 @@ export default function CuesheetPage() {
// TODO: can we use the normalised rundown for the table?
const { data: flatRundown, status: rundownStatus } = useFlatRundown();
const { data: customFields } = useCustomFields();
const [searchParams, setSearchParams] = useSearchParams();
const { isOpen: isMenuOpen, onOpen, onClose } = useDisclosure();

const { updateCustomField } = useEventAction();
const featureData = useCuesheet();
const columns = useMemo(() => makeCuesheetColumns(customFields), [customFields]);
const toggleSettings = useCuesheetSettings((state) => state.toggleSettings);

useWindowTitle('Cuesheet');

/** Handles showing the view params edit drawer */
const showEditFormDrawer = useCallback(() => {
searchParams.set('edit', 'true');
setSearchParams(searchParams);
}, [searchParams, setSearchParams]);

/**
* Handles updating a field
* Currently, only custom fields can be updated from the cuesheet
Expand Down Expand Up @@ -85,6 +93,7 @@ export default function CuesheetPage() {
return (
<div className={styles.tableWrapper} data-testid='cuesheet'>
<ProductionNavigationMenu isMenuOpen={isMenuOpen} onMenuClose={onClose} />
<ViewParamsEditor viewOptions={cuesheetOptions} />
<CuesheetOverview>
<IconButton
aria-label='Toggle navigation'
Expand All @@ -98,7 +107,7 @@ export default function CuesheetPage() {
variant='ontime-subtle-white'
size='lg'
icon={<IoSettingsOutline />}
onClick={() => toggleSettings()}
onClick={showEditFormDrawer}
/>
</CuesheetOverview>
<CuesheetProgress />
Expand Down
95 changes: 83 additions & 12 deletions apps/client/src/views/cuesheet/cuesheet.options.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,90 @@
import { OntimeEntryCommonKeys, OntimeEvent } from 'ontime-types';
import { useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';

import { ViewOption } from '../../common/components/view-params-editor/types';
import { isStringBoolean } from '../../features/viewers/common/viewUtils';

/**
* @description set default column order
* In the specific case of the cuesheet options
* we save the user preferences in the local storage
*/
export const defaultColumnOrder: OntimeEntryCommonKeys[] = [
'isPublic',
'cue',
'timeStart',
'timeEnd',
'duration',
'title',
'note',
export const cuesheetOptions: ViewOption[] = [
{ section: 'Table options' },
{
id: 'hideTableSeconds',
title: 'Hide seconds in table',
description: 'Whether to hide seconds in the time fields displayed in the table',
type: 'boolean',
defaultValue: false,
},
{
id: 'followSelected',
title: 'Follow selected event',
description: 'Whether the view should automatically scroll to the selected event',
type: 'boolean',
defaultValue: false,
},
{
id: 'hidePast',
title: 'Hide Past Events',
description: 'Whether to hide events that have passed',
type: 'boolean',
defaultValue: false,
},
{
id: 'hideIndexColumn',
title: 'Hide index column',
description: 'Whether the hide the event indexes in the table',
type: 'boolean',
defaultValue: false,
},
{ section: 'Delay flow' },
{
id: 'showDelayedTimes',
title: 'Show delayed times',
description: 'Whether the time fields should include delays',
type: 'boolean',
defaultValue: false,
},
{
id: 'hideDelays',
title: 'Hide delays',
description: 'Whether to hide the rows containing scheduled delays',
type: 'boolean',
defaultValue: false,
},
];

type CuesheetOptions = {
hideTableSeconds: boolean;
followSelected: boolean;
hidePast: boolean;
hideIndexColumn: boolean;
showDelayedTimes: boolean;
hideDelays: boolean;
};

/**
* Utility extract the view options from URL Params
* the names and fallbacks are manually matched with cuesheetOptions
*/
export function getOptionsFromParams(searchParams: URLSearchParams): CuesheetOptions {
// we manually make an object that matches the key above
return {
hideTableSeconds: isStringBoolean(searchParams.get('hideTableSeconds')),
followSelected: isStringBoolean(searchParams.get('followSelected')),
hidePast: isStringBoolean(searchParams.get('hidePast')),
hideIndexColumn: isStringBoolean(searchParams.get('hideIndexColumn')),
showDelayedTimes: isStringBoolean(searchParams.get('showDelayedTimes')),
hideDelays: isStringBoolean(searchParams.get('hideDelays')),
};
}

/**
* @description set default hidden columns
* Hook exposes the cuesheet view options
*/
export const defaultHiddenColumns: (keyof OntimeEvent)[] = [];
export function useCuesheetOptions(): CuesheetOptions {
const [searchParams] = useSearchParams();
const options = useMemo(() => getOptionsFromParams(searchParams), [searchParams]);
return options;
}
13 changes: 6 additions & 7 deletions apps/client/src/views/cuesheet/cuesheetCols.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DelayIndicator from '../../common/components/delay-indicator/DelayIndicat
import RunningTime from '../../features/viewers/common/running-time/RunningTime';

import EditableCell from './cuesheet-table-elements/EditableCell';
import { useCuesheetSettings } from './store/cuesheetSettingsStore';
import { useCuesheetOptions } from './cuesheet.options';

import style from './Cuesheet.module.scss';

Expand All @@ -17,27 +17,26 @@ function makePublic(row: CellContext<OntimeRundownEntry, unknown>) {
}

function MakeTimer({ getValue, row: { original } }: CellContext<OntimeRundownEntry, unknown>) {
const showDelayedTimes = useCuesheetSettings((state) => state.showDelayedTimes);
const hideSeconds = useCuesheetSettings((state) => state.hideSeconds);
const { showDelayedTimes, hideTableSeconds } = useCuesheetOptions();
const cellValue = (getValue() as number | null) ?? 0;
const delayValue = (original as OntimeEvent)?.delay ?? 0;

return (
<span className={style.time}>
<DelayIndicator delayValue={delayValue} />
<RunningTime value={cellValue} hideSeconds={hideSeconds} />
<RunningTime value={cellValue} hideSeconds={hideTableSeconds} />
{delayValue !== 0 && showDelayedTimes && (
<RunningTime className={style.delayedTime} value={cellValue + delayValue} hideSeconds={hideSeconds} />
<RunningTime className={style.delayedTime} value={cellValue + delayValue} hideSeconds={hideTableSeconds} />
)}
</span>
);
}

function MakeDuration({ getValue }: CellContext<OntimeRundownEntry, unknown>) {
const hideSeconds = useCuesheetSettings((state) => state.hideSeconds);
const { hideTableSeconds } = useCuesheetOptions();
const cellValue = (getValue() as number | null) ?? 0;

return <RunningTime value={cellValue} hideSeconds={hideSeconds} />;
return <RunningTime value={cellValue} hideSeconds={hideTableSeconds} />;
}

function MakeCustomField({ row, column, table }: CellContext<OntimeRundownEntry, unknown>) {
Expand Down
85 changes: 0 additions & 85 deletions apps/client/src/views/cuesheet/store/cuesheetSettingsStore.tsx

This file was deleted.

0 comments on commit 1ff2720

Please sign in to comment.