@@ -161,10 +161,6 @@ 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- ],
168164 ])
169165 ->keyBy ('name ' )
170166 ->all ();
@@ -221,22 +217,20 @@ public function mapFilterType(BaseFilter $filter): string
221217 };
222218 }
223219
224- public function mapFormComponent (Component $ component , Resource $ resource ): ?array
220+ public function mapFormComponent (Component $ component , ? Resource $ resource = null ): ?array
225221 {
226222 $ baseInfo = [
227223 'name ' => $ component ->getName (),
228224 'type ' => $ this ->mapComponentType ($ component ),
229225 'label ' => $ component ->getLabel (),
230226 'required ' => method_exists ($ component , 'isRequired ' ) ? $ component ->isRequired () : null ,
231- 'disabled ' => method_exists ($ component , 'isDisabled ' ) ? $ component ->isDisabled () : null ,
232- // 'nullable' => method_exists($component, 'isNullable') ? $component->isNullable() : null, // Needs checking validation rules
233227 ];
234228
235229 if ($ component instanceof TextInput) {
236230 $ baseInfo ['maxLength ' ] = $ component ->getMaxLength ();
237231 }
238232
239- if ($ component instanceof Select && $ component ->getRelationshipName ()) {
233+ if ($ resource && $ component instanceof Select && $ component ->getRelationshipName ()) {
240234 $ modelClass = $ resource ::getModel ();
241235 $ modelInstance = app ($ modelClass );
242236 $ relationshipDefinition = $ modelInstance ->{$ component ->getRelationshipName ()}();
@@ -245,25 +239,21 @@ public function mapFormComponent(Component $component, Resource $resource): ?arr
245239 'type ' => class_basename ($ relationshipDefinition ), // e.g., BelongsTo
246240 'model ' => get_class ($ relationshipDefinition ->getRelated ()),
247241 'displayColumn ' => $ component ->getRelationshipTitleAttribute (),
248- 'foreignKey ' => $ relationshipDefinition ->getForeignKeyName (), // Might need adjustment based on relationship type
242+ 'foreignKey ' => $ relationshipDefinition ->getForeignKeyName (),
249243 ];
250244 }
251245
252- // Add more specific component type mappings here if needed
253-
254246 return $ baseInfo ;
255247 }
256248
257249 public function mapTableAction (Action |BulkAction $ action ): string
258250 {
259- // Map common actions to simple strings, fallback to action name
260251 $ name = $ action ->getName ();
261252
262253 return match ($ name ) {
263254 'view ' , 'edit ' , 'delete ' , 'forceDelete ' , 'restore ' , 'replicate ' => $ name ,
264- default => $ name , // Return the action name itself
255+ default => $ name ,
265256 };
266- // Could potentially add more details like label, icon, color if needed
267257 }
268258
269259 public function mapTableColumn (Column $ column ): array
@@ -287,44 +277,25 @@ public function mapTableFilter(BaseFilter $filter): array
287277 'type ' => $ this ->mapFilterType ($ filter ),
288278 ];
289279
280+ if ($ filter ->hasFormSchema ()) {
281+ $ baseInfo ['usage ' ] = 'Please use the form schema to filter the data. ' ;
282+ $ baseInfo ['type ' ] = 'form ' ;
283+ $ baseInfo ['form ' ] = collect ($ filter ->getFormSchema ())
284+ ->map (fn (Component $ component ) => $ this ->mapFormComponent ($ component ))
285+ ->all ();
286+ }
287+
290288 if ($ filter instanceof TernaryFilter) {
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- ];
289+ // Condition is implicit (true/false/all)
296290 } elseif ($ filter instanceof SelectFilter) {
297- $ baseInfo ['optionsSource ' ] = 'Dynamic/Callable ' ;
291+ $ baseInfo ['optionsSource ' ] = 'Dynamic/Callable ' ; // Getting exact source is complex
298292
293+ // Try to get options if they are simple array
299294 if (method_exists ($ filter , 'getOptions ' ) && is_array ($ options = $ filter ->getOptions ())) {
300295 $ 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- ];
321296 }
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- ];
327297 }
298+ // Add more specific filter type mappings here if needed
328299
329300 return $ baseInfo ;
330301 }
0 commit comments