Skip to content

Commit 6b5f4f8

Browse files
authored
Fix side panel search filter (#1212)
* fix: schema properties and api call for search from side panel * fix: filter box categories when one type only * fix: testAvailableRelationshipsUrl * fix: testfilterListByType
1 parent 7a633de commit 6b5f4f8

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

resources/js/app/components/filter-box.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ export default {
261261
this.availableFilters = this.filterList;
262262
} else if (this.rightTypes.length == 1 && this.filtersByType) {
263263
this.availableFilters = this.filtersByType[this.rightTypes[0]];
264+
this.queryFilter.filter.type = this.rightTypes[0];
264265
} else {
265266
this.availableFilters = this.filtersByType?.[this.queryFilter.filter.type] || [];
266267
}
@@ -383,6 +384,10 @@ export default {
383384
this.folder = null;
384385
this.selectedSearchType = 'q';
385386
this.queryFilter = this.getCleanQuery();
387+
if (this.rightTypes.length == 1 && this.filtersByType) {
388+
this.availableFilters = this.filtersByType[this.rightTypes[0]];
389+
this.queryFilter.filter.type = this.rightTypes[0];
390+
}
386391
this.$emit('filter-reset');
387392
},
388393

src/Controller/ModulesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public function resources($id, string $type): void
481481
}
482482

483483
/**
484-
* Relation data load callig api `GET /:object_type/:id/relationships/:relation`
484+
* Relation data load calling api `GET /:object_type/:id/relationships/:relation`
485485
* Json response
486486
*
487487
* @param string|int $id The object ID.
@@ -532,7 +532,7 @@ protected function availableRelationshipsUrl(string $relation): string
532532
$relationsSchema = $this->Schema->getRelationsSchema();
533533
$types = $this->Modules->relatedTypes($relationsSchema, $relation);
534534

535-
return '/objects?filter[type][]=' . implode('&filter[type][]=', $types);
535+
return count($types) === 1 ? sprintf('/%s', $types[0]) : '/objects?filter[type][]=' . implode('&filter[type][]=', $types);
536536
}
537537

538538
/**

src/View/Helper/SchemaHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ public function filterListByType(array $filtersByType, ?array $schemasByType): a
368368
foreach ($filtersByType as $type => $filters) {
369369
$noSchema = empty($schemasByType) || !array_key_exists($type, $schemasByType);
370370
$schemaProperties = $noSchema ? null : Hash::get($schemasByType, $type);
371+
$schemaProperties = array_key_exists('properties', (array)$schemaProperties) ? $schemaProperties['properties'] : $schemaProperties;
371372
$schemaProperties = $schemaProperties !== false ? $schemaProperties : null;
372373
$list[$type] = self::filterList($filters, $schemaProperties);
373374
}

tests/TestCase/Controller/ModulesControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ public function testAvailableRelationshipsUrl(): void
10211021
->willReturn(['documents']);
10221022

10231023
$url = $this->controller->availableRelationshipsUrl('test_relation');
1024-
static::assertEquals('/objects?filter[type][]=documents', $url);
1024+
static::assertEquals('/documents', $url);
10251025

10261026
$this->controller->Modules = $this->createMock(ModulesComponent::class);
10271027
$this->controller->Modules->method('relatedTypes')

0 commit comments

Comments
 (0)