-
Notifications
You must be signed in to change notification settings - Fork 43
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
🐛 fix(autocomplete): tags not generated for preselected options #1403
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1403 +/- ##
==========================================
- Coverage 41.05% 41.01% -0.05%
==========================================
Files 137 137
Lines 4338 4333 -5
Branches 1043 1045 +2
==========================================
- Hits 1781 1777 -4
Misses 2469 2469
+ Partials 88 87 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Just noticed that the app can have multiple tags with the same name from different sources. This is causing duplicate tags to render in the UI Wondering if this enhancement would fall under #1321 or if we would need to be able to display tag by category AND source in this dropdown. |
@ibolton336 - how would this work in practice? should there be tags with the same id/name and a different source? how would the labels/tags look in this case? |
|
@gitdallas I am thinking that any tag that is not of source type "" (empty string aka "manual") should be hidden from this view. Maybe there is a read only field that might display tags associated to an app by archetype / assessment / analysis. IIRC this screen only lets you select "manual" source tags so in turn I think we should only be displaying "manual" source tags as selectable/deselectable. |
@ibolton336 - the but i added a filter on them so anything with a truthy |
Signed-off-by: gitdallas <[email protected]>
Signed-off-by: gitdallas <[email protected]>
Signed-off-by: gitdallas <[email protected]>
Signed-off-by: gitdallas <[email protected]>
40bd22a
to
53069c0
Compare
Sounds good @gitdallas - Looks like we have a "source" optional property on the TagRef so at least we are covered there. The Tags from the tags api won't have a source since they aren't associated with an app/archetype yet. |
const selections = value | ||
.map( | ||
(formTag) => | ||
tags?.find((tagRef) => tagRef.name === formTag.name) | ||
) | ||
.map((matchingTag) => | ||
matchingTag ? matchingTag.name : undefined | ||
) | ||
.filter((e) => e !== undefined) as string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const selections = value | |
.map( | |
(formTag) => | |
tags?.find((tagRef) => tagRef.name === formTag.name) | |
) | |
.map((matchingTag) => | |
matchingTag ? matchingTag.name : undefined | |
) | |
.filter((e) => e !== undefined) as string[]; | |
const tagNames = new Set(tags?.map((tag) => tag.name)); | |
const selections = value.flatMap((formTag) => | |
formTag.source === "" && tagNames.has(formTag.name) | |
? [formTag.name] | |
: [] | |
); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Played around with this a bit and borrowed Mikes suggestion of using a Set/has here instead of creating a map and using includes since set narrows the tags to unique values & boosts performance. Explicitly checking for the empty string source on the form tag on lookup should give us what we want since empty string source here means "manually selected tag" for a tag on an application object (a formTag in this case) .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up making tagOptions
a set of strings (tag names) from the beginning and using that. Also as the onChange event maps the form values to tags
(which seems to have undefined source instead of ""), I merge a {source:""}
object when returning from getTagRef
. Without this, after making any changes to the value we'd filter them out if they didn't have a source prop in the tags
array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticing that onSubmit, any tags that are filtered out from the selections on line 448 are not being added back in to the payload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, looks like even when we patch the object with the "archetype tags" not included, the hub just adds them back anyway. Need to check with Sam on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sam confirmed that there is no way for us to overwrite those non-manual tags by updating the application object directly so we should be good on what we are passing to the put request here. There seems to be some ongoing discussion/weirdness around this since the non-manual tags are "virtual" tags being inherited from other membership criteria etc.
We do need to make sure we are filtering out any pre-existing, non-manual tags in the selectable tag list so that we can't accidentally create a new "manual" tag for a tag that already exists on the application from a different source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure if there is a change you're asking for or if you are saying to wait.
Right now it is using tags
(filtered to only include undefined or "" source value) as the available options and not letting the user add new tags that don't exist outside the options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood - My concern was that after we are filtering out the tags on an app with a source other than "", we never add them back in to the tags payload on submit so we'd be overwriting those tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now it is using tags (filtered to only include undefined or "" source value) as the available options and not letting the user add new tags that don't exist outside the options.
The change I think we might temporarily need is to check to see if any tags in the "tagOptions" list you've created match up with any other tags on the application (archetype source or other non-manual tags) and remove any matching available tag from the list. The tags api fetch response won't include any tags with other sources . Those sources are only on tagRefs for tags that have been associated with an application or archetype on their respective api object. We would have to cross check the response from the tags fetch api with what exists on the application in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example:
const filteredTagOptions = new Set(
[...tagOptions].filter(
(tagOption) => {
const matchingAppTag = application.tags.find((appTag) => appTag.name === tagOption);
if (!matchingAppTag) return true;
if (matchingAppTag.source === '') return true;
return false;
}
)
);
Signed-off-by: gitdallas <[email protected]>
Signed-off-by: gitdallas <[email protected]>
I'm looking at this PR today while rebasing #1408 on this change. A few things are quite confusing. First, the list of tags generated from the tagCategories are just const tags = (tagCategories || []).flatMap((tc) => tc.tags || []);
const tagOptions = new Set(tags.map((t) => t.name)); Second, the Any further filtering of the set of tags to display etc should probably just be done in the same general area as where const applicationManualTags =
new Set(application?.tags?.filter((t) => t.source === "").map((t) => t.name) ?? []);
const applicationSourcedTags =
new Set(application?.tags?.filter((t) => t.source !== "").map((t) => t.name) ?? []);
const manualTagOptions = new Set(
tags.map((t) => t.name).filter((name) => !applicationSourcedTags.has(name))
); Then drive the select box with |
Agreed that this could use another pass @sjd78. This issue was blocking QE so wanted to get something in for them so that they can fix their automated tests. You raise some good points. |
### Contributors field The `contributors` field on the `Application` payload needs to be a pure `Ref` object or it will be rejected by the REST API call. Adopt the same set of data transforms used in the archetype-form to handle getting the correct set of data. Related changes (came up when working on #1331 that ended up revealing #1404): - REST `createApplication()` function updated to have the proper return type (response data is not unwrapped) - Query `useCreateApplicationMutation()` updated to properly pass the newly created `Application` to the `onSuccess()` handler - `onCreateApplicationSuccess()` in the application form updated to use the correct `onSuccess()` response data Resolves: #1404 ### Tags field Followup #1403 to update the way tags are updated to an existing application. Tags that are from an analysis need to be included with the update payload or they will be removed. This is different behavior from archetype or assessment sourced tags. No updates to an application can remove archetype or assessment tags. Summary of changes and refactoring: - As form values, keep the tags using just the tag name as a string - Moved all data access/mutation code to hook `useApplicationFormData()` to logically divide concerns (data access v. UI handling) - Tags dropdown will only display/edit the application's "Manual tags" - `onSubmit()`'s payload building simplified using partially curried helper functions - Migrate to use `ItemsSelect` for handling the Tags Update `useUpdateApplicationMutation()` to provide the mutation's payload to the `onSuccess()` function. This allows the `onSuccess()` function to toast a message with the application's name. Add utility functions to `model-utils.tsx`: - convert objects that look like `Ref` object into exactly a `Ref` object: - toRef() - toRefs() - Match a set of items that look like `Ref` objects against a (set of) values and return the matching items as exactly `Ref` objects: - matchItemsToRef() - matchItemsToRefs() --------- Signed-off-by: Scott J Dickerson <[email protected]>
closes jira 1315