refactor: migrate related components

This commit is contained in:
Carlos Valente
2025-07-03 09:00:00 +02:00
committed by Carlos Valente
parent cd8e014f08
commit 84b73fc02a
23 changed files with 346 additions and 277 deletions
@@ -81,6 +81,25 @@
} }
.ghosted { .ghosted {
background: transparent;
color: $blue-500;
&:hover:not(:disabled):not(:active) {
background: $gray-1000;
color: $blue-500;
}
&:active:not(:disabled) {
background: $gray-1100;
border-color: $gray-1250;
}
&:disabled {
opacity: $opacity-disabled;
}
}
.ghosted-white {
background: transparent; background: transparent;
color: $ui-white; color: $ui-white;
@@ -2,6 +2,7 @@
@import './BaseButtonStyles.module.scss'; @import './BaseButtonStyles.module.scss';
.baseButton { .baseButton {
position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@@ -25,6 +26,36 @@
outline: 2px solid $blue-500; outline: 2px solid $blue-500;
outline-offset: 2px; outline-offset: 2px;
} }
&.loading {
cursor: wait;
.content {
opacity: 0;
}
}
}
.content {
display: flex;
align-items: center;
gap: inherit;
}
.loadingOverlay {
position: absolute;
display: grid;
place-content: center;
}
.spinner {
animation: spin 1s linear infinite;
stroke-dasharray: 8;
}
@keyframes spin {
100% {
transform: rotate(360deg);
}
} }
.small { .small {
@@ -1,29 +1,44 @@
import { ButtonHTMLAttributes, forwardRef } from 'react'; import { ButtonHTMLAttributes, forwardRef } from 'react';
import { IoEllipseOutline } from 'react-icons/io5';
import { cx } from '../../utils/styleUtils'; import { cx } from '../../utils/styleUtils';
import style from './Button.module.scss'; import style from './Button.module.scss';
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'subtle' | 'subtle-white' | 'destructive' | 'subtle-destructive' | 'ghosted'; variant?: 'primary' | 'subtle' | 'subtle-white' | 'destructive' | 'subtle-destructive' | 'ghosted' | 'ghosted-white';
size?: 'small' | 'medium' | 'large' | 'xlarge'; size?: 'small' | 'medium' | 'large' | 'xlarge';
fluid?: boolean; fluid?: boolean;
loading?: boolean;
} }
const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => { const Button = forwardRef<HTMLButtonElement, ButtonProps>(
const { className, children, variant = 'subtle', size = 'medium', fluid, ...buttonProps } = props; ({ className, children, variant = 'subtle', size = 'medium', fluid, loading, ...buttonProps }, ref) => {
return (
return ( <button
<button ref={ref}
ref={ref} className={cx([
className={cx([style.baseButton, style[variant], style[size], fluid && style.fluid, className])} style.baseButton,
type='button' style[variant],
{...buttonProps} style[size],
> fluid && style.fluid,
{children} loading && style.loading,
</button> className,
); ])}
}); type='button'
disabled={loading || buttonProps.disabled}
{...buttonProps}
>
<span className={style.content}>{children}</span>
{loading && (
<div className={style.loadingOverlay}>
<IoEllipseOutline className={style.spinner} />
</div>
)}
</button>
);
},
);
Button.displayName = 'Button'; Button.displayName = 'Button';
@@ -5,7 +5,7 @@ import { cx } from '../../utils/styleUtils';
import style from './IconButton.module.scss'; import style from './IconButton.module.scss';
interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'subtle' | 'subtle-white' | 'destructive' | 'subtle-destructive' | 'ghosted'; variant?: 'primary' | 'subtle' | 'subtle-white' | 'destructive' | 'subtle-destructive' | 'ghosted' | 'ghosted-white';
size?: 'small' | 'medium' | 'large' | 'xlarge'; size?: 'small' | 'medium' | 'large' | 'xlarge';
} }
@@ -0,0 +1,47 @@
@use '../../../../theme/viewerDefs' as *;
.textarea {
box-sizing: border-box;
display: block;
font-size: 1rem;
font-weight: 400;
color: $gray-200;
border-radius: $component-border-radius-md;
border: 1px solid transparent;
padding-inline: 0.5em;
outline: none;
&:hover:not(:disabled) {
background-color: $gray-1100;
}
&:focus:not(:read-only) {
background-color: $gray-1000;
border: 1px solid $blue-500;
}
&:disabled {
opacity: 0.4;
cursor: not-allowed;
}
&::placeholder {
color: $gray-500;
letter-spacing: 0;
}
}
.subtle {
background-color: $gray-1200;
}
.ghosted {
background-color: transparent;
padding: 0;
}
.fluid {
width: 100%;
}
@@ -0,0 +1,31 @@
import { forwardRef, TextareaHTMLAttributes } from 'react';
import { cx } from '../../../utils/styleUtils';
import style from './Textarea.module.scss';
export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
variant?: 'subtle' | 'ghosted';
fluid?: boolean;
resize?: 'none' | 'both' | 'horizontal' | 'vertical';
}
const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(function TextArea(
{ className, variant = 'subtle', fluid, rows = 5, resize = 'none', style: customStyle, ...textareaProps },
ref,
) {
return (
<textarea
ref={ref}
autoCorrect='off'
autoComplete='off'
spellCheck='false'
rows={rows}
style={{ ...customStyle, resize }}
className={cx([style.textarea, style[variant], fluid && style.fluid, className])}
{...textareaProps}
/>
);
});
export default Textarea;
@@ -17,11 +17,11 @@
font-size: calc(1rem - 2px); font-size: calc(1rem - 2px);
white-space: nowrap; white-space: nowrap;
&:hover:not(:disabled) { &:hover:not([data-disabled]) {
background-color: $gray-1100; background-color: $gray-1100;
} }
&:active { &:active:not([data-disabled]) {
background-color: $gray-1000; background-color: $gray-1000;
} }
@@ -29,7 +29,7 @@
background-color: $gray-1000; background-color: $gray-1000;
} }
&:disabled { &[data-disabled] {
opacity: 0.4; opacity: 0.4;
cursor: not-allowed; cursor: not-allowed;
} }
@@ -4,25 +4,17 @@ import { Select as BaseSelect } from '@base-ui-components/react/select';
import styles from './Select.module.scss'; import styles from './Select.module.scss';
interface SelectProps<T extends string | null = string> { interface SelectProps<T> extends Omit<BaseSelect.Root.Props<T>, 'items'> {
defaultValue?: T; // overload items to not allow undefined values
options: { options: {
value: NonNullable<T>; value: T;
label: string; label: string;
disabled?: boolean; // exposed to allow creating a non-selectable option
}[]; }[];
value?: T;
onChange?: (value: NonNullable<T>) => void;
} }
export default function Select<T extends string | null = string>({ export default function Select<T>({ options, ...selectRootProps }: SelectProps<T>) {
defaultValue,
options,
value,
onChange,
}: SelectProps<T>) {
return ( return (
<BaseSelect.Root items={options} defaultValue={defaultValue} onValueChange={onChange} value={value}> <BaseSelect.Root items={options} {...selectRootProps}>
<BaseSelect.Trigger className={styles.select}> <BaseSelect.Trigger className={styles.select}>
<BaseSelect.Value /> <BaseSelect.Value />
<BaseSelect.Icon className={styles.selectIcon}> <BaseSelect.Icon className={styles.selectIcon}>
@@ -33,16 +25,14 @@ export default function Select<T extends string | null = string>({
<BaseSelect.Positioner side='bottom' align='start'> <BaseSelect.Positioner side='bottom' align='start'>
<BaseSelect.ScrollUpArrow className={styles.scrollArrow} /> <BaseSelect.ScrollUpArrow className={styles.scrollArrow} />
<BaseSelect.Popup className={styles.popup}> <BaseSelect.Popup className={styles.popup}>
{options.map((option) => { {options.map(({ label, value }) => (
return ( <BaseSelect.Item key={String(value)} className={styles.item} value={value}>
<BaseSelect.Item key={option.value} className={styles.item} value={option.value}> <BaseSelect.ItemIndicator className={styles.itemIndicator}>
<BaseSelect.ItemIndicator className={styles.itemIndicator}> <IoCheckmark className={styles.itemIndicatorIcon} />
<IoCheckmark className={styles.itemIndicatorIcon} /> </BaseSelect.ItemIndicator>
</BaseSelect.ItemIndicator> <BaseSelect.ItemText className={styles.itemLabel}>{label}</BaseSelect.ItemText>
<BaseSelect.ItemText className={styles.itemLabel}>{option.label}</BaseSelect.ItemText> </BaseSelect.Item>
</BaseSelect.Item> ))}
);
})}
</BaseSelect.Popup> </BaseSelect.Popup>
<BaseSelect.ScrollDownArrow className={styles.scrollArrow} /> <BaseSelect.ScrollDownArrow className={styles.scrollArrow} />
</BaseSelect.Positioner> </BaseSelect.Positioner>
@@ -1,6 +1,7 @@
import { PropsWithChildren } from 'react'; import { PropsWithChildren } from 'react';
import { IoClose } from 'react-icons/io5'; import { IoClose } from 'react-icons/io5';
import { Button } from '@chakra-ui/react';
import Button from '../../../common/components/buttons/Button';
import style from './PanelContent.module.scss'; import style from './PanelContent.module.scss';
@@ -8,14 +9,12 @@ interface PanelContentProps {
onClose: () => void; onClose: () => void;
} }
export default function PanelContent(props: PropsWithChildren<PanelContentProps>) { export default function PanelContent({ onClose, children }: PropsWithChildren<PanelContentProps>) {
const { onClose, children } = props;
return ( return (
<div className={style.contentWrapper}> <div className={style.contentWrapper}>
<div className={style.corner}> <div className={style.corner}>
<Button onClick={onClose} aria-label='close' rightIcon={<IoClose />} variant='ontime-subtle'> <Button size='large' onClick={onClose}>
Close settings Close settings <IoClose />
</Button> </Button>
</div> </div>
<div className={style.content}>{children}</div> <div className={style.content}>{children}</div>
@@ -1,11 +1,13 @@
import { useState } from 'react'; import { useMemo, useState } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import QRCode from 'react-qr-code'; import QRCode from 'react-qr-code';
import { Button, Select, Switch } from '@chakra-ui/react';
import { generateUrl } from '../../../../common/api/session'; import { generateUrl } from '../../../../common/api/session';
import { maybeAxiosError } from '../../../../common/api/utils'; import { maybeAxiosError } from '../../../../common/api/utils';
import Button from '../../../../common/components/buttons/Button';
import Info from '../../../../common/components/info/Info'; import Info from '../../../../common/components/info/Info';
import Select from '../../../../common/components/select/Select';
import Switch from '../../../../common/components/switch/Switch';
import useInfo from '../../../../common/hooks-query/useInfo'; import useInfo from '../../../../common/hooks-query/useInfo';
import useUrlPresets from '../../../../common/hooks-query/useUrlPresets'; import useUrlPresets from '../../../../common/hooks-query/useUrlPresets';
import copyToClipboard from '../../../../common/utils/copyToClipboard'; import copyToClipboard from '../../../../common/utils/copyToClipboard';
@@ -33,14 +35,15 @@ export default function GenerateLinkForm() {
const { const {
handleSubmit, handleSubmit,
register,
setError, setError,
watch,
setValue,
formState: { errors }, formState: { errors },
} = useForm<GenerateLinkFormOptions>({ } = useForm<GenerateLinkFormOptions>({
mode: 'onChange', mode: 'onChange',
defaultValues: { defaultValues: {
baseUrl: currentHostName, baseUrl: currentHostName,
path: '', path: 'timer',
lock: false, lock: false,
authenticate: false, authenticate: false,
}, },
@@ -67,6 +70,29 @@ export default function GenerateLinkForm() {
} }
}; };
const hostOptions = useMemo(
() =>
infoData.networkInterfaces.map((nif) => ({
value: nif.address,
label: `${nif.name} - ${nif.address}`,
})),
[infoData.networkInterfaces],
);
const pathOptions = useMemo(
() => [
{ value: 'timer', label: 'Timer' },
{ value: 'cuesheet', label: 'Cuesheet' },
{ value: 'op', label: 'Operator' },
{ value: '', label: 'Companion' },
...urlPresetData.map((preset) => ({
value: preset.alias,
label: `Preset: ${preset.alias}`,
})),
],
[urlPresetData],
);
return ( return (
<Panel.Section as='form' onSubmit={handleSubmit(onSubmit)} onKeyDown={(event) => preventEscape(event)}> <Panel.Section as='form' onSubmit={handleSubmit(onSubmit)} onKeyDown={(event) => preventEscape(event)}>
{errors.root && <Panel.Error>{errors.root.message}</Panel.Error>} {errors.root && <Panel.Error>{errors.root.message}</Panel.Error>}
@@ -81,59 +107,40 @@ export default function GenerateLinkForm() {
title='Host IP' title='Host IP'
description={`Which IP address will be used${isOntimeCloud ? ' (not applicable in Ontime Cloud)' : ''}`} description={`Which IP address will be used${isOntimeCloud ? ' (not applicable in Ontime Cloud)' : ''}`}
/> />
<Select variant='ontime' isDisabled={isOntimeCloud} size='sm' {...register('baseUrl')}> <Select
{infoData.networkInterfaces.map((nif) => { disabled={isOntimeCloud}
return ( options={hostOptions}
<option key={nif.name} value={nif.address}> value={watch('baseUrl')}
{`${nif.name} - ${nif.address}`} onValueChange={(value) => setValue('baseUrl', value)}
</option> />
);
})}
</Select>
</Panel.ListItem> </Panel.ListItem>
<Panel.ListItem> <Panel.ListItem>
<Panel.Field <Panel.Field
title='URL Preset' title='URL Preset'
description='Which preset will the link point to (will default to /timer if none is given)' description='Which preset will the link point to (will default to /timer if none is given)'
/> />
<Select variant='ontime' size='sm' {...register('path')}> <Select options={pathOptions} value={watch('path')} onValueChange={(value) => setValue('path', value)} />
<option key='timer' value='timer'>
Timer
</option>
<option key='companion' value=''>
Companion
</option>
{urlPresetData.map((preset) => {
return (
<option key={preset.alias} value={preset.alias}>
{`Preset: ${preset.alias}`}
</option>
);
})}
</Select>
</Panel.ListItem> </Panel.ListItem>
<Panel.ListItem> <Panel.ListItem>
<Panel.Field <Panel.Field
title='Lock navigation' title='Lock navigation'
description='Prevent showing navigation (will only work for non production URLs)' description='Prevent showing navigation (will only work for non production URLs)'
/> />
<Switch variant='ontime' size='lg' {...register('lock')} /> <Switch name='lock' checked={watch('lock')} onCheckedChange={(checked) => setValue('lock', checked)} />
</Panel.ListItem> </Panel.ListItem>
<Panel.ListItem> <Panel.ListItem>
<Panel.Field title='Authenticate' description='Whether the URL should be pre-authenticated' /> <Panel.Field title='Authenticate' description='Whether the URL should be pre-authenticated' />
<Switch variant='ontime' size='lg' {...register('authenticate')} /> <Switch
name='authenticate'
checked={watch('authenticate')}
onCheckedChange={(checked) => setValue('authenticate', checked)}
/>
</Panel.ListItem> </Panel.ListItem>
</Panel.ListGroup> </Panel.ListGroup>
<Panel.ListGroup> <Panel.ListGroup>
<Panel.ListItem> <Panel.ListItem>
<Panel.Field title='Generate link' description='Fill form and generate link and QR code' /> <Panel.Field title='Generate link' description='Fill form and generate link and QR code' />
<Button <Button variant='primary' loading={formState === 'loading'} type='submit' style={{ alignSelf: 'end' }}>
variant='ontime-filled'
size='sm'
isLoading={formState === 'loading'}
type='submit'
style={{ alignSelf: 'end' }}
>
{formState === 'success' ? 'Link copied to clipboard!' : 'Update share link'} {formState === 'success' ? 'Link copied to clipboard!' : 'Update share link'}
</Button> </Button>
<div className={style.column}> <div className={style.column}>
@@ -1,7 +1,7 @@
import { MouseEvent } from 'react'; import { MouseEvent } from 'react';
import { IoArrowUp } from 'react-icons/io5'; import { IoArrowUp } from 'react-icons/io5';
import { Button } from '@chakra-ui/react';
import Button from '../../../../common/components/buttons/Button';
import { handleLinks } from '../../../../common/utils/linkUtils'; import { handleLinks } from '../../../../common/utils/linkUtils';
import Log from '../../../log/Log'; import Log from '../../../log/Log';
import * as Panel from '../../panel-utils/PanelUtils'; import * as Panel from '../../panel-utils/PanelUtils';
@@ -18,13 +18,8 @@ export default function LogExport() {
<Panel.Card> <Panel.Card>
<Panel.SubHeader> <Panel.SubHeader>
Event log Event log
<Button <Button onClick={extract}>
variant='ontime-subtle' Extract <IoArrowUp className={style.iconRotate} />
size='sm'
rightIcon={<IoArrowUp className={style.iconRotate} />}
onClick={extract}
>
Extract
</Button> </Button>
</Panel.SubHeader> </Panel.SubHeader>
<Panel.Divider /> <Panel.Divider />
@@ -1,10 +1,10 @@
import { ChangeEvent, useRef, useState } from 'react'; import { ChangeEvent, useRef, useState } from 'react';
import { IoAdd } from 'react-icons/io5'; import { IoAdd } from 'react-icons/io5';
import { useSearchParams } from 'react-router-dom'; import { useSearchParams } from 'react-router-dom';
import { Button, Input } from '@chakra-ui/react';
import { uploadProjectFile } from '../../../../common/api/db'; import { uploadProjectFile } from '../../../../common/api/db';
import { invalidateAllCaches, maybeAxiosError } from '../../../../common/api/utils'; import { invalidateAllCaches, maybeAxiosError } from '../../../../common/api/utils';
import Button from '../../../../common/components/buttons/Button';
import { validateProjectFile } from '../../../../common/utils/uploadUtils'; import { validateProjectFile } from '../../../../common/utils/uploadUtils';
import * as Panel from '../../panel-utils/PanelUtils'; import * as Panel from '../../panel-utils/PanelUtils';
@@ -57,7 +57,7 @@ export default function ManageProjects() {
return ( return (
<Panel.Section> <Panel.Section>
<Input <input
ref={fileInputRef} ref={fileInputRef}
style={{ display: 'none' }} style={{ display: 'none' }}
type='file' type='file'
@@ -70,22 +70,14 @@ export default function ManageProjects() {
Manage projects Manage projects
<Panel.InlineElements> <Panel.InlineElements>
<Button <Button
variant='ontime-subtle'
onClick={handleSelectFile} onClick={handleSelectFile}
size='sm' disabled={Boolean(loading) || isCreatingProject}
isDisabled={Boolean(loading) || isCreatingProject} loading={loading === 'import'}
isLoading={loading === 'import'}
> >
Import Import
</Button> </Button>
<Button <Button onClick={handleToggleCreate} disabled={Boolean(loading) || isCreatingProject}>
variant='ontime-subtle' New <IoAdd />
onClick={handleToggleCreate}
size='sm'
isDisabled={Boolean(loading) || isCreatingProject}
rightIcon={<IoAdd />}
>
New
</Button> </Button>
</Panel.InlineElements> </Panel.InlineElements>
</Panel.SubHeader> </Panel.SubHeader>
@@ -1,12 +1,14 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useFieldArray, useForm } from 'react-hook-form'; import { useFieldArray, useForm } from 'react-hook-form';
import { IoTrash } from 'react-icons/io5'; import { IoAdd, IoTrash } from 'react-icons/io5';
import { Button, Input, Textarea } from '@chakra-ui/react';
import { useQueryClient } from '@tanstack/react-query'; import { useQueryClient } from '@tanstack/react-query';
import { PROJECT_LIST } from '../../../../common/api/constants'; import { PROJECT_LIST } from '../../../../common/api/constants';
import { createProject } from '../../../../common/api/db'; import { createProject } from '../../../../common/api/db';
import { maybeAxiosError } from '../../../../common/api/utils'; import { maybeAxiosError } from '../../../../common/api/utils';
import Button from '../../../../common/components/buttons/Button';
import Input from '../../../../common/components/input/input/Input';
import Textarea from '../../../../common/components/input/textarea/Textarea';
import { preventEscape } from '../../../../common/utils/keyEvent'; import { preventEscape } from '../../../../common/utils/keyEvent';
import { documentationUrl } from '../../../../externals'; import { documentationUrl } from '../../../../externals';
import * as Panel from '../../panel-utils/PanelUtils'; import * as Panel from '../../panel-utils/PanelUtils';
@@ -86,10 +88,10 @@ export default function ProjectCreateForm(props: ProjectCreateFromProps) {
<Panel.Title> <Panel.Title>
Create new project Create new project
<Panel.InlineElements> <Panel.InlineElements>
<Button onClick={onClose} variant='ontime-ghosted' size='sm' isDisabled={isSubmitting}> <Button onClick={onClose} variant='ghosted' disabled={isSubmitting}>
Cancel Cancel
</Button> </Button>
<Button isDisabled={!isValid} type='submit' isLoading={isSubmitting} variant='ontime-filled' size='sm'> <Button disabled={!isValid} type='submit' loading={isSubmitting} variant='primary'>
Create project Create project
</Button> </Button>
</Panel.InlineElements> </Panel.InlineElements>
@@ -98,53 +100,31 @@ export default function ProjectCreateForm(props: ProjectCreateFromProps) {
<Panel.Section className={style.innerColumn}> <Panel.Section className={style.innerColumn}>
<label> <label>
Project title Project title
<Input <Input fluid maxLength={50} placeholder='Your project name' {...register('title')} />
variant='ontime-filled'
size='sm'
maxLength={50}
placeholder='Your project name'
autoComplete='off'
{...register('title')}
/>
</label> </label>
<label> <label>
Project description Project description
<Input <Input fluid maxLength={100} placeholder='Euro Love, Malmö 2024' {...register('description')} />
variant='ontime-filled'
size='sm'
maxLength={100}
placeholder='Euro Love, Malmö 2024'
autoComplete='off'
{...register('description')}
/>
</label> </label>
<label> <label>
Backstage info Backstage info
<Textarea <Textarea
variant='ontime-filled' fluid
size='sm'
maxLength={150} maxLength={150}
placeholder='Wi-Fi password: 1234' placeholder='Wi-Fi password: 1234'
autoComplete='off' resize='vertical'
resize='none'
{...register('backstageInfo')} {...register('backstageInfo')}
/> />
</label> </label>
<label> <label>
Backstage QR code Url Backstage QR code Url
<Input <Input fluid placeholder={documentationUrl} {...register('backstageUrl')} />
variant='ontime-filled'
size='sm'
placeholder={documentationUrl}
autoComplete='off'
{...register('backstageUrl')}
/>
</label> </label>
<Panel.Section> <Panel.Section>
<Panel.ListItem> <Panel.ListItem>
<Panel.Field title='Custom data' description='Add custom data for your project' /> <Panel.Field title='Custom data' description='Add custom data for your project' />
<Button variant='ontime-subtle' onClick={handleAddCustom}> <Button onClick={handleAddCustom}>
+ Add <IoAdd />
</Button> </Button>
</Panel.ListItem> </Panel.ListItem>
{fields.map((field, idx) => ( {fields.map((field, idx) => (
@@ -152,25 +132,13 @@ export default function ProjectCreateForm(props: ProjectCreateFromProps) {
<Panel.Paragraph>{idx + 1}.</Panel.Paragraph> <Panel.Paragraph>{idx + 1}.</Panel.Paragraph>
<label> <label>
Title Title
<Input <Input placeholder={field.title} {...register(`custom.${idx}.title` as const)} />
variant='ontime-filled'
size='sm'
placeholder={field.title}
autoComplete='off'
{...register(`custom.${idx}.title` as const)}
/>
</label> </label>
<label> <label>
Value Value
<Input <Input placeholder={field.value} autoComplete='off' {...register(`custom.${idx}.value` as const)} />
variant='ontime-filled'
size='sm'
placeholder={field.value}
autoComplete='off'
{...register(`custom.${idx}.value` as const)}
/>
</label> </label>
<Button variant='ontime-ghosted' onClick={() => remove(idx)}> <Button variant='ghosted' onClick={() => remove(idx)}>
<IoTrash /> <IoTrash />
</Button> </Button>
</div> </div>
@@ -1,12 +1,14 @@
import { ChangeEvent, useEffect, useRef } from 'react'; import { ChangeEvent, useEffect, useRef } from 'react';
import { useFieldArray, useForm } from 'react-hook-form'; import { useFieldArray, useForm } from 'react-hook-form';
import { IoAdd, IoDownloadOutline, IoTrash } from 'react-icons/io5'; import { IoAdd, IoDownloadOutline, IoTrash } from 'react-icons/io5';
import { Button, Input, Textarea } from '@chakra-ui/react';
import { type ProjectData } from 'ontime-types'; import { type ProjectData } from 'ontime-types';
import { projectLogoPath } from '../../../../common/api/constants'; import { projectLogoPath } from '../../../../common/api/constants';
import { postProjectData, uploadProjectLogo } from '../../../../common/api/project'; import { postProjectData, uploadProjectLogo } from '../../../../common/api/project';
import { maybeAxiosError } from '../../../../common/api/utils'; import { maybeAxiosError } from '../../../../common/api/utils';
import Button from '../../../../common/components/buttons/Button';
import Input from '../../../../common/components/input/input/Input';
import Textarea from '../../../../common/components/input/textarea/Textarea';
import useProjectData from '../../../../common/hooks-query/useProjectData'; import useProjectData from '../../../../common/hooks-query/useProjectData';
import { preventEscape } from '../../../../common/utils/keyEvent'; import { preventEscape } from '../../../../common/utils/keyEvent';
import { validateLogo } from '../../../../common/utils/uploadUtils'; import { validateLogo } from '../../../../common/utils/uploadUtils';
@@ -112,16 +114,10 @@ export default function ProjectData() {
<Panel.SubHeader> <Panel.SubHeader>
Project data Project data
<Panel.InlineElements> <Panel.InlineElements>
<Button variant='ontime-ghosted' size='sm' onClick={onReset} isDisabled={isSubmitting || !isDirty}> <Button onClick={onReset} disabled={isSubmitting || !isDirty}>
Revert to saved Revert to saved
</Button> </Button>
<Button <Button variant='primary' type='submit' disabled={!isDirty || !isValid} loading={isSubmitting}>
variant='ontime-filled'
size='sm'
type='submit'
isDisabled={!isDirty || !isValid}
isLoading={isSubmitting}
>
Save Save
</Button> </Button>
</Panel.InlineElements> </Panel.InlineElements>
@@ -132,20 +128,16 @@ export default function ProjectData() {
<label> <label>
Project title Project title
<Input <Input
variant='ontime-filled' fluid
size='sm'
maxLength={50} maxLength={50}
placeholder='Project title is shown in production views' placeholder='Project title is shown in production views'
autoComplete='off'
{...register('title')} {...register('title')}
/> />
</label> </label>
<Panel.Section style={{ marginTop: 0 }}> <Panel.Section style={{ marginTop: 0 }}>
<label> <label>
Project logo Project logo
<Input <input
variant='ontime-filled'
size='sm'
type='file' type='file'
style={{ display: 'none' }} style={{ display: 'none' }}
accept='image/*' accept='image/*'
@@ -161,25 +153,17 @@ export default function ProjectData() {
<> <>
<img src={`${projectLogoPath}/${watch('projectLogo')}`} /> <img src={`${projectLogoPath}/${watch('projectLogo')}`} />
<Button <Button
size='sm' variant='subtle-destructive'
variant='ontime-filled' disabled={isSubmitting || !watch('projectLogo')}
isDisabled={isSubmitting || !watch('projectLogo')}
leftIcon={<IoTrash />}
onClick={handleDeleteLogo} onClick={handleDeleteLogo}
type='button'
> >
<IoTrash />
Delete Delete
</Button> </Button>
</> </>
) : ( ) : (
<Button <Button disabled={isSubmitting} onClick={handleClickUpload} type='button'>
variant='ontime-filled' <IoDownloadOutline />
size='sm'
isDisabled={isSubmitting}
leftIcon={<IoDownloadOutline />}
onClick={handleClickUpload}
type='button'
>
Upload logo Upload logo
</Button> </Button>
)} )}
@@ -187,44 +171,30 @@ export default function ProjectData() {
</Panel.Card> </Panel.Card>
</label> </label>
</Panel.Section> </Panel.Section>
<label> <label>
Project description Project description
<Input <Input fluid maxLength={100} placeholder='Euro Love, Malmö 2024' {...register('description')} />
variant='ontime-filled'
size='sm'
maxLength={100}
placeholder='Euro Love, Malmö 2024'
autoComplete='off'
{...register('description')}
/>
</label> </label>
<label> <label>
Backstage info Backstage info
<Textarea <Textarea
variant='ontime-filled' fluid
size='sm'
maxLength={150} maxLength={150}
placeholder='Wi-Fi password: 1234' placeholder='Wi-Fi password: 1234'
autoComplete='off' resize='vertical'
resize='none'
{...register('backstageInfo')} {...register('backstageInfo')}
/> />
</label> </label>
<label> <label>
Backstage QR code URL Backstage QR code URL
<Input <Input fluid placeholder={documentationUrl} {...register('backstageUrl')} />
variant='ontime-filled'
size='sm'
placeholder={documentationUrl}
autoComplete='off'
{...register('backstageUrl')}
/>
</label> </label>
<Panel.Section style={{ marginTop: 0 }}> <Panel.Section style={{ marginTop: 0 }}>
<Panel.ListItem> <Panel.ListItem>
<Panel.Field title='Custom data' description='' /> <Panel.Field title='Custom data' description='' />
<Button leftIcon={<IoAdd />} size='sm' variant='ontime-subtle' onClick={handleAddCustom}> <Button onClick={handleAddCustom}>
Add Add <IoAdd />
</Button> </Button>
</Panel.ListItem> </Panel.ListItem>
{fields.length > 0 && {fields.length > 0 &&
@@ -237,41 +207,31 @@ export default function ProjectData() {
| undefined; | undefined;
return ( return (
<div key={field.id} className={style.customDataItem}> <div key={field.id} className={style.customDataItem}>
<div> <div className={style.titleRow}>
<div className={style.titleRow}> <label>
<label> Title
Title <Input
<Input fluid
variant='ontime-filled' defaultValue={field.title}
size='sm' placeholder='Title of your custom data'
defaultValue={field.title} {...register(`custom.${idx}.title`, {
placeholder='Title of your custom data' required: { value: true, message: 'Field cannot be empty' },
autoComplete='off' })}
{...register(`custom.${idx}.title`, { />
required: { value: true, message: 'Field cannot be empty' }, </label>
})} <Button variant='subtle-destructive' onClick={() => remove(idx)}>
/> <IoTrash />
</label> Delete Entry
<Button </Button>
size='sm'
variant='ontime-subtle'
color='#FA5656' // $red-500
onClick={() => remove(idx)}
leftIcon={<IoTrash />}
>
Delete Entry
</Button>
</div>
{rowErrors?.title?.message && <Panel.Error>{rowErrors.title.message}</Panel.Error>}
</div> </div>
{rowErrors?.title?.message && <Panel.Error>{rowErrors.title.message}</Panel.Error>}
<label> <label>
Value Value
<Textarea <Textarea
variant='ontime-filled' fluid
resize='none' rows={3}
size='sm' resize='vertical'
defaultValue={field.value} defaultValue={field.value}
autoComplete='off'
placeholder='Text of your custom data' placeholder='Text of your custom data'
{...register(`custom.${idx}.value`, { {...register(`custom.${idx}.value`, {
required: { value: true, message: 'Field cannot be empty' }, required: { value: true, message: 'Field cannot be empty' },
@@ -61,14 +61,6 @@ function SecondarySourceControl() {
} }
}; };
const changeValue = (newValue: SecondarySource) => {
// we can only update the remote if it is enabled
if (secondarySource !== null) {
setMessage.timerSecondarySource(newValue);
}
setValue(newValue);
};
return ( return (
<> <>
<Select <Select
@@ -79,7 +71,13 @@ function SecondarySourceControl() {
{ value: 'aux3', label: 'Aux 3' }, { value: 'aux3', label: 'Aux 3' },
{ value: 'secondary', label: 'Secondary message' }, { value: 'secondary', label: 'Secondary message' },
]} ]}
onChange={changeValue} onValueChange={(value) => {
// we can only update the remote if it is enabled
if (secondarySource !== null) {
setMessage.timerSecondarySource(value as SecondarySource);
}
setValue(value as SecondarySource);
}}
/> />
<Button <Button
variant={secondarySource !== null ? 'primary' : 'subtle'} variant={secondarySource !== null ? 'primary' : 'subtle'}
+14 -14
View File
@@ -1,7 +1,7 @@
import { useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import { Button } from '@chakra-ui/react';
import { LogOrigin } from 'ontime-types'; import { LogOrigin } from 'ontime-types';
import Button from '../../common/components/buttons/Button';
import { clearLogs, useLogData } from '../../common/stores/logger'; import { clearLogs, useLogData } from '../../common/stores/logger';
import * as Panel from '../app-settings/panel-utils/PanelUtils'; import * as Panel from '../app-settings/panel-utils/PanelUtils';
@@ -52,8 +52,8 @@ export default function Log() {
<> <>
<Panel.InlineElements className={style.buttonBar}> <Panel.InlineElements className={style.buttonBar}>
<Button <Button
variant={showUser ? 'ontime-filled' : 'ontime-outlined'} variant={showUser ? 'primary' : 'subtle'}
size='xs' size='small'
onClick={() => setShowUser((s) => !s)} onClick={() => setShowUser((s) => !s)}
onAuxClick={() => disableOthers(LogOrigin.User)} onAuxClick={() => disableOthers(LogOrigin.User)}
onContextMenu={(e) => e.preventDefault()} onContextMenu={(e) => e.preventDefault()}
@@ -61,8 +61,8 @@ export default function Log() {
{LogOrigin.User} {LogOrigin.User}
</Button> </Button>
<Button <Button
variant={showClient ? 'ontime-filled' : 'ontime-outlined'} variant={showClient ? 'primary' : 'subtle'}
size='xs' size='small'
onClick={() => setShowClient((s) => !s)} onClick={() => setShowClient((s) => !s)}
onAuxClick={() => disableOthers(LogOrigin.Client)} onAuxClick={() => disableOthers(LogOrigin.Client)}
onContextMenu={(e) => e.preventDefault()} onContextMenu={(e) => e.preventDefault()}
@@ -70,8 +70,8 @@ export default function Log() {
{LogOrigin.Client} {LogOrigin.Client}
</Button> </Button>
<Button <Button
variant={showServer ? 'ontime-filled' : 'ontime-outlined'} variant={showServer ? 'primary' : 'subtle'}
size='xs' size='small'
onClick={() => setShowServer((s) => !s)} onClick={() => setShowServer((s) => !s)}
onAuxClick={() => disableOthers(LogOrigin.Server)} onAuxClick={() => disableOthers(LogOrigin.Server)}
onContextMenu={(e) => e.preventDefault()} onContextMenu={(e) => e.preventDefault()}
@@ -79,8 +79,8 @@ export default function Log() {
{LogOrigin.Server} {LogOrigin.Server}
</Button> </Button>
<Button <Button
variant={showPlayback ? 'ontime-filled' : 'ontime-outlined'} variant={showPlayback ? 'primary' : 'subtle'}
size='xs' size='small'
onClick={() => setShowPlayback((s) => !s)} onClick={() => setShowPlayback((s) => !s)}
onAuxClick={() => disableOthers(LogOrigin.Playback)} onAuxClick={() => disableOthers(LogOrigin.Playback)}
onContextMenu={(e) => e.preventDefault()} onContextMenu={(e) => e.preventDefault()}
@@ -88,8 +88,8 @@ export default function Log() {
{LogOrigin.Playback} {LogOrigin.Playback}
</Button> </Button>
<Button <Button
variant={showRx ? 'ontime-filled' : 'ontime-outlined'} variant={showRx ? 'primary' : 'subtle'}
size='xs' size='small'
onClick={() => setShowRx((s) => !s)} onClick={() => setShowRx((s) => !s)}
onAuxClick={() => disableOthers(LogOrigin.Rx)} onAuxClick={() => disableOthers(LogOrigin.Rx)}
onContextMenu={(e) => e.preventDefault()} onContextMenu={(e) => e.preventDefault()}
@@ -97,15 +97,15 @@ export default function Log() {
{LogOrigin.Rx} {LogOrigin.Rx}
</Button> </Button>
<Button <Button
variant={showTx ? 'ontime-filled' : 'ontime-outlined'} variant={showTx ? 'primary' : 'subtle'}
size='xs' size='small'
onClick={() => setShowTx((s) => !s)} onClick={() => setShowTx((s) => !s)}
onAuxClick={() => disableOthers(LogOrigin.Tx)} onAuxClick={() => disableOthers(LogOrigin.Tx)}
onContextMenu={(e) => e.preventDefault()} onContextMenu={(e) => e.preventDefault()}
> >
{LogOrigin.Tx} {LogOrigin.Tx}
</Button> </Button>
<Button variant='ontime-subtle' size='xs' onClick={clearLogs}> <Button variant='subtle-destructive' size='small' onClick={clearLogs}>
Clear Clear
</Button> </Button>
</Panel.InlineElements> </Panel.InlineElements>
@@ -1,7 +1,6 @@
import { PropsWithChildren, ReactNode } from 'react'; import { PropsWithChildren, ReactNode } from 'react';
import { ErrorBoundary } from '@sentry/react'; import { ErrorBoundary } from '@sentry/react';
import { Playback } from 'ontime-types'; import { isPlaybackActive, millisToString } from 'ontime-utils';
import { millisToString } from 'ontime-utils';
import { useIsOnline, useRuntimePlaybackOverview, useTimer } from '../../../common/hooks/useSocket'; import { useIsOnline, useRuntimePlaybackOverview, useTimer } from '../../../common/hooks/useSocket';
import useProjectData from '../../../common/hooks-query/useProjectData'; import useProjectData from '../../../common/hooks-query/useProjectData';
@@ -72,8 +71,9 @@ export function ProgressOverview() {
export function RuntimeOverview() { export function RuntimeOverview() {
const { clock, offset, playback } = useRuntimePlaybackOverview(); const { clock, offset, playback } = useRuntimePlaybackOverview();
const offsetText = getOffsetText(offset); const isPlaying = isPlaybackActive(playback);
const offsetClasses = cx([style.offset, playback !== Playback.Stop && (offset < 0 ? style.behind : style.ahead)]); const offsetText = getOffsetText(isPlaying ? offset : null);
const offsetClasses = cx([style.offset, isPlaying && (offset < 0 ? style.behind : style.ahead)]);
return ( return (
<> <>
@@ -102,7 +102,7 @@ function EventEditorTimes({
<Editor.Label htmlFor='endAction'>End Action</Editor.Label> <Editor.Label htmlFor='endAction'>End Action</Editor.Label>
<Select <Select
value={endAction} value={endAction}
onChange={(value) => handleSubmit('endAction', value)} onValueChange={(value) => handleSubmit('endAction', value)}
options={[ options={[
{ value: EndAction.None, label: 'None' }, { value: EndAction.None, label: 'None' },
{ value: EndAction.LoadNext, label: 'Load next event' }, { value: EndAction.LoadNext, label: 'Load next event' },
@@ -138,7 +138,7 @@ function EventEditorTimes({
<Editor.Label htmlFor='timerType'>Timer Type</Editor.Label> <Editor.Label htmlFor='timerType'>Timer Type</Editor.Label>
<Select <Select
value={timerType} value={timerType}
onChange={(value) => handleSubmit('timerType', value)} onValueChange={(value) => handleSubmit('timerType', value)}
options={[ options={[
{ value: TimerType.CountDown, label: 'Count down' }, { value: TimerType.CountDown, label: 'Count down' },
{ value: TimerType.CountUp, label: 'Count up' }, { value: TimerType.CountUp, label: 'Count up' },
@@ -1,4 +1,4 @@
import { Fragment, useCallback, useState } from 'react'; import { Fragment, useCallback, useMemo, useState } from 'react';
import { IoAlertCircle, IoCheckmarkCircle, IoTrash } from 'react-icons/io5'; import { IoAlertCircle, IoCheckmarkCircle, IoTrash } from 'react-icons/io5';
import { Tooltip } from '@chakra-ui/react'; import { Tooltip } from '@chakra-ui/react';
import { TimerLifeCycle, timerLifecycleValues, Trigger } from 'ontime-types'; import { TimerLifeCycle, timerLifecycleValues, Trigger } from 'ontime-types';
@@ -66,18 +66,38 @@ function EventTriggerForm({ eventId, triggers }: EventTriggerFormProps) {
const validationError = getValidationError(cycleValue, automationId); const validationError = getValidationError(cycleValue, automationId);
const triggerOptions = useMemo(
() => [
{ value: null, label: 'Select Trigger' },
...eventTriggerOptions.map((cycle) => ({ value: cycle, label: cycle })),
],
[], // eventTriggerOptions is a constant, no need for dependency
);
const automationOptions = useMemo(
() => [
{ value: null, label: 'Select Automation' },
...Object.values(automationSettings.automations).map(({ id, title }) => ({ value: id, label: title })),
],
[automationSettings.automations], // This needs to be a dependency as it can change
);
return ( return (
<div className={style.triggerForm}> <div className={style.triggerForm}>
<Select <Select
value={cycleValue} value={cycleValue}
onChange={(value) => setCycleValue(value)} onValueChange={(value) => {
options={eventTriggerOptions.map((cycle) => ({ value: cycle, label: cycle }))} if (value !== null) setCycleValue(value);
}}
options={triggerOptions}
/> />
<Select <Select
value={automationId} value={automationId ?? null}
onChange={(value) => setAutomationId(value)} onValueChange={(value) => {
options={Object.values(automationSettings.automations).map(({ id, title }) => ({ value: id, label: title }))} if (value !== null) setAutomationId(value);
}}
options={automationOptions}
/> />
<Button <Button
@@ -50,9 +50,7 @@ function EditableImage({ initialValue, updateValue }: EditableImageProps) {
return ( return (
<div className={style.imageCell}> <div className={style.imageCell}>
<div className={style.overlay}> <div className={style.overlay}>
<Button variant='subtle-white' onClick={openInNewTab}> <Button onClick={openInNewTab}>Preview</Button>
Preview
</Button>
<Button variant='subtle-destructive' onClick={() => handleUpdate('')}> <Button variant='subtle-destructive' onClick={() => handleUpdate('')}>
Delete Delete
</Button> </Button>
@@ -72,7 +72,7 @@ function ViewSettings() {
<Popover.Root> <Popover.Root>
<Popover.Trigger <Popover.Trigger
render={ render={
<Button variant='ghosted'> <Button variant='ghosted-white'>
<IoSettingsOutline /> Settings <IoSettingsOutline /> Settings
<IoChevronDown /> <IoChevronDown />
</Button> </Button>
@@ -140,7 +140,7 @@ function ColumnSettings({
<Popover.Root> <Popover.Root>
<Popover.Trigger <Popover.Trigger
render={ render={
<Button variant='ghosted'> <Button variant='ghosted-white'>
<IoOptions /> View <IoOptions /> View
<IoChevronDown /> <IoChevronDown />
</Button> </Button>
@@ -1,10 +1,9 @@
import { body } from 'express-validator'; import { body } from 'express-validator';
import { requestValidationFunction } from '../validation-utils/validationFunction.js'; import { requestValidationFunction } from '../validation-utils/validationFunction.js';
export const validateGenerateUrl = [ export const validateGenerateUrl = [
body('baseUrl').isString().trim().notEmpty(), body('baseUrl').isString().trim().notEmpty(),
body('path').isString().trim().notEmpty(), body('path').isString().trim(),
body('lock').isBoolean(), body('lock').isBoolean(),
body('authenticate').isBoolean(), body('authenticate').isBoolean(),
@@ -24,7 +24,7 @@ test('sheet file upload', async ({ page }) => {
await page.getByRole('button', { name: 'Import preview' }).click(); await page.getByRole('button', { name: 'Import preview' }).click();
await page.getByRole('button', { name: 'Apply' }).click(); await page.getByRole('button', { name: 'Apply' }).click();
await page.getByRole('button', { name: 'Return' }).click(); await page.getByRole('button', { name: 'Return' }).click();
await page.getByLabel('close').click(); await page.getByRole('button', { name: 'Close settings' }).click();
// asset test events // asset test events
const firstTitle = page.getByTestId('entry-1').getByTestId('block__title'); const firstTitle = page.getByTestId('entry-1').getByTestId('block__title');