Skip to content

Commit 2d68dd8

Browse files
committed
Deal with form schema inside filters when present
1 parent 4c43f4d commit 2d68dd8

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

src/DescribeFilamentResourceTool.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ public function makeFilamentTranslatableContentDriver(): ?TranslatableContentDri
161161
'name' => $column['name'],
162162
'label' => $column['label'],
163163
'type' => 'searchable_column',
164+
'example' => [
165+
'description' => 'Use string value to search within this column',
166+
'values' => ['search term', 'partial match']
167+
]
164168
])
165169
->keyBy('name')
166170
->all();
@@ -284,16 +288,43 @@ public function mapTableFilter(BaseFilter $filter): array
284288
];
285289

286290
if ($filter instanceof TernaryFilter) {
287-
// Condition is implicit (true/false/all)
291+
$baseInfo['example'] = [
292+
'description' => 'Use true for yes, false for no, null for all',
293+
'values' => [true, false, null],
294+
'usage' => "Include as '{$filter->getName()}': true|false|null in your filters JSON"
295+
];
288296
} elseif ($filter instanceof SelectFilter) {
289-
$baseInfo['optionsSource'] = 'Dynamic/Callable'; // Getting exact source is complex
297+
$baseInfo['optionsSource'] = 'Dynamic/Callable';
290298

291-
// Try to get options if they are simple array
292299
if (method_exists($filter, 'getOptions') && is_array($options = $filter->getOptions())) {
293300
$baseInfo['optionsSource'] = $options;
301+
$exampleSingle = array_key_first($options);
302+
$exampleMultiple = array_slice(array_keys($options), 0, 2);
303+
304+
$baseInfo['example'] = [
305+
'description' => 'Use array of option keys or single option key',
306+
'values' => [
307+
'single' => $exampleSingle,
308+
'multiple' => $exampleMultiple
309+
],
310+
'usage' => "Include as '{$filter->getName()}': [" . implode(', ', array_map(fn($v) => "\"$v\"", $exampleMultiple)) . "] or '{$filter->getName()}': \"$exampleSingle\" in your filters JSON"
311+
];
312+
} else {
313+
$baseInfo['example'] = [
314+
'description' => 'Use array of option values or single option value',
315+
'values' => [
316+
'single' => 'option_value',
317+
'multiple' => ['option_value_1', 'option_value_2']
318+
],
319+
'usage' => "Include as '{$filter->getName()}': [\"option_value_1\", \"option_value_2\"] or '{$filter->getName()}': \"option_value\" in your filters JSON"
320+
];
294321
}
322+
} else {
323+
$baseInfo['example'] = [
324+
'description' => 'Custom filter - check filter implementation for expected values',
325+
'usage' => "Include as '{$filter->getName()}': value in your filters JSON"
326+
];
295327
}
296-
// Add more specific filter type mappings here if needed
297328

298329
return $baseInfo;
299330
}

src/GetFilamentResourceDataTool.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function build(): PrismTool
2222
{
2323
return app(PrismTool::class)
2424
->as($this->getName())
25-
->for('Gets the data for a given Filament resource, applying optional filters provided in the describe_filament_resource tool. Always call the describe_filament_resource tool before calling this tool. Try to use the available filters to get the data you need.')
25+
->for('Gets the data for a given Filament resource, applying optional filters (try to use them). Always call the describe_filament_resource tool before calling this tool. Always try to use the available filters to get the data you need.')
2626
->withStringParameter('resource', 'The resource class name of the resource to get data for, from the list_filament_resources tool.', required: true)
2727
->withStringParameter('filters', 'JSON string of filters to apply (e.g., \'{"status": "published", "author_id": [1, 2]}\').', required: false)
2828
->using(function (string $resource, ?string $filters = null) {
@@ -55,9 +55,18 @@ public function build(): PrismTool
5555
$listPage->tableFilters[$filter->getName()] = [
5656
'value' => $filters[$filter->getName()] ?? null,
5757
];
58+
59+
if ($filter->hasFormSchema()) {
60+
foreach ($filter->getFormSchema() as $formSchema) {
61+
$listPage->tableFilters[$filter->getName()][$formSchema->getName()] =
62+
$filters[$formSchema->getName()] ?? null;
63+
}
64+
}
5865
}
5966
}
6067

68+
dump($listPage->tableFilters, $filters);
69+
6170
// TODO: Allow the tool to specify the number of results to return with a max
6271
$results = $listPage->getFilteredTableQuery()->take(10)->get();
6372

0 commit comments

Comments
 (0)