Skip to content

Conversation

@sermakov-orion
Copy link
Contributor

@sermakov-orion sermakov-orion commented Dec 5, 2023

"Export to CSV" functionality for main tables in oVirt Administration Portal
Signed-off-by: Stepan Ermakov [email protected]

Changes introduced with this PR

This feature adds new menu item "Export to CSV" for the following tables of oVirt Administration Portal:

Compute

  • Virtual Machines
  • Templates
  • Pools
  • Hosts
  • Data Centers

Network

  • Networks

Storage

  • Domains
  • Volumes
  • Disks

Events

The menu item allows to export current content (taking in to account current localization, columns visibility, sort order, filter) of the selected table into CSV. And initiates automatic download of the created CSV file.
Known limitation: not more than 10,000 rows can be exported.
image
vms.2023-12-05.09-07.csv

Are you the owner of the code you are sending in, or do you have permission of the owner?

y

@sandrobonazzola
Copy link
Member

@dupondje @BrooklynDewolf can you please review?

… Portal

Signed-off-by: Stepan Ermakov <[email protected]>

This feature adds new menu item "Export to CSV" for the following tables of oVirt Administration Portal
Compute
* Virtual Machines
* Templates
* Pools
* Hosts
* Data Centers
Network
* Networks
Storage
* Domains
* Volumes
* Disks
Events

The menu item allows to export current content (taking in to account current localization, columns visibility, sort order, filter) of the selected table into CSV. And initiates automatic download of the created CSV file.
Known limitation: not more than 10,000 can be exported.
Copy link
Contributor

@JasperB-TeamBlue JasperB-TeamBlue left a comment

Choose a reason for hiding this comment

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

Thanks for your commitment but there are some remarks about your PR:

  • What is the decision process behind which tables are valid to export and which aren't?
  • Exporting an empty CSV when there is nothing present seems wrong, it would be better if the button is disabled when there is nothing present
  • Best practice would be to push the CSV generatiion code more to the backend, now it resides in the frontend, a place where it shouldn't be. An added benefit of moving this would be that an api call could be implemented that would have the same functionality as your current UI button.

Comment on lines +252 to +257
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
document.body.appendChild(pom);
pom.click();
document.body.removeChild(pom); }-*/;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a commented out function so it does not actually do anything at the moment, please refactor this.

Comment on lines +101 to +103
// Note that in order to export content of the table we need to scroll to the first page, then export the content
// by moving forward page by page till the end (or till the 10000 rows limit is reached). And then return to the
// page where the export functionality was initiated.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do I understand this correctly that you are reading out the data that you want to push to the csv from what is presented in the UI? Would it not be better practice to trigger an appropriate database call that could provide the needed data instead?

* Table row data type.
**/
public class TableCsvExporter<T> {
private static final int LINES_LIMIT = 10000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of hard coding variable in here would it not be better to save this in the database and link it to the ConfigValues, an example of this:

int timeout = Config.<Integer> getValue(ConfigValues.SetupNetworksWaitTimeoutSeconds)


@Override
public String csvExportFilenameBase() {
return "events"; //$NON-NLS-1$
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there be a localized string used here? This way we ensure that the file name is in a language the end user actually understands, and if the language does not exist it can default to the english string.

private static final String DOUBLE_QUOTE_STR = "\""; //$NON-NLS-1$
private static final String DOUBLE_DOUBLE_QUOTE_STR = "\"\""; //$NON-NLS-1$
private static final String FILE_EXT = ".csv"; //$NON-NLS-1$
private static final String FILE_CURRENT_DATE_AND_TIME_FORMAT = "yyyy-MM-dd.HH-mm"; //$NON-NLS-1$
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed, there is a whole class dedicated to rendering time called FullDateTimeRenderer and you also have functions like DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM);

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants