-
Notifications
You must be signed in to change notification settings - Fork 1k
Fixes #38941 - Implement CSV exports on the hosts overview #10793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
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. |
|
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. |
a55dae9 to
9e6a0c2
Compare
chris1984
left a comment
There was a problem hiding this 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`)} |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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:
| 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 |
There was a problem hiding this comment.
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
Exportbutton on the new hosts overview page.OrganizationandLocationto 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