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

Use ProgrammingEnvironmentCategory in ProgrammingExpression #44735

Merged
merged 6 commits into from
Feb 10, 2022

Conversation

bethanyaconnor
Copy link
Contributor

@bethanyaconnor bethanyaconnor commented Feb 9, 2022

Put programming expressions in the new categories! This PR does a best attempt to match the expressions with a ProgrammingEnvironmentCategory and updates the programming expression edit page to use these. It also prevents deletion of any ProgrammingEnvironmentCategory that has a programming expression.

Note to reviewers: I'd suggest reviewing this in two parts. The code changes load a bit better by filtering out the json files. All the json file changes were in commit ca1ee8b so a quick look at that commit should be good for those changes.

Categories where some can be deleted and some can't:
Screen Shot 2022-02-07 at 3 54 41 PM

Follow-up work

I realized that this will soon break our search for code docs on the lesson edit page. I'll fix that in the coming week or so.

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@bethanyaconnor bethanyaconnor force-pushed the programming-expression-categories branch from 575c7ee to bf1f9d8 Compare February 9, 2022 18:09
@bethanyaconnor bethanyaconnor changed the title Programming expression categories Use ProgrammingEnvironmentCategory in ProgrammingExpression Feb 9, 2022
@bethanyaconnor bethanyaconnor marked this pull request as ready for review February 9, 2022 20:21
@bethanyaconnor bethanyaconnor requested review from a team and dmcavoy February 9, 2022 20:21
@dmcavoy
Copy link
Contributor

dmcavoy commented Feb 9, 2022

I realized that this will soon break our search for code docs on the lesson edit page. I'll fix that in the coming week or so.

How soon will this break things? Why will it break things?

@@ -7,7 +7,8 @@ export default function OrderableList({
list,
setList,
addButtonText,
renderItem
renderItem,
checkItemDeletionAllowed = item => true
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you tell me about how this works?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just setting a default if checkItemDeletionAllowed is not passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it's just a default. All items can be deleted unless a specific function is passed in to check.

@@ -39,9 +39,12 @@ describe('OrderableList', () => {
const wrapper = shallow(<OrderableList {...defaultProps} />);
wrapper
.find('.fa-trash')
.at(1)
.at('1')
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this at be changing to '1' too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops good catch. This is what I get for a too optimistic search/replace...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotta love JS allowing this to still work though

checkItemDeletionAllowed={item => item.key === '3'}
/>
);
expect(wrapper.find('.fa-trash').length).to.equal(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like there should be 2 trash icons because there should be 3 items. Is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only the third item is deletable. I waffled on which was to frame the function, i.e. checkItemDeletionAllowed or preventItemDeletion. Do you think the second one is clearer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohhhh I see. I think thats fine. I think I just didn't fully understand before.

programming_expression.palette_params = programming_expression_params[:parameters]
programming_environment_category = programming_expression.programming_environment.categories.find_by_key(programming_expression_params[:category_key])
programming_expression.programming_environment_category_id = programming_environment_category&.id
# TODO: get rid of this when we remove the category column
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the issue with search on lesson edit you called out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's related. The category column doesn't serve a function anymore so I was going to get rid of that column, but the lesson edit page allows searching by category.

@@ -17,6 +17,7 @@
#
class ProgrammingEnvironmentCategory < ApplicationRecord
belongs_to :programming_environment
has_many :programming_expressions, dependent: :restrict_with_error
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL!

@bethanyaconnor
Copy link
Contributor Author

How soon will this break things? Why will it break things?

Right now, it's fine. But with category moving off of the ProgrammingExpression model, we'll no longer be able to search by category, which we currently support. This is likely not a huge deal and can be worked around, just something I noticed yesterday.

if env_category
nil
else
environment_name == 'spritelab' ? expression_config['color'] : ProgrammingExpression.get_category_color(expression_config['category'])
Copy link
Contributor

Choose a reason for hiding this comment

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

what still falls back on the second case here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a bunch of programming expressions that don't have a ProgrammingEnvironmentCateogry. I'm going to clean a bunch of those up over the next several days then hopefully we won't need this case anymore.

exp = create :programming_expression, key: 'myExp', category: 'World', examples: 'myexamples', palette_params: 'some parameters', programming_environment_id: programming_environment.id
exp.color = ProgrammingExpression.get_category_color('World')
category = create :programming_environment_category, programming_environment: programming_environment, name: 'World', color: '#ABCDEF'
exp = create :programming_expression, key: 'myExp', category: 'World', examples: 'myexamples', palette_params: 'some parameters', programming_environment_id: programming_environment.id, programming_environment_category_id: category.id
Copy link
Contributor

Choose a reason for hiding this comment

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

Shoudl this still have category set separate from programming_environment_category?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah probably. I'll add that back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sorry, misunderstood the comment. I think that's fine for now as we still seed and serialize the category column

Copy link
Contributor

@dmcavoy dmcavoy left a comment

Choose a reason for hiding this comment

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

I only spot checked random of the json file changes but I think it looks good. Thanks for all your hard work on this

@bethanyaconnor bethanyaconnor merged commit 6821145 into staging Feb 10, 2022
@bethanyaconnor bethanyaconnor deleted the programming-expression-categories branch February 10, 2022 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants