refactor: typescript improvements

This commit is contained in:
cv
2023-09-29 21:39:50 +02:00
parent 4e9d9fc075
commit e10c0e8c97
2 changed files with 7 additions and 9 deletions
@@ -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) {