mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
refactor: small ux improvements
- rename dissolve > ungroup - prevent ondrag when clicking - add untitled as block title fallback - move block action to context menu
This commit is contained in:
committed by
Carlos Valente
parent
b0e42811a5
commit
256755bf02
@@ -97,8 +97,8 @@ export async function postCloneEntry(entryId: EntryId): Promise<AxiosResponse<Ru
|
|||||||
/**
|
/**
|
||||||
* HTTP request for dissolving of a block
|
* HTTP request for dissolving of a block
|
||||||
*/
|
*/
|
||||||
export async function requestDissolveBlock(blockId: EntryId): Promise<AxiosResponse<Rundown>> {
|
export async function requestUngroup(blockId: EntryId): Promise<AxiosResponse<Rundown>> {
|
||||||
return axios.post(`${rundownPath}/dissolve/${blockId}`);
|
return axios.post(`${rundownPath}/ungroup/${blockId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import {
|
|||||||
ReorderEntry,
|
ReorderEntry,
|
||||||
requestApplyDelay,
|
requestApplyDelay,
|
||||||
requestDeleteAll,
|
requestDeleteAll,
|
||||||
requestDissolveBlock,
|
|
||||||
requestEventSwap,
|
requestEventSwap,
|
||||||
requestGroupEntries,
|
requestGroupEntries,
|
||||||
|
requestUngroup,
|
||||||
SwapEntry,
|
SwapEntry,
|
||||||
} from '../api/rundown';
|
} from '../api/rundown';
|
||||||
import { logAxiosError } from '../api/utils';
|
import { logAxiosError } from '../api/utils';
|
||||||
@@ -544,8 +544,8 @@ export const useEntryActions = () => {
|
|||||||
* Calls mutation to dissolve a block
|
* Calls mutation to dissolve a block
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
const _dissolveBlockMutation = useMutation({
|
const _ungroupMutation = useMutation({
|
||||||
mutationFn: requestDissolveBlock,
|
mutationFn: requestUngroup,
|
||||||
onSuccess: (response) => {
|
onSuccess: (response) => {
|
||||||
if (!response.data) return;
|
if (!response.data) return;
|
||||||
|
|
||||||
@@ -565,15 +565,15 @@ export const useEntryActions = () => {
|
|||||||
/**
|
/**
|
||||||
* Deletes a block and moves its events to the top level
|
* Deletes a block and moves its events to the top level
|
||||||
*/
|
*/
|
||||||
const dissolveBlock = useCallback(
|
const ungroup = useCallback(
|
||||||
async (blockId: EntryId) => {
|
async (blockId: EntryId) => {
|
||||||
try {
|
try {
|
||||||
await _dissolveBlockMutation.mutateAsync(blockId);
|
await _ungroupMutation.mutateAsync(blockId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logAxiosError('Error dissolving block', error);
|
logAxiosError('Error dissolving block', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[_dissolveBlockMutation],
|
[_ungroupMutation],
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -762,7 +762,7 @@ export const useEntryActions = () => {
|
|||||||
clone,
|
clone,
|
||||||
deleteEntry,
|
deleteEntry,
|
||||||
deleteAllEntries,
|
deleteAllEntries,
|
||||||
dissolveBlock,
|
ungroup,
|
||||||
getEntryById,
|
getEntryById,
|
||||||
groupEntries,
|
groupEntries,
|
||||||
reorderEntry,
|
reorderEntry,
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export default function Rundown({ data }: RundownProps) {
|
|||||||
useFollowComponent({ followRef: cursorRef, scrollRef, doFollow: appMode === AppMode.Run });
|
useFollowComponent({ followRef: cursorRef, scrollRef, doFollow: appMode === AppMode.Run });
|
||||||
|
|
||||||
// DND KIT
|
// DND KIT
|
||||||
const sensors = useSensors(useSensor(PointerSensor));
|
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 10 } }));
|
||||||
|
|
||||||
const deleteAtCursor = useCallback(
|
const deleteAtCursor = useCallback(
|
||||||
(cursor: string | null) => {
|
(cursor: string | null) => {
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ import {
|
|||||||
IoChevronDown,
|
IoChevronDown,
|
||||||
IoChevronUp,
|
IoChevronUp,
|
||||||
IoDuplicateOutline,
|
IoDuplicateOutline,
|
||||||
IoEllipsisHorizontal,
|
|
||||||
IoFolderOpenOutline,
|
IoFolderOpenOutline,
|
||||||
IoReorderTwo,
|
IoReorderTwo,
|
||||||
IoTrash,
|
IoTrash,
|
||||||
} from 'react-icons/io5';
|
} from 'react-icons/io5';
|
||||||
import { IconButton, Menu, MenuButton, MenuItem, MenuList, Portal } from '@chakra-ui/react';
|
import { IconButton } from '@chakra-ui/react';
|
||||||
import { useSortable } from '@dnd-kit/sortable';
|
import { useSortable } from '@dnd-kit/sortable';
|
||||||
import { CSS } from '@dnd-kit/utilities';
|
import { CSS } from '@dnd-kit/utilities';
|
||||||
import { EntryId, OntimeBlock } from 'ontime-types';
|
import { EntryId, OntimeBlock } from 'ontime-types';
|
||||||
|
|
||||||
|
import { useContextMenu } from '../../../common/hooks/useContextMenu';
|
||||||
import { useEntryActions } from '../../../common/hooks/useEntryAction';
|
import { useEntryActions } from '../../../common/hooks/useEntryAction';
|
||||||
import { cx, getAccessibleColour } from '../../../common/utils/styleUtils';
|
import { cx, getAccessibleColour } from '../../../common/utils/styleUtils';
|
||||||
import { formatDuration, formatTime } from '../../../common/utils/time';
|
import { formatDuration, formatTime } from '../../../common/utils/time';
|
||||||
@@ -31,7 +31,27 @@ interface BlockBlockProps {
|
|||||||
export default function BlockBlock(props: BlockBlockProps) {
|
export default function BlockBlock(props: BlockBlockProps) {
|
||||||
const { data, hasCursor, collapsed, onCollapse } = props;
|
const { data, hasCursor, collapsed, onCollapse } = props;
|
||||||
const handleRef = useRef<null | HTMLSpanElement>(null);
|
const handleRef = useRef<null | HTMLSpanElement>(null);
|
||||||
const { clone, dissolveBlock, deleteEntry } = useEntryActions();
|
const { clone, ungroup, deleteEntry } = useEntryActions();
|
||||||
|
|
||||||
|
const [onContextMenu] = useContextMenu<HTMLDivElement>([
|
||||||
|
{
|
||||||
|
label: 'Clone Block',
|
||||||
|
icon: IoDuplicateOutline,
|
||||||
|
onClick: () => clone(data.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Ungroup',
|
||||||
|
icon: IoFolderOpenOutline,
|
||||||
|
onClick: () => ungroup(data.id),
|
||||||
|
isDisabled: data.events.length === 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Delete Block',
|
||||||
|
icon: IoTrash,
|
||||||
|
onClick: () => deleteEntry([data.id]),
|
||||||
|
withDivider: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
attributes: dragAttributes,
|
attributes: dragAttributes,
|
||||||
@@ -60,12 +80,11 @@ export default function BlockBlock(props: BlockBlockProps) {
|
|||||||
cursor: isOver ? (isValidDrop ? 'grabbing' : 'no-drop') : 'default',
|
cursor: isOver ? (isValidDrop ? 'grabbing' : 'no-drop') : 'default',
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasChildren = data.events.length > 0;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cx([style.block, hasCursor && style.hasCursor, !collapsed && style.expanded])}
|
className={cx([style.block, hasCursor && style.hasCursor, !collapsed && style.expanded])}
|
||||||
ref={setNodeRef}
|
ref={setNodeRef}
|
||||||
|
onContextMenu={onContextMenu}
|
||||||
style={{
|
style={{
|
||||||
...(binderColours ? { '--user-bg': binderColours.backgroundColor } : {}),
|
...(binderColours ? { '--user-bg': binderColours.backgroundColor } : {}),
|
||||||
...dragStyle,
|
...dragStyle,
|
||||||
@@ -84,31 +103,6 @@ export default function BlockBlock(props: BlockBlockProps) {
|
|||||||
<div className={style.header}>
|
<div className={style.header}>
|
||||||
<div className={style.titleRow}>
|
<div className={style.titleRow}>
|
||||||
<EditableBlockTitle title={data.title} eventId={data.id} placeholder='Block title' />
|
<EditableBlockTitle title={data.title} eventId={data.id} placeholder='Block title' />
|
||||||
<Menu variant='ontime-on-dark' size='sm'>
|
|
||||||
<MenuButton
|
|
||||||
as={IconButton}
|
|
||||||
aria-label='Options'
|
|
||||||
icon={<IoEllipsisHorizontal />}
|
|
||||||
color='#e2e2e2' // $gray-200
|
|
||||||
variant='ontime-ghosted'
|
|
||||||
size='sm'
|
|
||||||
/>
|
|
||||||
<Portal>
|
|
||||||
<MenuList>
|
|
||||||
<MenuItem icon={<IoDuplicateOutline />} onClick={() => clone(data.id)}>
|
|
||||||
Clone Block
|
|
||||||
</MenuItem>
|
|
||||||
{hasChildren && (
|
|
||||||
<MenuItem icon={<IoFolderOpenOutline />} onClick={() => dissolveBlock(data.id)}>
|
|
||||||
Dissolve Block
|
|
||||||
</MenuItem>
|
|
||||||
)}
|
|
||||||
<MenuItem icon={<IoTrash />} onClick={() => deleteEntry([data.id])}>
|
|
||||||
Delete Block
|
|
||||||
</MenuItem>
|
|
||||||
</MenuList>
|
|
||||||
</Portal>
|
|
||||||
</Menu>
|
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label='Collapse'
|
aria-label='Collapse'
|
||||||
onClick={() => onCollapse(!collapsed, data.id)}
|
onClick={() => onCollapse(!collapsed, data.id)}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
deleteAllEntries,
|
deleteAllEntries,
|
||||||
deleteEvent,
|
deleteEvent,
|
||||||
editEvent,
|
editEvent,
|
||||||
dissolveBlock,
|
ungroupEntries,
|
||||||
groupEntries,
|
groupEntries,
|
||||||
reorderEntry,
|
reorderEntry,
|
||||||
swapEvents,
|
swapEvents,
|
||||||
@@ -139,9 +139,9 @@ export async function rundownCloneEntry(req: Request, res: Response<Rundown | Er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function rundownDissolveBlock(req: Request, res: Response<Rundown | ErrorResponse>) {
|
export async function rundownUngroupEntries(req: Request, res: Response<Rundown | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
const newRundown = await dissolveBlock(req.params.entryId);
|
const newRundown = await ungroupEntries(req.params.entryId);
|
||||||
res.status(200).send(newRundown);
|
res.status(200).send(newRundown);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = getErrorMessage(error);
|
const message = getErrorMessage(error);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
rundownBatchPut,
|
rundownBatchPut,
|
||||||
rundownCloneEntry,
|
rundownCloneEntry,
|
||||||
rundownDelete,
|
rundownDelete,
|
||||||
rundownDissolveBlock,
|
rundownUngroupEntries,
|
||||||
rundownGetAll,
|
rundownGetAll,
|
||||||
rundownGetById,
|
rundownGetById,
|
||||||
rundownGetCurrent,
|
rundownGetCurrent,
|
||||||
@@ -41,7 +41,7 @@ router.patch('/reorder/', rundownReorderValidator, rundownReorder);
|
|||||||
router.patch('/swap', rundownSwapValidator, rundownSwap);
|
router.patch('/swap', rundownSwapValidator, rundownSwap);
|
||||||
router.patch('/applydelay/:entryId', paramsMustHaveEntryId, rundownApplyDelay);
|
router.patch('/applydelay/:entryId', paramsMustHaveEntryId, rundownApplyDelay);
|
||||||
router.post('/clone/:entryId', paramsMustHaveEntryId, rundownCloneEntry);
|
router.post('/clone/:entryId', paramsMustHaveEntryId, rundownCloneEntry);
|
||||||
router.post('/dissolve/:entryId', paramsMustHaveEntryId, rundownDissolveBlock);
|
router.post('/ungroup/:entryId', paramsMustHaveEntryId, rundownUngroupEntries);
|
||||||
router.post('/group', rundownArrayOfIds, rundownAddToBlock);
|
router.post('/group', rundownArrayOfIds, rundownAddToBlock);
|
||||||
|
|
||||||
router.delete('/', rundownArrayOfIds, deletesEventById);
|
router.delete('/', rundownArrayOfIds, deletesEventById);
|
||||||
|
|||||||
@@ -244,8 +244,8 @@ export async function cloneEntry(entryId: EntryId) {
|
|||||||
/**
|
/**
|
||||||
* Deletes a block from the rundown and moves all its children to the top level
|
* Deletes a block from the rundown and moves all its children to the top level
|
||||||
*/
|
*/
|
||||||
export async function dissolveBlock(blockId: EntryId) {
|
export async function ungroupEntries(blockId: EntryId) {
|
||||||
const scopedMutation = cache.mutateCache(cache.dissolveBlock);
|
const scopedMutation = cache.mutateCache(cache.ungroup);
|
||||||
const { newRundown } = await scopedMutation({ blockId });
|
const { newRundown } = await scopedMutation({ blockId });
|
||||||
|
|
||||||
// notify runtime that rundown has changed
|
// notify runtime that rundown has changed
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
editCustomField,
|
editCustomField,
|
||||||
removeCustomField,
|
removeCustomField,
|
||||||
customFieldChangelog,
|
customFieldChangelog,
|
||||||
dissolveBlock,
|
ungroup,
|
||||||
groupEntries,
|
groupEntries,
|
||||||
clone,
|
clone,
|
||||||
} from '../rundownCache.js';
|
} from '../rundownCache.js';
|
||||||
@@ -870,7 +870,7 @@ describe('clone() mutation', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('dissolveBlock() mutation', () => {
|
describe('ungroup() mutation', () => {
|
||||||
it('should correctly dissolve a block into its events', () => {
|
it('should correctly dissolve a block into its events', () => {
|
||||||
const rundown = makeRundown({
|
const rundown = makeRundown({
|
||||||
order: ['1', '2'],
|
order: ['1', '2'],
|
||||||
@@ -883,7 +883,7 @@ describe('dissolveBlock() mutation', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { newRundown } = dissolveBlock({
|
const { newRundown } = ungroup({
|
||||||
rundown,
|
rundown,
|
||||||
blockId: '2',
|
blockId: '2',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -594,7 +594,7 @@ export function clone({ rundown, entryId }: CloneEntryArgs): MutatingReturn {
|
|||||||
const flatIndex = rundown.flatOrder.indexOf(lastNestedIdInOriginal) + 1;
|
const flatIndex = rundown.flatOrder.indexOf(lastNestedIdInOriginal) + 1;
|
||||||
|
|
||||||
newBlock.events = nestedIds;
|
newBlock.events = nestedIds;
|
||||||
newBlock.title = `${entry.title} (copy)`;
|
newBlock.title = `${entry.title || 'Untitled'} (copy)`;
|
||||||
|
|
||||||
rundown.entries[newBlock.id] = newBlock;
|
rundown.entries[newBlock.id] = newBlock;
|
||||||
rundown.order = insertAtIndex(atIndex, newBlock.id, rundown.order);
|
rundown.order = insertAtIndex(atIndex, newBlock.id, rundown.order);
|
||||||
@@ -606,13 +606,13 @@ export function clone({ rundown, entryId }: CloneEntryArgs): MutatingReturn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DissolveBlockArgs = MutationParams<{ blockId: EntryId }>;
|
type UngroupArgs = MutationParams<{ blockId: EntryId }>;
|
||||||
/**
|
/**
|
||||||
* Deletes a block and moves all its children to the top level order
|
* Deletes a block and moves all its children to the top level order
|
||||||
* Mutates the given rundown
|
* Mutates the given rundown
|
||||||
* @throws if block ID not found
|
* @throws if block ID not found
|
||||||
*/
|
*/
|
||||||
export function dissolveBlock({ rundown, blockId }: DissolveBlockArgs): MutatingReturn {
|
export function ungroup({ rundown, blockId }: UngroupArgs): MutatingReturn {
|
||||||
const block = rundown.entries[blockId];
|
const block = rundown.entries[blockId];
|
||||||
if (!isOntimeBlock(block)) {
|
if (!isOntimeBlock(block)) {
|
||||||
throw new Error('Block with ID not found');
|
throw new Error('Block with ID not found');
|
||||||
|
|||||||
Reference in New Issue
Block a user