mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 10:23:54 +00:00
refactor: typescript improvements
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
import { MutableRefObject } from 'react';
|
||||
|
||||
import { ExcelInputOptions } from '../UploadModal';
|
||||
import { ExcelImportMap } from 'ontime-utils';
|
||||
|
||||
import ImportMapTable, { type TableEntry } from './ImportMapTable';
|
||||
|
||||
import style from '../UploadModal.module.scss';
|
||||
|
||||
interface ExcelFileOptionsProps {
|
||||
optionsRef: MutableRefObject<ExcelInputOptions>;
|
||||
optionsRef: MutableRefObject<ExcelImportMap>;
|
||||
}
|
||||
|
||||
export default function ExcelFileOptions(props: ExcelFileOptionsProps) {
|
||||
const { optionsRef } = props;
|
||||
|
||||
const updateRef = <T extends keyof ExcelInputOptions>(field: T, value: ExcelInputOptions[T]) => {
|
||||
const updateRef = <T extends keyof ExcelImportMap>(field: T, value: ExcelImportMap[T]) => {
|
||||
// avoid unnecessary changes
|
||||
if (optionsRef.current[field] !== value) {
|
||||
optionsRef.current = { ...optionsRef.current, [field]: value };
|
||||
@@ -39,6 +38,7 @@ export default function ExcelFileOptions(props: ExcelFileOptionsProps) {
|
||||
|
||||
const options: TableEntry[] = [
|
||||
{ label: 'Is Public', title: 'isPublic', value: optionsRef.current.isPublic },
|
||||
{ label: 'Skip', title: 'skip', value: optionsRef.current.skip },
|
||||
{ label: 'Timer Type', title: 'timerType', value: optionsRef.current.timerType },
|
||||
{ label: 'End Action', title: 'endAction', value: optionsRef.current.endAction },
|
||||
];
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import { Input } from '@chakra-ui/react';
|
||||
|
||||
import { ExcelInputOptions } from '../UploadModal';
|
||||
import { ExcelImportMap } from 'ontime-utils';
|
||||
|
||||
import style from './ImportMapTable.module.scss';
|
||||
|
||||
// TODO: make this generic
|
||||
export type TableEntry = { label: string; title: keyof ExcelInputOptions; value: string };
|
||||
export type TableEntry = { label: string; title: keyof ExcelImportMap; value: string };
|
||||
|
||||
interface ImportMapTableProps {
|
||||
title: string;
|
||||
fields: TableEntry[];
|
||||
handleOnChange: (field: keyof ExcelInputOptions, value: string) => void;
|
||||
handleOnChange: (field: keyof ExcelImportMap, value: string) => void;
|
||||
}
|
||||
|
||||
export default function ImportMapTable(props: ImportMapTableProps) {
|
||||
|
||||
Reference in New Issue
Block a user