Skip to content

Feature/column chooser#1333

Open
BastianLedererIcinga wants to merge 28 commits intomainfrom
feature/column-chooser
Open

Feature/column chooser#1333
BastianLedererIcinga wants to merge 28 commits intomainfrom
feature/column-chooser

Conversation

@BastianLedererIcinga
Copy link
Copy Markdown
Contributor

@BastianLedererIcinga BastianLedererIcinga commented Feb 13, 2026

Add a new form to choose the displayed columns in hosts and services view.

resolves: #82
fixes #850

requires: Icinga/ipl-web#277 for the TabularViewModeSwitcher icon
requires: Icinga/ipl-web#357 to display error messages for invalid columns

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Feb 13, 2026
@BastianLedererIcinga BastianLedererIcinga force-pushed the feature/column-chooser branch 4 times, most recently from 8453195 to 3c998e0 Compare February 26, 2026 14:49
Add a new form that supports adding and removing dispalyed columns
in tabular viewmode.
Add TabularViewModeSwitcher as a subclass of ViewModeSwitcher
and remove tabular view as option of the ViewModeSwitcher.
Adjust HostsController and ServicesController to use the new
ColumnChooser form and the TabularViewModeSwitcher.
The Controller class is adjusted to work with the TabularViewModeSwitcher
The HostGroupsController and ServiceGroupsController are adjusted,
to ensure they use with the GridViewModeSwitcher.
Add a button to the StateItemTable to open the ColumnChooser form.
Exclude regular columns by using fixed columns
and expand Objectsuggestions to exclude a given set of
customvars.
…lass`

Use the parameter to customize the type of ViewModeSwitcher used
Add a parameter for default columns to be used if no columns
are set in the URL
Use `SearchSuggestions` in `HostsController` and `ServicesController`
Use the setter to set the url for the ColumnChooser
@nilmerg nilmerg marked this pull request as ready for review March 19, 2026 09:58
Copy link
Copy Markdown
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why you're not satisfied with the usage of SearchSuggestions. To get to a desirable result, a larger change is required. ObjectSuggestions were never designed to be more than a provider for the SearchBar. Now you're borrowing a part of its implementation either by making a protected method public or by copying parts of the code and reduce them to what you need.

I'd suggest to put the logic to retrieve custom variables and model columns for suggestions in a dedicated location that can be used by ObjectSuggestions and SearchSuggestions equally.

namespace Icinga\Module\Icingadb\Data;

/** Not necessarily complete, but I hope you get the idea */
class QueryColumnsProvider implements IteratorAggregate
{
    public function __construct(Query $query, string $searchTerm);
    
    public function setFixedColumns(array $columns);

    public function setCustomVarSources(array $sources);

    /** Basically a copy from `ObjectSuggestions` but without the need for a base implementation */
    protected function matchSuggestion($path, $label, $searchTerm);

    public function getIterator(): Generator;

    /** public because `ObjectSuggestions::fetchValueSuggestions()` need it as well */
    public static function collectFilterColumns(): Generator;
}

This should serve functionality currently only implemented in ObjectSuggestions to retrieve columns and custom variable names. It should be mostly a drop-in replacement for what ObjectSuggestions::fetchColumnSuggestions() currently does. Though, there is one thing it cannot provide:

addHtml – It's not a html element nor a container. The reason this is required comes from what the SearchSuggestions define as grouping. Though, in case of the column chooser this is required as well I think. QueryColumnsProvider should group by default. i.e. It yields in two levels, first a string key and a generator as value. SearchSuggestions should be able to handle this right now already, ObjectSuggestions need to be adjusted for this.

I hope this is sufficient to get you on track again.

@BastianLedererIcinga
Copy link
Copy Markdown
Contributor Author

addHtml – It's not a html element nor a container. The reason this is required comes from what the SearchSuggestions define as grouping. Though, in case of the column chooser this is required as well I think. QueryColumnsProvider should group by default. i.e. It yields in two levels, first a string key and a generator as value. SearchSuggestions should be able to handle this right now already, ObjectSuggestions need to be adjusted for this.

From my understanding SearchSuggestions can't handle grouping the way you suggested.
When no groupingCallback is set the output is not grouped at all, when it is set yield_groups() is used to create the groups, which expects a flat Traversable.

I added a group key to the values yielded by QueryColumnsProvider instead.

Copy link
Copy Markdown
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look in detail at QueryColumnsProvider and ObjectSuggestions yet.

Use a `where` to filter out custom vars that should be excluded
Comment on lines +215 to +216
'host' => t('Host %s', '..<customvar-name>'),
'service' => t('Service %s', '..<customvar-name>')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce indentation please

Comment on lines +232 to +233
'host' => t('Host %s', '..<customvar-name>'),
'service' => t('Service %s', '..<customvar-name>')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce indentation please

yield [
'search' => $relation . '.vars.' . $search,
'label' => sprintf($label, $name),
'group' => t('Best Suggestions')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ipl-i18n's Translation trait instead of the global functions.

if (isset($excludedByRelation[$name])) {
$flatname = $resolver->qualifyColumn('flatname', $resolver->getAlias($customVars->getModel()));
$select->where(
"$flatname Not In (?)",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOT IN please

) {
yield [
'search' => $columnName,
'label' => $columnMeta,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that a feature of ObjectSuggestions is missing here: Relation names. (Controlled by shouldShowRelationFor)

We have several duplicate column labels such as Endpoint Name that need further distinction in the suggestions. The search bar's Suggestions have this builtin, the SearchSuggestions on the other hand do not. But as said, they should be dumb, what I'd suggest is to teach them only about that labels might be ipl\Html\Contract\ValidHtml and in that case, they don't render an <input type="button"> but a <button type="button"></button> (That's what Suggestions already do but always.)

So please add support for this, I will create an issue for ip-web, and replicate here the markup the Suggestions use to show relations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List views with tabular view mode and empty columns are broken Column chooser

2 participants