Skip to content

Commit

Permalink
sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef552 committed Sep 16, 2024
1 parent dab89e5 commit 6f51770
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 131 deletions.
24 changes: 13 additions & 11 deletions src/utils/formattingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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]
);
Expand All @@ -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 {
Expand Down
79 changes: 39 additions & 40 deletions src/view/FreeClausesManipulation.tsx
Original file line number Diff line number Diff line change
@@ -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<FreeClausesManipulationProps> = (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) => (
<Grid key={row.id} container spacing={2} alignItems="center">
<Grid item xs={1}>
<IconButton
disabled={freeClauses.length <= 0}
onMouseDown={() => deleteFreeClause(viewModel, row.id)}
onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteFreeClause(viewModel, row.id))}
data-testid={'button-delete-freeClause-row-' + row.id}
>
<Tooltip title={'Klausel löschen' /*t('clauses.delete')*/}>
<DeleteIcon />
</Tooltip>
</IconButton>
</Grid>
<Grid item xs={11}>
<TextField
margin="dense"
label={'Freie Klausel' /*t('clauses.input.value')*/}
fullWidth
variant="outlined"
value={row.term}
onChange={(e) => changeFreeClause(viewModel, row.id, 'freeInput', e.target.value)}
InputProps={{ inputProps: { min: 1 } }}
data-testid={'enter-freeClause-row'}
/>
</Grid>
</Grid>
))}
</>
);
return (
<>
{freeClauses.map((row) => (
<Grid key={row.id} container spacing={2} alignItems="center">
<Grid item xs={1}>
<IconButton
disabled={freeClauses.length <= 0}
onMouseDown={() => deleteFreeClause(viewModel, row.id)}
onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteFreeClause(viewModel, row.id))}
data-testid={'button-delete-freeClause-row-' + row.id}
>
<Tooltip title={'Klausel löschen' /*t('clauses.delete')*/}>
<DeleteIcon />
</Tooltip>
</IconButton>
</Grid>
<Grid item xs={11}>
<TextField
margin="dense"
label={'Freie Klausel' /*t('clauses.input.value')*/}
fullWidth
variant="outlined"
value={row.term}
onChange={(e) => changeFreeClause(viewModel, row.id, 'freeInput', e.target.value)}

Check failure on line 40 in src/view/FreeClausesManipulation.tsx

View workflow job for this annotation

GitHub Actions / build

Argument of type '"freeInput"' is not assignable to parameter of type 'keyof FreeClauseViewData'.
InputProps={{ inputProps: { min: 1 } }}
data-testid={'enter-freeClause-row'}
/>
</Grid>
</Grid>
))}
</>
);
};
79 changes: 39 additions & 40 deletions src/view/LabelsListManipulation.tsx
Original file line number Diff line number Diff line change
@@ -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<LabelsManipulationProps> = (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) => (
<Grid key={row.id} container spacing={2} alignItems="center">
<Grid item xs={1}>
<IconButton
disabled={labels.length <= 0}
onMouseDown={() => deleteLabel(viewModel, row.id)}
onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteLabel(viewModel, row.id))}
data-testid={'button-delete-label-row-' + row.id}
>
<Tooltip title={'Label löschen' /*t('clauses.delete')*/}>
<DeleteIcon />
</Tooltip>
</IconButton>
</Grid>
<Grid item xs={11}>
<TextField
margin="dense"
label={'Label' /*t('clauses.input.value')*/}
fullWidth
variant="outlined"
value={row.term}
onChange={(e) => changeLabel(viewModel, row.id, 'freeInput', e.target.value)}
InputProps={{ inputProps: { min: 1 } }}
data-testid={'enter-label-row'}
/>
</Grid>
</Grid>
))}
</>
);
return (
<>
{labels.map((row) => (
<Grid key={row.id} container spacing={2} alignItems="center">
<Grid item xs={1}>
<IconButton
disabled={labels.length <= 0}
onMouseDown={() => deleteLabel(viewModel, row.id)}
onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteLabel(viewModel, row.id))}
data-testid={'button-delete-label-row-' + row.id}
>
<Tooltip title={'Label löschen' /*t('clauses.delete')*/}>
<DeleteIcon />
</Tooltip>
</IconButton>
</Grid>
<Grid item xs={11}>
<TextField
margin="dense"
label={'Label' /*t('clauses.input.value')*/}
fullWidth
variant="outlined"
value={row.term}
onChange={(e) => changeLabel(viewModel, row.id, 'freeInput', e.target.value)}
InputProps={{ inputProps: { min: 1 } }}
data-testid={'enter-label-row'}
/>
</Grid>
</Grid>
))}
</>
);
};
79 changes: 39 additions & 40 deletions src/view/StatementManipulation.tsx
Original file line number Diff line number Diff line change
@@ -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<StatementManipulationProps> = (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) => (
<Grid key={row.id} container spacing={2} alignItems="center">
<Grid item xs={1}>
<IconButton
disabled={statements.length <= 0}
onMouseDown={() => deleteStatement(viewModel, row.id)}
onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteStatement(viewModel, row.id))}
data-testid={'button-delete-statement-row-' + row.id}
>
<Tooltip title={'Statement löschen' /*t('clauses.delete')*/}>
<DeleteIcon />
</Tooltip>
</IconButton>
</Grid>
<Grid item xs={11}>
<TextField
margin="dense"
label={'Statement' /*t('clauses.input.value')*/}
fullWidth
variant="outlined"
value={row.term}
onChange={(e) => changeStatement(viewModel, row.id, 'freeInput', e.target.value)}
InputProps={{ inputProps: { min: 1 } }}
data-testid={'enter-statement-row'}
/>
</Grid>
</Grid>
))}
</>
);
return (
<>
{statements.map((row) => (
<Grid key={row.id} container spacing={2} alignItems="center">
<Grid item xs={1}>
<IconButton
disabled={statements.length <= 0}
onMouseDown={() => deleteStatement(viewModel, row.id)}
onKeyDown={(e) => executeOnKeyboardClick(e.key, () => deleteStatement(viewModel, row.id))}
data-testid={'button-delete-statement-row-' + row.id}
>
<Tooltip title={'Statement löschen' /*t('clauses.delete')*/}>
<DeleteIcon />
</Tooltip>
</IconButton>
</Grid>
<Grid item xs={11}>
<TextField
margin="dense"
label={'Statement' /*t('clauses.input.value')*/}
fullWidth
variant="outlined"
value={row.term}
onChange={(e) => changeStatement(viewModel, row.id, 'freeInput', e.target.value)}
InputProps={{ inputProps: { min: 1 } }}
data-testid={'enter-statement-row'}
/>
</Grid>
</Grid>
))}
</>
);
};

0 comments on commit 6f51770

Please sign in to comment.