Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make aspect multi select input #213

Open
wants to merge 1 commit into
base: NewForm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/components/Chip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import React, { useEffect } from 'react'
import { Theme, useTheme } from '@mui/material/styles'
import Box from '@mui/material/Box'
import OutlinedInput from '@mui/material/OutlinedInput'
import InputLabel from '@mui/material/InputLabel'
import MenuItem from '@mui/material/MenuItem'
import FormControl from '@mui/material/FormControl'
import Select, { SelectChangeEvent } from '@mui/material/Select'
import Chip from '@mui/material/Chip'
import data from '../Form'
import { useState } from 'react'
import CancelIcon from '@mui/icons-material/Cancel'
import { FormHelperText } from '@mui/material'
import { useController, Control } from 'react-hook-form'
import Select, { SelectChangeEvent } from '@mui/material/Select'
import { Box, MenuItem, FormHelperText, InputLabel, FormControl, OutlinedInput, Chip } from '@mui/material'

const ITEM_HEIGHT = 48
const ITEM_PADDING_TOP = 8

const MenuProps = {
PaperProps: {
style: {
Expand All @@ -22,10 +18,19 @@ const MenuProps = {
}

const names = ['Impact', 'Quality', 'Test', 'RelationShip']
interface MultipleSelectChipProps {
name: string
control: Control<any>
}

export default function MultipleSelectChip({ name, control }: MultipleSelectChipProps) {
const { field } = useController({
control,
name
})

export default function MultipleSelectChip() {
const theme = useTheme()
const [options, setOptions] = React.useState<string[]>([])
const { value, onChange } = field
const [options, setOptions] = useState<string[]>(value)

const handleChange = (event: SelectChangeEvent<typeof options>) => {
const {
Expand All @@ -39,6 +44,7 @@ export default function MultipleSelectChip() {
}

setOptions(selectedValues)
onChange(selectedValues)
}

const handleDelete = (value: any) => {
Expand All @@ -51,6 +57,7 @@ export default function MultipleSelectChip() {
setOptions(options.filter(name => name !== value))
}
}

return (
<div>
<FormControl sx={{ m: 1, width: 250 }}>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const Form = ({
claim: 'rated',
object: '' as string,
statement: '' as string,
aspect: '' as string,
aspect: [],
howKnown: '' as string,
sourceURI: '' as string,
effectiveDate: new Date(),
Expand Down Expand Up @@ -174,7 +174,7 @@ export const Form = ({
setValue('object', '')
} else {
setValue('stars', null)
setValue('aspect', '')
setValue('aspect', [])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah so we want this, but it requires other changes actually on front end - we have to create multiple claims and sign and submit all, in front end

because back end can't sign a claim

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh we know we make it till we change in the data model

}
}, [watchClaim, setValue])

Expand Down Expand Up @@ -333,7 +333,7 @@ export const Form = ({
{watchClaim === 'rated' ? (
<>
<Tooltip title='A specific dimension being evaluated or rated' placement='right' arrow>
<MultipleSelectChip />
<MultipleSelectChip control={control} name={'aspect'} />
</Tooltip>

<Controller
Expand Down