mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 04:43:35 +00:00
1849b4d39f
* chore: migrate eslint to oxlint * chore: migrate prettier to oxfmt * chore: migrate typescript * chore: toThrow should have a expected value * chore: cast test value as Day * chore: small title fix * chore: mocks should be hoisted * chore: incorrect async useage * chore: test should be inside description * chore: test sohuld include an expeced * chore: oxfmt --------- Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
105 lines
2.6 KiB
TypeScript
105 lines
2.6 KiB
TypeScript
import { Toolbar } from '@base-ui/react/toolbar';
|
|
import { MaybeString, SupportedEntry } from 'ontime-types';
|
|
import { memo } from 'react';
|
|
import { IoAdd } from 'react-icons/io5';
|
|
|
|
import Button from '../../../../common/components/buttons/Button';
|
|
import { useEntryActionsContext } from '../../../../common/context/EntryActionsContext';
|
|
import { cx } from '../../../../common/utils/styleUtils';
|
|
|
|
import style from './QuickAddButtons.module.scss';
|
|
|
|
interface QuickAddButtonsProps {
|
|
previousEventId: MaybeString;
|
|
parentGroup: MaybeString;
|
|
backgroundColor?: string;
|
|
}
|
|
|
|
export default memo(QuickAddButtons);
|
|
function QuickAddButtons({ previousEventId, parentGroup, backgroundColor }: QuickAddButtonsProps) {
|
|
const { addEntry } = useEntryActionsContext();
|
|
|
|
const addEvent = () => {
|
|
addEntry(
|
|
{
|
|
type: SupportedEntry.Event,
|
|
parent: parentGroup,
|
|
},
|
|
{
|
|
after: previousEventId,
|
|
lastEventId: previousEventId,
|
|
},
|
|
);
|
|
};
|
|
|
|
const addDelay = () => {
|
|
addEntry(
|
|
{ type: SupportedEntry.Delay, parent: parentGroup },
|
|
{
|
|
lastEventId: previousEventId,
|
|
after: previousEventId,
|
|
},
|
|
);
|
|
};
|
|
|
|
const addMilestone = () => {
|
|
addEntry(
|
|
{ type: SupportedEntry.Milestone, parent: parentGroup },
|
|
{
|
|
lastEventId: previousEventId,
|
|
after: previousEventId,
|
|
},
|
|
);
|
|
};
|
|
|
|
const addGroup = () => {
|
|
if (parentGroup !== null) {
|
|
return;
|
|
}
|
|
addEntry(
|
|
{ type: SupportedEntry.Group },
|
|
{
|
|
lastEventId: previousEventId,
|
|
after: previousEventId,
|
|
},
|
|
);
|
|
};
|
|
|
|
/**
|
|
* If the colour is empty string ''
|
|
* ie: we are inside a group, but there is no defined colour
|
|
* we default to $gray-500 #9d9d9d
|
|
*/
|
|
const groupColour = backgroundColor === '' ? '#9d9d9d' : backgroundColor;
|
|
|
|
return (
|
|
<Toolbar.Root
|
|
className={cx([style.quickAdd, Boolean(parentGroup) && style.indent])}
|
|
style={groupColour ? { '--user-bg': groupColour } : {}}
|
|
data-testid='quick-add-buttons'
|
|
>
|
|
<Toolbar.Button render={<Button size='small' />} onClick={addEvent}>
|
|
<IoAdd />
|
|
Event
|
|
</Toolbar.Button>
|
|
|
|
<Toolbar.Button render={<Button size='small' />} onClick={addDelay}>
|
|
<IoAdd />
|
|
Delay
|
|
</Toolbar.Button>
|
|
|
|
<Toolbar.Button render={<Button size='small' />} onClick={addMilestone}>
|
|
<IoAdd />
|
|
Milestone
|
|
</Toolbar.Button>
|
|
|
|
{parentGroup === null && (
|
|
<Toolbar.Button render={<Button size='small' />} onClick={addGroup}>
|
|
<IoAdd />
|
|
Group
|
|
</Toolbar.Button>
|
|
)}
|
|
</Toolbar.Root>
|
|
);
|
|
}
|