Skip to content

Commit

Permalink
feat: allow users to put custom url when adding apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Oct 15, 2021
1 parent 1823b80 commit cfeb8c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cypress/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const mockGetAppListRoute = (apps) => {
(req) => {
req.reply(apps);
},
).as('useApps');
).as('getApps');
};


Expand Down
49 changes: 22 additions & 27 deletions src/components/item/form/AppForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import Typography from '@material-ui/core/Typography';
import { InputLabel, Select, MenuItem, FormControl, makeStyles } from '@material-ui/core';
import { makeStyles, TextField } from '@material-ui/core';
import { Autocomplete } from '@material-ui/lab';
import BaseItemForm from './BaseItemForm';
import { buildAppExtra, getAppExtra } from '../../../utils/itemExtra';
import { hooks } from '../../../config/queryClient';
Expand All @@ -19,45 +20,39 @@ const useStyles = makeStyles((theme) => ({
const AppForm = ({ onChange, item }) => {
const { t } = useTranslation();

const handleAppUrlInput = (event) => {
onChange({ ...item, extra: buildAppExtra({ url: event?.target?.value }) });
const handleAppUrlInput = (event, newValue) => {
const url = newValue?.url ?? newValue;
onChange({ ...item, extra: buildAppExtra({ url }) });
};

const classes = useStyles()
const { useApps } = hooks;
const { data } = useApps();

const entries = data ?
data?.map(elt => (
<MenuItem value={elt.url}>
<img className={classes.img} src={elt.extra.image} alt={elt.name} />
{elt.name}
</MenuItem>
))
:
<MenuItem />;


const url = getAppExtra(item?.extra)?.url;

return (
<div>
<Typography variant="h6">{t('Create an App')}</Typography>
<BaseItemForm onChange={onChange} item={item} />

<FormControl fullWidth>
<InputLabel>{t('App url')}</InputLabel>
<Select
id={ITEM_FORM_APP_URL_ID}
margin="dense"
label={t('App url')}
value={url}
onChange={handleAppUrlInput}
fullWidth
>
{entries}
</Select>
</FormControl>
<Autocomplete
id={ITEM_FORM_APP_URL_ID}
freeSolo
options={data?.toArray()}
getOptionLabel={(option) => option.name ?? option}
value={url}
onChange={handleAppUrlInput}
onInputChange={handleAppUrlInput}
renderOption={(option) => (
<>
<img className={classes.img} src={option.extra.image} alt={option.name} />
{option.name}
</>
)}
// eslint-disable-next-line react/jsx-props-no-spreading
renderInput={(params) => <TextField {...params} label="Combo box" />}
/>
</div>
);
};
Expand Down

0 comments on commit cfeb8c0

Please sign in to comment.