refactor: normalise data (#756)

* chore: remove legal from bundle

* refactor: create normalised dataset

* refactor: cuesheet uses flat rundown

* refactor: multi-selection

* refactor: prevent stale data on server restart

* refactor: increase ID size

* chore: instrument operation

* chore: update csv tests

* fix: resolve directory to test-db (#758)
This commit is contained in:
Carlos Valente
2024-02-03 21:43:17 +01:00
committed by GitHub
parent 47a519bac1
commit 1890fc49d7
62 changed files with 1838 additions and 3341 deletions
@@ -1,67 +0,0 @@
import { Modal, ModalBody, ModalCloseButton, ModalContent, ModalHeader, ModalOverlay } from '@chakra-ui/react';
import { version } from '../../../../package.json';
import OntimeLogo from '../../../assets/images/ontime-logo.svg?react';
import { gitbookUrl, githubUrl } from '../../../externals';
import ModalLink from '../ModalLink';
import UpdateChecker from './UpdateChecker';
import styles from '../Modal.module.scss';
interface AboutModalProps {
isOpen: boolean;
onClose: () => void;
}
export default function AboutModal(props: AboutModalProps) {
const { isOpen, onClose } = props;
return (
<Modal
size='sm'
isOpen={isOpen}
onClose={onClose}
closeOnOverlayClick={false}
motionPreset='slideInBottom'
scrollBehavior='inside'
preserveScrollBarGap
variant='ontime-small'
>
<ModalOverlay />
<ModalContent>
<ModalHeader>
About Ontime
<ModalCloseButton />
</ModalHeader>
<ModalBody className={styles.body}>
<div className={styles.twoColumn}>
<OntimeLogo className={styles.logo} />
<div>
<div className={styles.padBottom}>
<span className={styles.sectionTitle}>Ontime</span>
Free Open Source Software for managing rundowns and event timers
<ModalLink href='https://www.getontime.no'>www.getontime.no</ModalLink>
</div>
<div className={styles.padBottom}>
<span className={styles.sectionTitle}>Current version</span>
{`You are currently using Ontime ${version}`}
</div>
<div className={styles.padBottom}>
<span className={styles.sectionTitle}>Docs</span>
<ModalLink href={gitbookUrl}>Read the docs over at GitBook</ModalLink>
</div>
<div>
<span className={styles.sectionTitle}>Github</span>
<ModalLink href={githubUrl}>Follow the project on GitHub</ModalLink>
</div>
<UpdateChecker version={version} />
</div>
</div>
</ModalBody>
</ModalContent>
</Modal>
);
}
@@ -1,72 +0,0 @@
import { useState } from 'react';
import { Button } from '@chakra-ui/react';
import { getLatestVersion, HasUpdate } from '../../../common/api/ontimeApi';
import ModalLink from '../ModalLink';
import styles from '../Modal.module.scss';
interface UpdateCheckerProps {
version: string;
}
type CheckFail = {
error: string;
};
type CheckIsLatest = {
latest: true;
};
type CheckRemote = CheckFail | CheckIsLatest | HasUpdate;
export default function UpdateChecker(props: UpdateCheckerProps) {
const { version } = props;
const [updateMessage, setUpdateMessage] = useState<CheckRemote | null>(null);
const [isFetching, setIsFetching] = useState(false);
/**
* Handles version comparison and returns component with message
*/
const versionCheck = async () => {
setIsFetching(true);
try {
const latest = await getLatestVersion();
if (!latest.version.includes(version)) {
// new version, pass data to component
setUpdateMessage(latest);
} else {
setUpdateMessage({ latest: true });
}
} catch {
setUpdateMessage({ error: 'Error reaching server' });
} finally {
setIsFetching(false);
}
};
const disableButton = Boolean(updateMessage && 'version' in updateMessage);
return (
<div className={styles.updateSection}>
<Button onClick={versionCheck} variant='ontime-filled' isLoading={isFetching} isDisabled={disableButton}>
Check for updates
</Button>
<ResolveUpdateMessage updateMessage={updateMessage} />
</div>
);
}
function ResolveUpdateMessage(props: { updateMessage: CheckRemote | null }) {
const { updateMessage } = props;
if (updateMessage && 'error' in updateMessage) {
return <span className={styles.error}>{updateMessage.error}</span>;
}
if (updateMessage && 'url' in updateMessage) {
return <ModalLink href={updateMessage?.url}>{`New version available: ${updateMessage.version}`}</ModalLink>;
}
return null;
}
@@ -1,7 +0,0 @@
.buttonRow {
justify-content: space-between;
margin-top: $section-spacing;
display: flex;
gap: $section-spacing;
margin: 0 0.25rem;
}
@@ -1,32 +0,0 @@
import { Button, Modal, ModalBody, ModalCloseButton, ModalContent, ModalHeader, ModalOverlay } from '@chakra-ui/react';
import styles from './ExportModal.module.scss';
export type ExportType = 'csv' | 'json';
interface ExportModalProps {
isOpen: boolean;
onClose: (type?: ExportType) => void;
}
export default function ExportModal(props: ExportModalProps) {
const { isOpen, onClose } = props;
return (
<Modal isOpen={isOpen} onClose={onClose} motionPreset='slideInBottom' size='xl' variant='ontime-small'>
<ModalOverlay />
<ModalContent>
<ModalHeader className={styles.modalHeader}>Download options</ModalHeader>
<ModalCloseButton />
<ModalBody className={styles.buttonRow}>
<Button onClick={() => onClose('csv')} variant='ontime-subtle-on-light' width='100%'>
Rundown as CSV
</Button>
<Button onClick={() => onClose('json')} variant='ontime-filled' width='100%'>
Project file
</Button>
</ModalBody>
</ModalContent>
</Modal>
);
}
@@ -150,6 +150,8 @@ export default function UploadModal({ onClose, isOpen }: UploadModalProps) {
setSubmitting(true);
try {
await patchData({ rundown, userFields });
// TODO: broken :(
// we need to normalise the data here
queryClient.setQueryData(RUNDOWN, { rundown, revision: -1 });
queryClient.setQueryData(USERFIELDS, userFields);
await queryClient.invalidateQueries({