Skip to content

Commit

Permalink
[PLAY-1391] Add Category to Playbook kit generator (#3488)
Browse files Browse the repository at this point in the history
**What does this PR do?** A clear and concise description with your
runway ticket url.
[PLAY-1391](https://runway.powerhrg.com/backlog_items/PLAY-1391) adds
the capability to use a category flag when creating a new kit with the
Playbook kit generator that allows for the newly generated kit to be
sorted into one of the preexisting categories (aka submenus with in
Components on the sidebar). This feature does not allow for the
generation of new categories via this generator (creating new categories
is a rare occurrence and should be done manually) and it is optional
(when a kit is generated with a category flag, it will function like it
is currently and just be appended to the bottom of the `menu.yml`).

This ticket is a follow up following an initial investigation done
during [PLAY-1330](https://runway.powerhrg.com/backlog_items/PLAY-1330)
which fixed the Fix generator and updated its documentation. New
information about the Category prop will be added to the [Generating a
Kit huddle
doc](https://huddle.powerapp.cloud/v2/projects/419/artifacts/6279) once
this is approved (the
[draft](https://gist.github.com/ElisaShapiro/922d47e7518971e49ff1014e5c1fcc36)
is here with doc changes pending approval).

**Screenshots:** Screenshots to visualize your addition/change
Example Uno: adding a new kit with a typo in the category, then
successfully doing so once fixed
<img width="800" alt="uno code"
src="https://github.com/powerhome/playbook/assets/83474365/54ec61f8-2ef1-4cdc-ab61-316648f7febf"><img
width="400" alt="uno page"
src="https://github.com/powerhome/playbook/assets/83474365/5d294f89-6c4a-43f1-9d35-ed8a713bff85">

Example dos: adding a new kit with a category and a kit type
<img width="800" alt="dos code"
src="https://github.com/powerhome/playbook/assets/83474365/d6edc961-5c9a-4d84-9222-6c1752720f40"><img
width="400" alt="dos page"
src="https://github.com/powerhome/playbook/assets/83474365/9235c2a6-c29d-4dcb-9e69-dfc3c062ef9b">


Example tres: adding a new kit without a category specified
<img width="800" alt="tres code"
src="https://github.com/powerhome/playbook/assets/83474365/14eea25c-bb5d-4b2c-8b8e-c19d715e3aea"><img
width="400" alt="tres page"
src="https://github.com/powerhome/playbook/assets/83474365/7de0cd4d-2f81-48da-832e-5ab1556095ef">

Example quatro: adding a new kit with kit type, props, and category
specified
<img width="800" alt="quatro code"
src="https://github.com/powerhome/playbook/assets/83474365/f2a5773a-cb78-4b76-8817-19f79c3e617e"><img
width="400" alt="quatro page"
src="https://github.com/powerhome/playbook/assets/83474365/6a66a10c-8d85-4d99-b8a9-cb2a45777145">


**How to test?** Steps to confirm the desired behavior:
1. Pull down this branch.
2. Reference the generating a kit documentation to try to add a kit with
a category (see draft linked above if huddle doc not yet updated).
3. New kit should be added to `menu.yml` file and visible on the PB
website locally when you start the server and check localhost.
4. Try to add a kit omitting a category (and see it append to the bottom
of `menu.yml` like it did previously; try to mess up the category name
(with a typo or a category that doesn't exist) and see the generator
stall out.

ALTERNATIVE:
Reference demo video in Runway ticket.


#### Checklist:
- [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new
kit`, `deprecated`, or `breaking`. See [Changelog &
Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels)
for details.
- [x] **DEPLOY** I have added the `milano` label to show I'm ready for a
review.
~~- [ ] **TESTS** I have added test coverage to my code.~~
  • Loading branch information
ElisaShapiro committed Jul 5, 2024
1 parent 19734b1 commit 6168cf5
Show file tree
Hide file tree
Showing 5 changed files with 634 additions and 493 deletions.
8 changes: 4 additions & 4 deletions playbook-website/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def aggregate_kits
end

def categories
aggregate_kits.map { |item| item["name"] }
aggregate_kits.map { |item| item["category"] }
end

def all_kits
Expand All @@ -229,7 +229,7 @@ def set_js
end

def set_category
@category = params[:name]
@category = params[:category]
if categories.include?(@category) && helpers.category_has_kits?(category_kits: kit_categories, type: params[:type])
@category_kits = kit_categories
@kits = params[:name]
Expand All @@ -239,8 +239,8 @@ def set_category
end

def kit_categories
@category = params[:name]
aggregate_kits.find { |item| item["name"] == @category }["components"].map { |component| component["name"] }
@category = params[:category]
aggregate_kits.find { |item| item["category"] == @category }["components"].map { |component| component["name"] }
end

def set_kit
Expand Down
6 changes: 3 additions & 3 deletions playbook-website/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ def aggregate_kits_with_status
all_kits = []

MENU["kits"].each do |kit|
kit_name = kit["name"]
kit_category = kit["category"]
# Modify this line to include both name and status in the components array
components = kit["components"].map { |c| { name: c["name"], status: c["status"] } }

all_kits << { kit_name => components }
all_kits << { kit_category => components }
end

all_kits
Expand All @@ -166,7 +166,7 @@ def search_list

aggregate_kits_with_status.each do |kit|
if kit.is_a? Hash
_kit_name, components = kit.first
_kit_category, components = kit.first
components.each do |component|
all_kits.push(component[:name]) if component[:status] != "beta"
end
Expand Down
Loading

0 comments on commit 6168cf5

Please sign in to comment.