Browse Source

feat(search): hide search provider

Some search providers can be hidden if they send `null` in `getOrder`

Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
tags/v28.0.0rc1
Benjamin Gaussorgues 6 months ago
parent
commit
75e5854458
No account linked to committer's email address
2 changed files with 10 additions and 3 deletions
  1. 6
    1
      lib/private/Search/SearchComposer.php
  2. 4
    2
      lib/public/Search/IProvider.php

+ 6
- 1
lib/private/Search/SearchComposer.php View File

@@ -184,6 +184,10 @@ class SearchComposer {
function (array $providerData) use ($route, $routeParameters) {
$appId = $providerData['appId'];
$provider = $providerData['provider'];
$order = $provider->getOrder($route, $routeParameters);
if ($order === null) {
return;
}
$triggers = [$provider->getId()];
if ($provider instanceof IFilteringProvider) {
$triggers += $provider->getAlternateIds();
@@ -197,7 +201,7 @@ class SearchComposer {
'appId' => $appId,
'name' => $provider->getName(),
'icon' => $this->fetchIcon($appId, $provider->getId()),
'order' => $provider->getOrder($route, $routeParameters),
'order' => $order,
'triggers' => $triggers,
'filters' => $this->getFiltersType($filters, $provider->getId()),
'inAppSearch' => $provider instanceof IInAppSearch,
@@ -205,6 +209,7 @@ class SearchComposer {
},
$this->providers,
);
$providers = array_filter($providers);

// Sort providers by order and strip associative keys
usort($providers, function ($provider1, $provider2) {

+ 4
- 2
lib/public/Search/IProvider.php View File

@@ -68,15 +68,17 @@ interface IProvider {
/**
* Get the search provider order
* The lower the int, the higher it will be sorted (0 will be before 10)
* If null, the search provider will be hidden in the UI and the API not called
*
* @param string $route the route the user is currently at, e.g. files.view.index
* @param array $routeParameters the parameters of the route the user is currently at, e.g. [fileId = 982, dir = "/"]
*
* @return int
* @return int|null
*
* @since 20.0.0
* @since 28.0.0 Can return null
*/
public function getOrder(string $route, array $routeParameters): int;
public function getOrder(string $route, array $routeParameters): ?int;

/**
* Find matching search entries in an app

Loading…
Cancel
Save