Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: ensure we handle null values on description #554
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: ensure we handle null values on description #554
Changes from all commits
e90481e
40ed8d4
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Why we need mock for svg?
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.
see https://github.com/zendesk/copenhagen_theme/pull/554/files#r1888290869
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 don't think we need to check if type is string but just to check if it is not null. In
ServiceCatalogItem
type we assign type string to description.Other question is for product if we want to allow to save service catalog item with empty description? If yes so we need to change the type.
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.
the typeof description being string was a suggestion from copilot, because instead of checking for null its safer to check typeOf being string because the "length" method requires a string - meaning its a safer check
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 would change that on the API side so it will be a string or empty string as Luis suggested in the JIRA ticket.
We know that if it won't be null it will be 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.
if we change it on the backend its a larger change as it affects every single ticketfield, we cant limit it to service catalog items? Because every item would then need to have a default of empty string on the TicketField initialization, but thats not how we are treating other fields.
so instead of initializing the ticket fields as we currently do:
we'd have to prefill to a string on each initialization:
My qualm with this approach is that it affects every single part of the codebase using ticketfields, instead of just our own isolated code - and I'm uncertain if there won't be any code thats running a check on whether this value is present or not. Surely changing just our own code in the front end is a more isolated, and thus safer change?
Unless we have some other layer here I could insert the change on that im missing..? @luis-almeida
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.
however instead of api level maybe what is actually meant is at api request level, where we fallback to some default values should they not be available? In which case the change would still be in this repo where we are placing the request
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.
The problem doesn't seem to be with the
description
of ticket fields. That is already an empty string when not set from what I can see.This seems to be the
description
of the Service Catalog Item we're fetching from/api/v2/help_center/service_catalog/items/:id
and we're in full control of that end point in Help Center.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.
makes sense thanks, closing this one
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.
(nit) Maybe we can check for the presence of the description here instead of using typeof. I believe when you do something like
It returns false for both
null
andundefined
. No strong feelings here though, since we know the exact type of the description.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.
We don't need additional function, something like this should be enough:
const showToggleButton = description != null && description.length > DESCRIPTION_LENGTH_THRESHOLD;
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 extracted it so I could test it, otherwise it can't be tested in isolation
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 don't think we need test for such a small function so that makes us to install new dependencies like svgMock
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.
its not a dependency install, no new packages were added - just a mock, and this is the same we do for testing in other jest cases. As soon as we increase our test coverage - which I don't understand quite why we don't have more tests on this repo already - it becomes needed, so unsure why not add it now?