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

Data entity group form bug #779 #782

Merged
merged 2 commits into from
Jul 6, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const DataEntityGroupForm: React.FC<DataEntityGroupFormProps> = ({
[dataEntityGroupDetails]
);

const { handleSubmit, control, reset, formState, setValue } =
const { handleSubmit, control, reset, formState, setValue, register } =
useForm<DataEntityGroupFormData>({
mode: 'onChange',
reValidateMode: 'onChange',
Expand Down Expand Up @@ -205,19 +205,12 @@ const DataEntityGroupForm: React.FC<DataEntityGroupFormProps> = ({
</AppTextField>
)}
/>
<Controller
control={control}
name="entities"
rules={{ required: true, validate: () => fields.length > 0 }}
render={({ field }) => (
<SearchSuggestionsAutocomplete
placeholder="Search entities"
label="Entities"
controllerProps={field}
append={append}
addEntities
/>
)}
<SearchSuggestionsAutocomplete
placeholder="Search entities"
label="Entities"
formOnChange={register('entities').onChange}
append={append}
addEntities
/>
<EntityItemsContainer sx={{ mt: 1.25 }}>
{fields?.map((entity, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const EntityItem: React.FC<TagItemProps> = ({
entity,
}) => (
<Container container>
<Grid container>
<Typography variant="body1" sx={{ mr: 1 }}>
<Grid container flexWrap="nowrap" sx={{ width: 'calc(100% - 24px)' }}>
<Typography variant="body1" sx={{ mr: 1 }} noWrap>
{entity.internalName || entity.externalName}
</Typography>
{entity.entityClasses?.map(entityClass => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
getDataEntityAddToGroupStatuses,
getDataEntityClassesList,
} from 'redux/selectors';
import SearchSuggestionsAutocomplete from 'components/shared/Autocomplete/SearchSuggestionsAutocomplete/SearchSuggestionsAutocomplete';
import { addDataEntityToGroup } from 'redux/thunks';
import SearchSuggestionsAutocomplete from 'components/shared/Autocomplete/SearchSuggestionsAutocomplete/SearchSuggestionsAutocomplete';

interface AddDataEntityToGroupFormProps {
btnCreateEl: JSX.Element;
Expand Down Expand Up @@ -95,7 +95,7 @@ const AddDataEntityToGroupForm: React.FC<
<SearchSuggestionsAutocomplete
placeholder="Search groups"
label="Group name"
controllerProps={field}
formOnChange={field.onChange}
searchParams={{
entityClassId: dataEntityGroupClassId,
manuallyCreated: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,22 @@ import EntityClassItem from 'components/shared/EntityClassItem/EntityClassItem';
import { useDebouncedCallback } from 'use-debounce';
import AppTextField from 'components/shared/AppTextField/AppTextField';
import ClearIcon from 'components/shared/Icons/ClearIcon';
import { ControllerRenderProps } from 'react-hook-form';
import AppButton from 'components/shared/AppButton/AppButton';
import { UseFieldArrayAppend } from 'react-hook-form/dist/types/fieldArray';
import { useAppDispatch, useAppSelector } from 'lib/redux/hooks';
import { fetchSearchSuggestions } from 'redux/thunks';
import {
getSearchSuggestions,
getSearchSuggestionsFetchingStatuses,
} from 'redux/selectors';
import { DataEntityGroupFormData } from 'components/DataEntityDetails/DataEntityGroupForm/DataEntityGroupForm';
import { AddDataEntityToGroupFormData } from 'components/DataEntityDetails/Overview/OverviewGroups/AddDataEntityToGroupForm/AddDataEntityToGroupForm';
import { UseFieldArrayReturn } from 'react-hook-form';

interface SearchSuggestionsAutocompleteProps {
placeholder: string;
label?: string;
addEntities?: boolean;
append?: UseFieldArrayAppend<DataEntityGroupFormData['entities']>;
append?: UseFieldArrayReturn['append'];
searchParams?: SearchApiGetSearchSuggestionsRequest;
controllerProps:
| ControllerRenderProps<DataEntityGroupFormData, 'entities'>
| ControllerRenderProps<AddDataEntityToGroupFormData, 'group'>;
formOnChange: (val: any) => void;
}

const SearchSuggestionsAutocomplete: React.FC<
Expand All @@ -38,8 +33,8 @@ const SearchSuggestionsAutocomplete: React.FC<
label,
addEntities,
append,
controllerProps,
searchParams,
formOnChange,
}) => {
const dispatch = useAppDispatch();

Expand Down Expand Up @@ -97,17 +92,15 @@ const SearchSuggestionsAutocomplete: React.FC<
};

const handleOptionChange = React.useCallback(
(onChange: (val?: DataEntityRef) => void) =>
(
_: React.ChangeEvent<unknown>,
value: Partial<DataEntityRef> | string | null
) => {
setSelectedOption(value as DataEntityRef);
onChange(value as DataEntityRef);
},
(
_: React.ChangeEvent<unknown>,
value: Partial<DataEntityRef> | string | null
) => {
setSelectedOption(value as DataEntityRef);
formOnChange(value);
},
[]
);

const handleAddEntity = () => {
if (append) {
append(selectedOption as DataEntityRef);
Expand Down Expand Up @@ -144,7 +137,6 @@ const SearchSuggestionsAutocomplete: React.FC<

return (
<Autocomplete
{...controllerProps}
fullWidth
value={{ externalName: searchText }}
open={autocompleteOpen}
Expand All @@ -155,7 +147,7 @@ const SearchSuggestionsAutocomplete: React.FC<
setAutocompleteOpen(false);
}}
onInputChange={handleInputChange}
onChange={handleOptionChange(controllerProps.onChange)}
onChange={handleOptionChange}
getOptionLabel={getOptionLabel}
options={options}
loading={isSearchSuggestionsLoading}
Expand Down