diff --git a/resources/js/app/components/filter-box.vue b/resources/js/app/components/filter-box.vue index 45d8a5184..f113215f5 100644 --- a/resources/js/app/components/filter-box.vue +++ b/resources/js/app/components/filter-box.vue @@ -261,6 +261,7 @@ export default { this.availableFilters = this.filterList; } else if (this.rightTypes.length == 1 && this.filtersByType) { this.availableFilters = this.filtersByType[this.rightTypes[0]]; + this.queryFilter.filter.type = this.rightTypes[0]; } else { this.availableFilters = this.filtersByType?.[this.queryFilter.filter.type] || []; } @@ -383,6 +384,10 @@ export default { this.folder = null; this.selectedSearchType = 'q'; this.queryFilter = this.getCleanQuery(); + if (this.rightTypes.length == 1 && this.filtersByType) { + this.availableFilters = this.filtersByType[this.rightTypes[0]]; + this.queryFilter.filter.type = this.rightTypes[0]; + } this.$emit('filter-reset'); }, diff --git a/src/Controller/ModulesController.php b/src/Controller/ModulesController.php index 1555fc077..ae95628bc 100644 --- a/src/Controller/ModulesController.php +++ b/src/Controller/ModulesController.php @@ -481,7 +481,7 @@ public function resources($id, string $type): void } /** - * Relation data load callig api `GET /:object_type/:id/relationships/:relation` + * Relation data load calling api `GET /:object_type/:id/relationships/:relation` * Json response * * @param string|int $id The object ID. @@ -532,7 +532,7 @@ protected function availableRelationshipsUrl(string $relation): string $relationsSchema = $this->Schema->getRelationsSchema(); $types = $this->Modules->relatedTypes($relationsSchema, $relation); - return '/objects?filter[type][]=' . implode('&filter[type][]=', $types); + return count($types) === 1 ? sprintf('/%s', $types[0]) : '/objects?filter[type][]=' . implode('&filter[type][]=', $types); } /** diff --git a/src/View/Helper/SchemaHelper.php b/src/View/Helper/SchemaHelper.php index a7a6a886d..7f2efdac6 100644 --- a/src/View/Helper/SchemaHelper.php +++ b/src/View/Helper/SchemaHelper.php @@ -368,6 +368,7 @@ public function filterListByType(array $filtersByType, ?array $schemasByType): a foreach ($filtersByType as $type => $filters) { $noSchema = empty($schemasByType) || !array_key_exists($type, $schemasByType); $schemaProperties = $noSchema ? null : Hash::get($schemasByType, $type); + $schemaProperties = array_key_exists('properties', (array)$schemaProperties) ? $schemaProperties['properties'] : $schemaProperties; $schemaProperties = $schemaProperties !== false ? $schemaProperties : null; $list[$type] = self::filterList($filters, $schemaProperties); } diff --git a/tests/TestCase/Controller/ModulesControllerTest.php b/tests/TestCase/Controller/ModulesControllerTest.php index b32a20970..a7050d7ab 100644 --- a/tests/TestCase/Controller/ModulesControllerTest.php +++ b/tests/TestCase/Controller/ModulesControllerTest.php @@ -1021,7 +1021,7 @@ public function testAvailableRelationshipsUrl(): void ->willReturn(['documents']); $url = $this->controller->availableRelationshipsUrl('test_relation'); - static::assertEquals('/objects?filter[type][]=documents', $url); + static::assertEquals('/documents', $url); $this->controller->Modules = $this->createMock(ModulesComponent::class); $this->controller->Modules->method('relatedTypes')