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

[BUU] Change name of my products 🚧 #11208

Merged
merged 18 commits into from Aug 24, 2023

Conversation

dacook
Copy link
Member

@dacook dacook commented Jul 13, 2023

What? Why?

Adding a new bulk update form for product names, submitting using Reflex.
You can edit the name of any product (but we don't yet highlight modified/unsaved fields)
On saving, any modified products will attempt to update
Any errors are captured and some information is displayed to the user (more to be added in next PR).
On successful save, the table reloads to show saved fields (but there's no success message yet).

Editing:
Screen Shot 2023-08-18 at 4 44 24 pm
Errors:
Screen Shot 2023-08-18 at 4 43 46 pm

What should we test?

No testing required, this is a work in progress behind feature toggle.

Release notes

Changelog Category: Feature toggle

@dacook dacook changed the base branch from master to backoffice-ui-uplift July 28, 2023 05:48
@dacook dacook force-pushed the buu-editing-11059 branch 2 times, most recently from 862114c to 91f0c1f Compare August 9, 2023 03:34
@dacook dacook force-pushed the backoffice-ui-uplift branch 2 times, most recently from 868b648 to 73bfe63 Compare August 10, 2023 03:47
@jibees jibees force-pushed the backoffice-ui-uplift branch 5 times, most recently from 90fdda1 to e9640d7 Compare August 14, 2023 12:42
@dacook dacook changed the base branch from backoffice-ui-uplift to master August 18, 2023 05:15
@dacook dacook force-pushed the buu-editing-11059 branch 2 times, most recently from bcd809a to b3a7e14 Compare August 18, 2023 06:36
@dacook dacook changed the title Buu editing 11059 [BUU] Change name of my products 🚧 Aug 18, 2023
@dacook dacook marked this pull request as ready for review August 18, 2023 06:48
@dacook dacook requested a review from jibees August 18, 2023 06:49
@dacook
Copy link
Member Author

dacook commented Aug 18, 2023

Oops, I missed a broken spec. JB I think it would still be worth your review if you have the chance. I'll next look at it on Tuesday.

Copy link
Contributor

@jibees jibees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed a broken spec.

I suppose this was a flaky one?

BTW, real nice job!

Quick comments:

  • Should we hide form-actions toolbar if no modification are currently made?
  • I tried to modify a product name, but I received an error. Even if I don't change any name, and click on "Save changes" button, I received an error ("
#<ActiveModel::Error attribute=base, type=Image attachment is not a valid image., options={}>

I suppose this is related to an old product on my page?

).broadcast
morph :nothing

# dunno why this doesn't work.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me as well.


// "Naked" inputs. Row hover helps reveal them.
input {
border-color: transparent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change background color as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Currently, the input background and the row background are white.
When we have row:hover, background-color: $light-grey; and we rely on the input background-color: white.

So technically, the code doesn't ensure the inputs are naked (eg if one of the background colours change in the future), and I think we could add more rules to ensure that. But I don't think we should add more style rules until we need them.

app/webpacker/css/admin_v3/components/buttons.scss Outdated Show resolved Hide resolved
@@ -220,11 +220,13 @@ Metrics/ClassLength:
- 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
- 'app/models/spree/zone.rb'
- 'app/reflexes/products_reflex.rb'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems legit 👌

(For now at least,) we use one big standard Rails form, and ModelSet to update each record.
Submitting with Reflex allows us to manage the loading state along with the rest of the page (although I would rather use the built in HTTP POST standard).

Aria-label makes it a bit easier for testing (and accessibility software of course!). Technically it should have been aria-labelledby="id_of_column_header" but that would have resulted in more HTML and processing, which seemed silly.

Best viewed with whitespace ignored.
Perhaps this should be tested in the system spec too ("I can rename a product and still see it after saving"). But I'd like to find the compromise to avoid bulking up system specs too much. I think it's covered well enough by the reflex spec?
Before, it would abort after the first invalid record, and it doesn't tell you about the others. This way you find out about all at once.

This affects the existing Bulk Edit Products screen, and can result in longer error messages than before. But I would argue that's a good thing.

I think this is technically optional for BUU at this point, but a helpful improvement.
But it's not perfect. Can we use a pseudo element instead?
Inputs add extra padding, so we add the same padding to the header. Using an opt-in class, because I think we won't want this on all columns.
As much as I hate to add to this list, this is still a work in progress so it's not worth refactoring at this point.
@dacook
Copy link
Member Author

dacook commented Aug 22, 2023

Thanks @jibees,

  • Should we hide form-actions toolbar if no modification are currently made?

For sure. I plan to do this when implementing the modified/"dirty" field state.

  • I tried to modify a product name, but I received an error.

I suppose this is related to an old product on my page?

Yes I would guess so. It might be a good time to refresh your dev database.

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of suggestions but this is work in progress and it can all be changed later.

Comment on lines 169 to 171
# TO Consider: We could actually rearrange the form to suit that format more directly. eg:
# '[products][0][id]' (hidden field)
# '[products][0][name]'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that this is necessary when you want to support creating several new products in the same form. Then you can't use the id as index. But I find this approach of stuffing all kind of data into one action unnecessarily complex. Doing lots of stuff at once has the challenge of lots of things potentially failing and providing lots of error feedback while also adding a lot of logic regarding different actions to one thing. In this case the ModelSet encapsulates it quite well but it's still complicated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. At this stage, we want to provide that behaviour (updating multiple at once) so I think it makes sense to use the one form, for now. So far we haven't hit any issues with this method, so I'd avoid complicating it. For now..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about new products or deleting products? Will there be a separate form or UX?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume, new products will continue to be with a specific form, and deleting would be one-by-one.

But if we needed to do it in bulk here, then we could.. but like you say it makes things complicated!

app/services/sets/product_set.rb Outdated Show resolved Hide resolved
app/services/sets/product_set.rb Outdated Show resolved Hide resolved
Rails is clever enough to not query the database without ids

Co-authored-by: Maikel <maikel@email.org.au>
Copy link
Member Author

@dacook dacook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

app/services/sets/product_set.rb Outdated Show resolved Hide resolved
@drummer83
Copy link
Contributor

Hi @dacook,
This one ended up in 'Test Ready' but it's stating 'no testing required'.
Please proceed with this one as needed or let us know if testing is required.
Thanks!
BTW: Looking great! 😉

@filipefurtad0 filipefurtad0 added the pr-staged-uk staging.openfoodnetwork.org.uk label Aug 24, 2023
@filipefurtad0
Copy link
Contributor

Ok, I've staged the PR just as a quick check whether it staged with no issues, and made some bulk product edits, with the feature toggle on and off.

Nothing unusual, so merging not to block this work 👍

@filipefurtad0 filipefurtad0 merged commit cc3b7c6 into openfoodfoundation:master Aug 24, 2023
54 checks passed
@filipefurtad0 filipefurtad0 removed pr-staged-uk staging.openfoodnetwork.org.uk feedback-needed labels Aug 24, 2023
@dacook
Copy link
Member Author

dacook commented Aug 24, 2023

Thanks both! I think I wasn't aware of the pr-no-test label when I created this PR, but will try to remember in the future to help streamline things.

@mariocarabotta mariocarabotta added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Aug 29, 2023
dacook added a commit to dacook/openfoodnetwork that referenced this pull request Sep 6, 2023
dacook added a commit to dacook/openfoodnetwork that referenced this pull request Sep 6, 2023
dacook added a commit to dacook/openfoodnetwork that referenced this pull request Feb 23, 2024
@dacook dacook mentioned this pull request Feb 23, 2024
8 tasks
fleblond07 pushed a commit to fleblond07/openfoodnetwork that referenced this pull request Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

6 participants