Repository navigation
fix(products): stop saving the uploaded icon file record into a category's icon - #157
Merged
Merged
Conversation
…ory's icon
Uploading an icon in the new and edit product category modals set the
category's `icon` string attribute to the uploaded File record as well as
`icon_file_uuid` and `icon_url`. The string transform turned the record into
"<model::file:{uuid}>", which the save sent and core-api stored in
`categories.icon`, in place of any icon name the category had. The upload now
sets only `icon_file_uuid` and `icon_url`, as the catalog category modal does.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Uploading an icon in the New product category and Edit category modals saved a stringified File record into the category's
iconcolumn. The upload callback seticon: uploadedFilenext toicon_file_uuidandicon_url.iconis a string attribute on the console's category model. Ember Data's string transform callsString(record), so the save sent"icon": "<model::file:{file uuid}>". core-api mass-fillsicon(it is inCategory::$fillable), so that string replaced any icon name the category had.The callbacks now set only
icon_file_uuidandicon_url. The catalog category modal does the same since #155.Related Issue
None. Found while working on #155.
Type of Change
Implementation Notes
addon/controllers/products/index/category.js(editCategory→uploadNewPhoto) andaddon/controllers/products/index.js(createNewProductCategory→uploadNewPhoto): removedicon: uploadedFile. The icon file stays linked throughicon_file_uuid, andicon_urlpreviews it.tests/dummy/app/models/category.js: the console category stand-in getsicon,icon_color,icon_file_uuidandcompany_uuid. These lines match fix(catalogs): edit a catalog category's name, description and icon in a modal #155's, so the two branches merge cleanly (checked withgit merge-treeagainst fix(catalogs): edit a catalog category's name, description and icon in a modal #155 and feat(categories): nest product and catalog categories up to three levels #156).tests/unit/controllers/products/category-icon-upload-test.js: covers both upload callbacks. The test serializes with the app's REST serializer, which is the base of the console's category serializer.Validation
How I confirmed the bug, before the fix:
Request payload: I ran the new tests against the unfixed controllers, logging
category.serialize()after the upload callback. Both flows sent"icon":"<model::file:file-new>", and both tests failed becausecategory.iconheld the File record.DB: in the local application container, inside a transaction I rolled back, I called
Category::createRecordFromRequest()with that payload.categories.iconstored<model::file:00000000-0000-0000-0000-000000000001>. After the rollback, 0 rows were left.Tests
Lint
Build
Manual validation
Command output / summary:
I didn't run a build or check the change in the console: the local dev server isn't running, and this PR changes no templates. No server code changed, so PHP coverage is unaffected.
Documentation Impact
fleetbase/fleetbase.ioAPI Reference Impact
fleetbase/postmanAPI reference notes: none. The API is unchanged. The console just stops sending a bad
iconvalue.Documentation Notes
None.
Risk
Low. The upload no longer touches
icon, so a category's icon name is kept. Product categories that already had an icon uploaded may still hold a<model::file:…>value incategories.icon. My local DB had none. Nothing in the Storefront console renders a product category'sicon, so those values are harmless, and this PR doesn't clean them up.Screenshots / Recordings
None. No UI change.