Skip to content

Commit

Permalink
Alphabetize the Team list for easier selection (#59)
Browse files Browse the repository at this point in the history
* Alphabetize the Team list for easier selection

Problem
-------

If I run `bin/packs` and create a new pack, when I get to the team list
it's in what looks like a random order.

```bash
❯ bin/packs
Hello! What would you like to do? Create a new pack
What should the name of your pack be? packs/whatever
Please select a team owner (Press ↑/↓/←/→ arrow to move, Enter to select and letters to filter)
‣ Team 5
  Apples Team
  Search
  Other Team
```

We do have autocomplete with typing but you can also scroll through by arrow keys.
If you use the latter method, it might be nice to have these in order.

Solution
--------

Sort the list of teams by name before sending to the prompt.

```bash
❯ bin/packs
Hello! What would you like to do? Create a new pack
What should the name of your pack be? packs/whatever
Please select a team owner (Press ↑/↓/←/→ arrow to move, Enter to select and letters to filter)
‣ Apples Team
  Other Team
  Search
  Team 5
```

* bump version to 0.70.0

* bundle install
  • Loading branch information
bunnymatic authored Nov 28, 2022
1 parent 92db6c3 commit a159f17
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
use_packwerk (0.69.0)
use_packwerk (0.70.0)
code_ownership
colorize
packwerk (>= 2.2.1)
Expand Down Expand Up @@ -124,7 +124,7 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-packs (0.0.27)
rubocop-packs (0.0.29)
activesupport
parse_packwerk
rubocop
Expand Down
2 changes: 1 addition & 1 deletion lib/use_packwerk/private/interactive_cli/team_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TeamSelector

sig { params(prompt: TTY::Prompt, question_text: String).returns(CodeTeams::Team) }
def self.single_select(prompt, question_text: 'Please select a team owner')
teams = CodeTeams.all.to_h { |t| [t.name, t] }
teams = CodeTeams.all.sort_by(&:name).to_h { |t| [t.name, t] }
prompt.select(
question_text,
teams,
Expand Down
17 changes: 17 additions & 0 deletions spec/use_packwerk/private/interactive_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module UsePackwerk
Private::InteractiveCli.start!(prompt: prompt)
end

before { CodeTeams.bust_caches! }

it 'allows creating a new pack interactively' do
write_file('config/teams/artists.yml', 'name: Artists')
expect(UsePackwerk).to receive(:create_pack!).with(pack_name: 'packs/my_new_pack', team: CodeTeams.find('Artists'))
Expand All @@ -19,6 +21,21 @@ module UsePackwerk
subject
end

it 'shows teams listed alphabetically and you can pick one with arrow keys' do
write_file('config/teams/zebras.yml', 'name: Zebras')
write_file('config/teams/artists.yml', 'name: Artists')
write_file('config/teams/bbs.yml', 'name: BBs')

expect(UsePackwerk).to receive(:create_pack!).with(pack_name: 'packs/my_new_pack', team: CodeTeams.find('Zebras'))
prompt.input << "Create\r"
prompt.input << "my_new_pack\r"
prompt.input << "\e[B" # down arrow
prompt.input << "\e[B" # down arrow
prompt.input << "\r"
prompt.input.rewind
subject
end

it 'allows adding a dependency interactively' do
write_package_yml('packs/my_dependent_pack')
write_package_yml('packs/my_dependency')
Expand Down
2 changes: 1 addition & 1 deletion use_packwerk.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'use_packwerk'
spec.version = '0.69.0'
spec.version = '0.70.0'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']

Expand Down

0 comments on commit a159f17

Please sign in to comment.