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