statamic-rad-pack / runway

Eloquently manage your database models in Statamic.
https://statamic.com/addons/rad-pack/runway
MIT License
113 stars 49 forks source link

Missing "hidden" columns in listableColumns #392

Closed caseydwyer closed 10 months ago

caseydwyer commented 10 months ago

Description

Currently, if you mark a field as hidden, the second qualifier in the listableColumns method of Resource.php (noted below) causes it to be rejected. That is, it does not show up in the "column picker" of the control panel's index view:

/**
 * Returns an array of column handles that are marked as listable.
 */
public function listableColumns(): array
{
  return $this->blueprint()->fields()->items()
    ->reject(function ($field) {
      return isset($field['import'])
        // ❌ Remove this next line, to avoid rejecting hidden fields:
        || (isset($field['field']['listable']) && $field['field']['listable'] === 'hidden') 
        || (isset($field['field']['listable']) && $field['field']['listable'] === false);
      })
    ->pluck('handle')
    ->toArray();
}

PR in 2 minutes. πŸ™‚

Steps to reproduce

  1. Create a model & blueprint with any field type.
  2. Set listable: hidden on the field
  3. Open the index page for the resource
  4. Confirm missing/unavailable column in Customize Columns multi-picker

Environment

Environment Application Name: TF Laravel Version: 10.39.0 PHP Version: 8.2.5 Composer Version: 2.5.4 Environment: local Debug Mode: ENABLED URL: tf.test Maintenance Mode: OFF Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED Drivers Broadcasting: log Cache: statamic Database: mysql Logs: stack / single Mail: smtp Queue: sync Session: file Livewire Livewire: v3.3.5 Statamic Addons: 6 Antlers: runtime Stache Watcher: Enabled Static Caching: Disabled Version: 4.42.1 PRO Statamic Addons doublethreedigital/runway: 5.6.0 ... Statamic Eloquent Driver Asset Containers: file Assets: file Blueprints: file Collection Trees: file Collections: file Entries: eloquent Forms: file Global Sets: file Global Variables: file Navigation Trees: file Navigations: file Revisions: eloquent Taxonomies: file Terms: file
duncanmcclean commented 10 months ago

It's late here so I may be misunderstanding but if you set listable:hidden on a field in a collection blueprint, does it show up in the "column picker"?

If it doesn't, then why would it be different here?

caseydwyer commented 10 months ago

Yeah, sorryβ€”I did a lousy job of explaining that. Also should have just shown the entire function call; that line is within a rejects closure, so it's kind of like a double-negative. Updating the original codeblock with that context. πŸ‘ The way it's written (if I understand it correctly) says "reject the field if any of the following do apply:"

That second one is where the problem lies; it excludes any hidden fields from being listable. So prior to this PR, those fields don't show up in the column picker, under Available Columnsβ€”they're just missing altogether. After this PR, they're now made available (but not selected by default).

duncanmcclean commented 10 months ago

Yeah, I was misunderstanding, thanks!

github-actions[bot] commented 10 months ago

Released as part of v5.6.1.