Skip to content

Conversation

@sldblog
Copy link
Contributor

@sldblog sldblog commented Mar 13, 2023

Extends the type: Product schema to allow a new attribute, only.

We want to allow creators to choose the relevant types of products for blocks using this type.

Example:

Experiences:
  group: content
  label: Select featured experiences
  type: Product
  array: true
  default:
    - random
    - random
    - random
  only:
    - experiences

@sldblog sldblog requested review from a team, eballantine and ianmooney and removed request for a team March 13, 2023 13:18
@sldblog
Copy link
Contributor Author

sldblog commented Mar 13, 2023

@eballantine eballantine self-assigned this Mar 13, 2023
@sldblog
Copy link
Contributor Author

sldblog commented Mar 13, 2023

❓ I decided not to validate the values as if we need to expand that, that would require a schema change. Semantically, however, it can result in excluding everything if there's a typo like expereince. What would you suggest?

@eballantine
Copy link
Contributor

❓ I decided not to validate the values as if we need to expand that, that would require a schema change. Semantically, however, it can result in excluding everything if there's a typo like expereince. What would you suggest?

So this canvas gem is used for theme developers to lint the theme before making changes, and therefore personally I think it should validate the exact values of 'experience' or 'accommodation' so they're not committing code that won't work.

I've just added another example to the Trello ticket for how this should also be an option on the variant type. But appreciate if you want to tackle that separately.

I'm also just going to say 'extras' as I'm not sure if we've fully considered them for this work. We maybe we need to have refinement of the ticket to be clear what's in scope, let me know when you're free to discuss cc:@ianmooney

Copy link
Contributor

@eballantine eballantine left a comment

Choose a reason for hiding this comment

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

Hey @sldblog thanks for the rubocop clearup along the way.

I wasn't sure how to go about testing this and either I still haven't figured it out or, this is not behaving as we'd like it to. Please correct my approach:

  1. I've checked out this branch
  2. Run canvas lint inside a local version of a theme (alchemist in my case).

If I update a block schema to use only in the way we've outlined, then I get the below failure.

Screenshot 2023-03-13 at 14 12 22

@sldblog
Copy link
Contributor Author

sldblog commented Mar 13, 2023

Thanks @eballantine, I will add the choice validation here. I'm unsure what the options would be for variants, can we catch up offline about that, please?

Copy link
Contributor

@ianmooney ianmooney left a comment

Choose a reason for hiding this comment

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

Nice one, David. I just left a couple comments in there.

end

def optional_keys
super.merge("only_show" => Array)
Copy link
Contributor

Choose a reason for hiding this comment

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

Now I'm looking at it, I wonder if only reads better than only_show.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should validate that the values passed to the only_show option are from an allowed list of options (experiences, accommodations and extras). I think these should be lower case but I don't have a strong opinion whether they should be pluralised or not.

This is because this list of allowed options is unlikely to change and if it did it would warrant a update to this canvas gem.

Copy link
Contributor Author

@sldblog sldblog Mar 13, 2023

Choose a reason for hiding this comment

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

done in 5ec1e53

sldblog added 2 commits March 13, 2023 18:37
Warning: obsolete parameter `IgnoredMethods` (for `Style/BlockDelimiters`) found in .rubocop.yml
`IgnoredMethods` has been renamed to `AllowedMethods` and/or `AllowedPatterns`.
Warning: Style/BlockDelimiters does not support IgnoredMethods parameter.
The new attribute is

1. optional
2. has to be a non-empty array

The intent is to provide a way for creators and theme developers to
limit the available options to either experiences or accommodation, as
appropriate.

I decided not to validate the allowed values as I thought that would be
too restrictive in the schema.
@sldblog sldblog force-pushed the support-limiting-options-for-product branch 2 times, most recently from b0c8634 to ea407d4 Compare March 13, 2023 18:53
@sldblog
Copy link
Contributor Author

sldblog commented Mar 13, 2023

@ianmooney @eballantine 👍 Thank you for your reviews!
Renamed to only in 7c36d16 and added the restrictions in 5ec1e53

@sldblog sldblog force-pushed the support-limiting-options-for-product branch from 0e28164 to db14753 Compare March 14, 2023 11:47
sldblog added 2 commits March 14, 2023 11:48
To avoid accidental typos and misuse in the user input
(This is a new, non-breaking feature)
@sldblog sldblog force-pushed the support-limiting-options-for-product branch from db14753 to f4e5214 Compare March 14, 2023 11:48
sldblog added 2 commits March 14, 2023 12:17
It's generally quicker than installing the gem, but installing the gem
is better for final testing
@sldblog sldblog force-pushed the support-limiting-options-for-product branch from f4e5214 to e5ab567 Compare March 14, 2023 12:17
@ianmooney ianmooney self-assigned this Mar 14, 2023
Copy link
Contributor

@ianmooney ianmooney left a comment

Choose a reason for hiding this comment

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

Works great 🚀

```
cd alchemist_theme
../canvas/bin/canvas lint
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice one for updating these docs with a quicker way to test things 🚀

@sldblog sldblog merged commit 7e6f65f into main Mar 14, 2023
@sldblog sldblog deleted the support-limiting-options-for-product branch March 14, 2023 13:41
@sldblog
Copy link
Contributor Author

sldblog commented Mar 14, 2023

🎩 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants