Skip to content

Commit

Permalink
Add dependency type support
Browse files Browse the repository at this point in the history
  • Loading branch information
PhiloNL committed Apr 23, 2021
1 parent 5083553 commit 2c2be07
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 35 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `spotlight` will be documented in this file.

## 0.1.6
- Add `SpotlightCommandDependency` type support. Defaults to `SpotlightCommandDependency::SEARCH`
- *Important* The dependency order was incorrect, you need to change your dependency order after updating if you have more than one dependency.


## 0.1.5
- Add option to toggle Spotlight via browser events. `$this->dispatchBrowserEvent('toggle-spotlight');`

Expand Down
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ follows the order in which you add the commands.
```php
SpotlightCommandDependencies::collection()
->add(SpotlightCommandDependency::make('team')->setPlaceholder('For which team do you want to create a user?'))
->add(SpotlightCommandDependency::make('foobar')->setPlaceholder('Some other dependency here?'));
->add(SpotlightCommandDependency::make('foobar')->setPlaceholder('Input from user')->setType(SpotlightCommandDependency::INPUT));
```

For every dependency, Spotlight will check if a `search{dependency-name}` method exists on the command. This method
Expand Down Expand Up @@ -169,7 +169,7 @@ class CreateUser extends SpotlightCommand
{
return SpotlightCommandDependencies::collection()
->add(SpotlightCommandDependency::make('team')->setPlaceholder('For which team do you want to create a user?'))
->add(SpotlightCommandDependency::make('foobar')->setPlaceholder('Some other dependency here?'));
->add(SpotlightCommandDependency::make('name')->setPlaceholder('How do you want to name this user?')->setType(SpotlightCommandDependency::INPUT));
}

public function searchTeam($query)
Expand All @@ -185,22 +185,10 @@ class CreateUser extends SpotlightCommand
});
}

public function searchFoobar(Team $team, $query)
{
return $team->foobar()->where('name', 'like', "%$query%")
->get()
->map(function(Foobar $foobar) {
return new SpotlightSearchResult(
$foobar->id,
$foobar->name,
sprintf('Create something for %s', $foobar->name)
);
});
}

public function execute(Spotlight $spotlight, Team $team)
public function execute(Spotlight $spotlight, Team $team, string $name)
{
$spotlight->emit('openModal', 'user-create', ['team' => $team->id]);
$spotlight->emit('openModal', 'user-create', ['team' => $team->id, 'name' => $name]);
}

}
Expand Down
2 changes: 1 addition & 1 deletion public/spotlight.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2c2be07

Please sign in to comment.