From 6f517707a0c1e0bc38b9737658b742f930581345 Mon Sep 17 00:00:00 2001 From: Josef552 <105931716+Josef552@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:26:02 +0200 Subject: [PATCH] sugar --- src/utils/formattingUtils.ts | 24 +++++---- src/view/FreeClausesManipulation.tsx | 79 ++++++++++++++-------------- src/view/LabelsListManipulation.tsx | 79 ++++++++++++++-------------- src/view/StatementManipulation.tsx | 79 ++++++++++++++-------------- 4 files changed, 130 insertions(+), 131 deletions(-) diff --git a/src/utils/formattingUtils.ts b/src/utils/formattingUtils.ts index a3294f3..83cd2c9 100644 --- a/src/utils/formattingUtils.ts +++ b/src/utils/formattingUtils.ts @@ -3,7 +3,7 @@ import { ClockConstraint } from '../model/ta/clockConstraint'; import { Clock } from '../model/ta/clock'; import { Switch } from '../model/ta/switch'; import { Location } from '../model/ta/location'; -import {SwitchStatement} from "../model/ta/switchStatement.ts"; +import { SwitchStatement } from '../model/ta/switchStatement.ts'; export interface FormattingUtils { formatClockConstraint: (clockConstraint?: ClockConstraint, clauseJoinStr?: string) => string | undefined; @@ -18,20 +18,20 @@ export interface FormattingUtils { export function useFormattingUtils(): FormattingUtils { const formatClockConstraint = useCallback((clockConstraint?: ClockConstraint, clauseJoinStr: string = ' ∧ ') => { const cc = clockConstraint; - if (!cc || (!cc.clauses && !cc.freeClauses) || (cc.clauses.length === 0 && cc.freeClauses.length === 0 )) { + if (!cc || (!cc.clauses && !cc.freeClauses) || (cc.clauses.length === 0 && cc.freeClauses.length === 0)) { return undefined; } let clauses = ''; let freeClauses = ''; - if (cc.clauses){ - if (cc.clauses.length !== 0){ + if (cc.clauses) { + if (cc.clauses.length !== 0) { clauses = cc.clauses.map((c) => `${c.lhs.name} ${c.op} ${c.rhs}`).join(clauseJoinStr); - if (cc.freeClauses && cc.freeClauses.length !== 0){ + if (cc.freeClauses && cc.freeClauses.length !== 0) { clauses += clauseJoinStr; } } } - if (cc.freeClauses && cc.freeClauses.length !== 0){ + if (cc.freeClauses && cc.freeClauses.length !== 0) { freeClauses = cc.freeClauses.map((c) => `${c.term}`).join(clauseJoinStr); } return clauses + freeClauses; @@ -49,16 +49,16 @@ export function useFormattingUtils(): FormattingUtils { const formatStatement = useCallback((statement?: SwitchStatement, clauseJoinStr: string = '; ') => { const stmt = statement; - if(!stmt || !stmt.statements || stmt.statements.length === 0){ + if (!stmt || !stmt.statements || stmt.statements.length === 0) { return undefined; } let formattedStatements = ''; - if (stmt.statements && stmt.statements.length !== 0){ + if (stmt.statements && stmt.statements.length !== 0) { formattedStatements = stmt.statements.map((c) => `${c.term}`).join(clauseJoinStr); } return formattedStatements; }, []); - + const formatLocationLabelTable = useCallback( (location: Location) => { const invariant = formatClockConstraint(location.invariant); @@ -80,7 +80,9 @@ export function useFormattingUtils(): FormattingUtils { const guard = formatClockConstraint(sw.guard); const reset = formatReset(sw.reset, true); const statement = formatStatement(sw.statement); - return [sw.source.name, sw.actionLabel, guard, reset, statement, sw.target.name].filter((e) => e !== undefined).join(', '); + return [sw.source.name, sw.actionLabel, guard, reset, statement, sw.target.name] + .filter((e) => e !== undefined) + .join(', '); }, [formatClockConstraint, formatReset, formatStatement] ); @@ -92,7 +94,7 @@ export function useFormattingUtils(): FormattingUtils { const statement = formatStatement(sw.statement); return [sw.actionLabel, guard, reset, statement].filter((e) => e !== undefined).join('\n'); }, - [formatClockConstraint, formatReset] + [formatClockConstraint, formatReset, formatStatement] ); return { diff --git a/src/view/FreeClausesManipulation.tsx b/src/view/FreeClausesManipulation.tsx index 17b65b5..909f567 100644 --- a/src/view/FreeClausesManipulation.tsx +++ b/src/view/FreeClausesManipulation.tsx @@ -1,50 +1,49 @@ import { Grid, IconButton, TextField, Tooltip } from '@mui/material'; import DeleteIcon from '@mui/icons-material/Delete'; -import { useTranslation } from 'react-i18next'; import { useButtonUtils } from '../utils/buttonUtils'; -import {FreeClausesViewModel} from "../viewmodel/FreeClausesViewModel.ts"; -import React from "react"; +import { FreeClausesViewModel } from '../viewmodel/FreeClausesViewModel.ts'; +import React from 'react'; interface FreeClausesManipulationProps { - viewModel: FreeClausesViewModel; + viewModel: FreeClausesViewModel; } export const FreeClausesManipulation: React.FC = (props) => { - const { viewModel} = props; - const { freeClauses, deleteFreeClause, changeFreeClause } = viewModel; - //const { t } = useTranslation(); - const { executeOnKeyboardClick } = useButtonUtils(); + const { viewModel } = props; + const { freeClauses, deleteFreeClause, changeFreeClause } = viewModel; + //const { t } = useTranslation(); + const { executeOnKeyboardClick } = useButtonUtils(); - return ( - <> - {freeClauses.map((row) => ( - - - deleteFreeClause(viewModel, row.id)} - onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteFreeClause(viewModel, row.id))} - data-testid={'button-delete-freeClause-row-' + row.id} - > - - - - - - - changeFreeClause(viewModel, row.id, 'freeInput', e.target.value)} - InputProps={{ inputProps: { min: 1 } }} - data-testid={'enter-freeClause-row'} - /> - - - ))} - - ); + return ( + <> + {freeClauses.map((row) => ( + + + deleteFreeClause(viewModel, row.id)} + onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteFreeClause(viewModel, row.id))} + data-testid={'button-delete-freeClause-row-' + row.id} + > + + + + + + + changeFreeClause(viewModel, row.id, 'freeInput', e.target.value)} + InputProps={{ inputProps: { min: 1 } }} + data-testid={'enter-freeClause-row'} + /> + + + ))} + + ); }; diff --git a/src/view/LabelsListManipulation.tsx b/src/view/LabelsListManipulation.tsx index 7f6b8cb..464542f 100644 --- a/src/view/LabelsListManipulation.tsx +++ b/src/view/LabelsListManipulation.tsx @@ -1,50 +1,49 @@ import { Grid, IconButton, TextField, Tooltip } from '@mui/material'; import DeleteIcon from '@mui/icons-material/Delete'; -import { useTranslation } from 'react-i18next'; import { useButtonUtils } from '../utils/buttonUtils'; -import {LabelsViewModel} from "../viewmodel/LabelsListViewModel.ts"; -import React from "react"; +import { LabelsViewModel } from '../viewmodel/LabelsListViewModel.ts'; +import React from 'react'; interface LabelsManipulationProps { - viewModel: LabelsViewModel; + viewModel: LabelsViewModel; } export const LabelsListManipulation: React.FC = (props) => { - const { viewModel} = props; - const { labels, deleteLabel, changeLabel } = viewModel; - //const { t } = useTranslation(); - const { executeOnKeyboardClick } = useButtonUtils(); + const { viewModel } = props; + const { labels, deleteLabel, changeLabel } = viewModel; + //const { t } = useTranslation(); + const { executeOnKeyboardClick } = useButtonUtils(); - return ( - <> - {labels.map((row) => ( - - - deleteLabel(viewModel, row.id)} - onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteLabel(viewModel, row.id))} - data-testid={'button-delete-label-row-' + row.id} - > - - - - - - - changeLabel(viewModel, row.id, 'freeInput', e.target.value)} - InputProps={{ inputProps: { min: 1 } }} - data-testid={'enter-label-row'} - /> - - - ))} - - ); + return ( + <> + {labels.map((row) => ( + + + deleteLabel(viewModel, row.id)} + onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteLabel(viewModel, row.id))} + data-testid={'button-delete-label-row-' + row.id} + > + + + + + + + changeLabel(viewModel, row.id, 'freeInput', e.target.value)} + InputProps={{ inputProps: { min: 1 } }} + data-testid={'enter-label-row'} + /> + + + ))} + + ); }; diff --git a/src/view/StatementManipulation.tsx b/src/view/StatementManipulation.tsx index 7878d81..c2f3e97 100644 --- a/src/view/StatementManipulation.tsx +++ b/src/view/StatementManipulation.tsx @@ -1,50 +1,49 @@ import { Grid, IconButton, TextField, Tooltip } from '@mui/material'; import DeleteIcon from '@mui/icons-material/Delete'; -import { useTranslation } from 'react-i18next'; import { useButtonUtils } from '../utils/buttonUtils'; -import {StatementsViewModel} from "../viewmodel/StatementsViewModel.ts"; -import React from "react"; +import { StatementsViewModel } from '../viewmodel/StatementsViewModel.ts'; +import React from 'react'; interface StatementManipulationProps { - viewModel: StatementsViewModel; + viewModel: StatementsViewModel; } export const StatementManipulation: React.FC = (props) => { - const { viewModel} = props; - const { statements, deleteStatement, changeStatement } = viewModel; - const { t } = useTranslation(); - const { executeOnKeyboardClick } = useButtonUtils(); + const { viewModel } = props; + const { statements, deleteStatement, changeStatement } = viewModel; + //const { t } = useTranslation(); + const { executeOnKeyboardClick } = useButtonUtils(); - return ( - <> - {statements.map((row) => ( - - - deleteStatement(viewModel, row.id)} - onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteStatement(viewModel, row.id))} - data-testid={'button-delete-statement-row-' + row.id} - > - - - - - - - changeStatement(viewModel, row.id, 'freeInput', e.target.value)} - InputProps={{ inputProps: { min: 1 } }} - data-testid={'enter-statement-row'} - /> - - - ))} - - ); + return ( + <> + {statements.map((row) => ( + + + deleteStatement(viewModel, row.id)} + onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteStatement(viewModel, row.id))} + data-testid={'button-delete-statement-row-' + row.id} + > + + + + + + + changeStatement(viewModel, row.id, 'freeInput', e.target.value)} + InputProps={{ inputProps: { min: 1 } }} + data-testid={'enter-statement-row'} + /> + + + ))} + + ); };