WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@lfu
Copy link
Contributor

@lfu lfu commented Dec 8, 2025

  • Add Export button on the new hosts overview page.
  • Add Manage columns Organization and Location to pagelet for CSV export.

Related to Katello/katello#11591.

To test
Before apply this patch.
Hosts - All Hosts - Legacy UI - Export - save the exported CSV file A
Hosts - All Hosts - Content Hosts - Export - save the exported CSV file B

Apply this patch.
Hosts - All Hosts - Legacy UI - Export
The exported file should be the same as the saved exported CSV file A

Hosts - All Hosts - Export
The columns in the exported file should contain the columns exported from CSV file A + CSV file B

@jeremylenz
Copy link
Contributor

If I click Manage Columns and change my columns, and then export to CSV, does the CSV contain different columns?

Same question for the legacy page and the new UI.

@lfu
Copy link
Contributor Author

lfu commented Dec 8, 2025

Yes. Export for both Legacy and new hosts page would show different contents as you change the managed columns.

Also noticed the export file would contain all the hosts in the page.
In other words, selected hosts is not honored here. And this's the current behavior with export from Legacy UI and content hosts UI.

@lfu lfu force-pushed the 38427_export_hosts branch from a55dae9 to 9e6a0c2 Compare December 9, 2025 01:21
Copy link
Member

@chris1984 chris1984 left a comment

Choose a reason for hiding this comment

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

Nice work Lucy, left a few comments, have not tested yet.

<Button
component="a"
ouiaId="export-hosts-button"
href={foremanUrl(`${hostsIndexUrl}.csv`)}
Copy link
Member

Choose a reason for hiding this comment

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

the export button constructs a static URL. If a user filters the list (e.g., name ~ production), clicking "Export" will download all hosts because the search query is not passed to the controller.

Suggested change
href={foremanUrl(`${hostsIndexUrl}.csv`)}
// Assuming 'search' is available in the component props/hooks
// You might need to import 'useSelector' or standard URI encoding
href={foremanUrl(`${hostsIndexUrl}.csv`, { search: search })}

csv_pagelets.map { |pagelet| pagelet.opts[:export_data] || pagelet.opts[:export_key] || pagelet.opts[:key] }.flatten
end

def csv_headers
Copy link
Member

Choose a reason for hiding this comment

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

Would it be worth it to clean this method up? I asked Gemini and it came back with this:

Suggested change
def csv_headers
def csv_headers
csv_pagelets.map do |pagelet|
export_data = pagelet.opts[:export_data]
# Existing array handling...
if export_data.is_a?(Array)
export_data.map(&:label)
elsif export_data.is_a?(CsvExporter::ExportDefinition)
export_data.label
else
# Simplified fallback
pagelet.opts[:export_label] || pagelet.opts[:label] || (pagelet.opts[:export_key] || pagelet.opts[:key]).to_s.titleize.gsub('.', ' - ')
end
end.flatten
end

add_pagelet :hosts_table_column_content, key: :owner, callback: ->(host) { host_owner_column(host) }, class: common_class
add_pagelet :hosts_table_column_header, key: :hostgroup, label: N_('Host group'), sortable: true, width: '15%', class: common_class
add_pagelet :hosts_table_column_content, key: :hostgroup, callback: ->(host) { label_with_link host.hostgroup, 23, @hostgroup_authorizer }, class: common_class
add_pagelet :hosts_table_column_header, key: :organization, label: N_('Organization'), sortable: true, width: '12%', class: common_class
Copy link
Member

Choose a reason for hiding this comment

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

Can we use export_key like boot time does?

add_pagelet :hosts_table_column_header, key: :organization, label: N_('Organization'), sortable: true, width: '12%', export_key: 'organization.name', class: common_class
# ...
add_pagelet :hosts_table_column_header, key: :location, label: N_('Location'), sortable: true, width: '12%', export_key: 'location.name', class: common_class

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants