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

🐛 fix(autocomplete): tags not generated for preselected options #1403

Prev Previous commit
Next Next commit
use set for tag options, filter shown tags with other source
Signed-off-by: gitdallas <dallas.nicol@gmail.com>
  • Loading branch information
gitdallas committed Sep 27, 2023
commit ba418c1a7534c7923312bba082d5198a5cc901a8
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,12 @@ export const ApplicationForm: React.FC<ApplicationFormProps> = ({
}
}, []);

const tagOptions =
tags
?.filter((tag) => !tag.source)
.map((tag) => {
return {
value: tag.name,
toString: () => tag.name,
};
}) || [];
const tagOptions = new Set(
(tags || []).reduce<string[]>(
(acc, curr) => (!curr.source ? [...acc, curr.name] : acc),
[]
)
);

const getBinaryInitialValue = (
application: Application | null,
Expand Down Expand Up @@ -387,7 +384,7 @@ export const ApplicationForm: React.FC<ApplicationFormProps> = ({
];

const getTagRef = (tagName: string) =>
tags?.find((tag) => tag.name === tagName);
Object.assign({ source: "" }, tags?.find((tag) => tag.name === tagName));

return (
<Form onSubmit={handleSubmit(onSubmit)}>
Expand Down Expand Up @@ -448,15 +445,14 @@ export const ApplicationForm: React.FC<ApplicationFormProps> = ({
label={t("terms.tags")}
fieldId="tags"
renderInput={({ field: { value, name, onChange } }) => {
const selections = value
.map(
(formTag) =>
tags?.find((tagRef) => tagRef.name === formTag.name)
)
.map((matchingTag) =>
matchingTag ? matchingTag.name : undefined
)
.filter((e) => e !== undefined) as string[];
console.log(value);
const selections = value.reduce<string[]>(
(acc, curr) =>
curr.source === "" && tagOptions.has(curr.name)
? [...acc, curr.name]
: acc,
[]
);

return (
<Autocomplete
Expand All @@ -468,7 +464,7 @@ export const ApplicationForm: React.FC<ApplicationFormProps> = ({
.filter((sel) => sel !== undefined) as TagRef[]
);
}}
options={tagOptions.map((o) => o.value)}
options={Array.from(tagOptions)}
placeholderText={t("composed.selectMany", {
what: t("terms.tags").toLowerCase(),
})}
Expand Down