Skip to content

Commit

Permalink
fix form submit (finos#38)
Browse files Browse the repository at this point in the history
* fix form submit

* Fix tempalte name name field reloading workbench + submit appChannel addContextListener on enter

* Update toolbox/fdc3-workbench/src/components/AppChannels.tsx

Co-authored-by: Kris West <kris@cosaic.io>
  • Loading branch information
kenny-ciq and kriswest authored Nov 16, 2022
1 parent 939f86c commit 03335b6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 46 deletions.
13 changes: 10 additions & 3 deletions toolbox/fdc3-workbench/src/components/AppChannels.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { FormEvent, useState } from "react";
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles";
import { Button, IconButton, Tooltip, Typography, Grid, TextField } from "@material-ui/core";
import { observer } from "mobx-react";
Expand Down Expand Up @@ -126,7 +126,8 @@ export const AppChannels = observer(({handleTabChange} : {handleTabChange:any})
const contextListenersOptions = Array.from(new Map(contextListenersOptionsAll.reverse().map((item) => [item["type"], item])).values()).reverse();


const handleGetorCreateChannel = () =>{
const handleGetorCreateChannel = (e: FormEvent | null = null) =>{
e?.preventDefault()
if (currentAppChannelId) {
let foundChannel = appChannelStore.appChannelsList.find((currentChannel)=>currentChannel.id === currentAppChannelId);
if (!foundChannel) {
Expand Down Expand Up @@ -226,7 +227,7 @@ export const AppChannels = observer(({handleTabChange} : {handleTabChange:any})
<Typography variant="h5">Get Channel</Typography>
</Grid>

<form className={classes.form} noValidate autoComplete="off">
<form className={classes.form} noValidate autoComplete="off" onSubmit={(e) => handleGetorCreateChannel(e)}>
<Grid container direction="row" spacing={1}>
<Grid item className={classes.field}>
<TextField
Expand Down Expand Up @@ -321,6 +322,12 @@ export const AppChannels = observer(({handleTabChange} : {handleTabChange:any})
helperText={channel.listenerError}
/>
)}
onKeyDown={(event) => {
if (event.key === 'Enter') {
event.defaultPrevented = true;
handleAddContextListener(channel.id);
}
}}
/>
</Grid>

Expand Down
7 changes: 4 additions & 3 deletions toolbox/fdc3-workbench/src/components/ContextCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useRef } from "react";
import React, { useEffect, useState, useRef, FormEvent } from "react";
import { observer } from "mobx-react";
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles";
import { Button, Grid, Typography, Tooltip, IconButton, Table, TableBody, TableRow, TableCell, TableContainer } from "@material-ui/core";
Expand Down Expand Up @@ -195,7 +195,8 @@ export const ContextCreate = observer(({contextName}: {contextName:string}) => {
setDisabled(true);
};

const handleSaveTemplate = () => {
const handleSaveTemplate = (e: FormEvent | null = null) => {
e?.preventDefault();
const isValid: boolean = validate();

if (isValid && context && templateName) {
Expand Down Expand Up @@ -373,7 +374,7 @@ export const ContextCreate = observer(({contextName}: {contextName:string}) => {
</Grid>
</form>

<form className={classes.form} noValidate autoComplete="off">
<form className={classes.form} noValidate autoComplete="off" onSubmit={(e)=>handleSaveTemplate(e)}>
<Grid container direction="row" spacing={1} className={classes.rightAlign}>
<Grid item xs={12} className={`${classes.controls} ${classes.templateSelect}`}>
<Grid item xs={6} className={classes.field}>
Expand Down
8 changes: 4 additions & 4 deletions toolbox/fdc3-workbench/src/components/ContextLinking.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { FormEvent, useState } from "react";
import { observer } from "mobx-react";
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles";
import { Typography, Grid, Button, IconButton, Tooltip } from "@material-ui/core";
Expand Down Expand Up @@ -123,7 +123,8 @@ export const ContextLinking = observer(() => {
return filtered;
};

const handleAddContextListener = () => {
const handleAddContextListener = (e: FormEvent | null = null) => {
e?.preventDefault();
if (contextListener) {
if (contextStore.isContextListenerExists(contextListener.type)) {
setContextError("Listener already added");
Expand All @@ -141,8 +142,7 @@ export const ContextLinking = observer(() => {
<Grid item xs={12}>
<Typography variant="h5">Add Context Listener</Typography>
</Grid>

<form className={classes.form} noValidate autoComplete="off">
<form className={classes.form} noValidate autoComplete="off" onSubmit={(e) => handleAddContextListener(e)}>
<Grid
container
direction="row"
Expand Down
70 changes: 34 additions & 36 deletions toolbox/fdc3-workbench/src/components/ContextTemplates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,43 +121,41 @@ export const ContextTemplates = observer(({handleTabChange, contextStateSetter,

return (
<div className={classes.root}>
<form className={classes.form} noValidate autoComplete="off">
<Grid
container
direction="row"
spacing={1}
justifyContent="space-between"
className={`${classes.controls} ${classes.rightAlign}`}
>
<Grid item className={classes.contextName}>
<Autocomplete
id="context-"
size="small"
selectOnFocus
blurOnSelect
clearOnBlur
handleHomeEndKeys
value={context}
onChange={handleChange(setContext, setContextError)}
getOptionSelected={(option, value) => option.value === value.value}
filterOptions={filterOptions}
options={contextsOptions}
getOptionLabel={getOptionLabel}
renderOption={(option) => option.title}
renderInput={(params) => (
<TemplateTextField
label="CONTEXT "
placeholder="Enter Context Type"
variant="outlined"
{...params}
error={!!contextError}
helperText={contextError}
/>
)}
/>
</Grid>
<Grid
container
direction="row"
spacing={1}
justifyContent="space-between"
className={`${classes.controls} ${classes.rightAlign}`}
>
<Grid item className={classes.contextName}>
<Autocomplete
id="context-"
size="small"
selectOnFocus
blurOnSelect
clearOnBlur
handleHomeEndKeys
value={context}
onChange={handleChange(setContext, setContextError)}
getOptionSelected={(option, value) => option.value === value.value}
filterOptions={filterOptions}
options={contextsOptions}
getOptionLabel={getOptionLabel}
renderOption={(option) => option.title}
renderInput={(params) => (
<TemplateTextField
label="CONTEXT "
placeholder="Enter Context Type"
variant="outlined"
{...params}
error={!!contextError}
helperText={contextError}
/>
)}
/>
</Grid>
</form>
</Grid>
</div>
);
});

0 comments on commit 03335b6

Please sign in to comment.