frontend icon indicating copy to clipboard operation
frontend copied to clipboard

Enhancement #500 Export bootstrap-table

Open nvcastelli opened this issue 2 years ago • 6 comments

Description

This changes utilizes the bootstrap-table export plugin to pull table data from tables within the Dependency Track application. In places where it's been enabled on a bootstrap table users will be able to select a dropdown to download table data based on the file type they select.

Addressed Issue

This PR is the first step to fulfilling the following enhancement #500. Pending approval this should resolve enhancement #500

Additional Details

We had brought up this enhancement and Steve suggested using the bootstrap-table export plugin. Currently, this change only adds the ability to download on the component table and only in json and txt formats. I am looking into adding the ability to download as an excel but there are more dependancies needed.

For this change to work some new dependencies need to be included:

  • js-xlsx
  • tableexport.jquery.plugin
  • file-saver

I'm happy to add any suggestions.

Checklist

nvcastelli avatar Jun 14 '23 17:06 nvcastelli

Hi @nvcastelli, thanks for the PR!

For this change to work some new dependencies need to be included:

  • js-xlsx
  • tableexport.jquery.plugin
  • file-saver

Could you please add those dependencies to package.json via npm install, so this change can be tested?

nscuro avatar Jul 08 '23 20:07 nscuro

Hey @nscuro, I was able to add those dependancies, please let me know if there's anything else you need from my end.

nvcastelli avatar Jul 12 '23 15:07 nvcastelli

@nvcastelli I just gave this a spin, but it seems like despite usage of exportDataType: 'all', the export still only contains only up to 100 components.

The issue seems to be that, in order to fetch all items, the plugin requests the REST endpoint without pageNumber / pageSize query parameters, e.g.:

http://localhost:8081/api/v1/component/project/f803526f-fe36-4485-ae0b-e7fe463caf18?onlyOutdated=false&onlyDirect=false&searchText=&sortName=name&sortOrder=asc

Whereas in the paginated view it would do:

http://localhost:8081/api/v1/component/project/f803526f-fe36-4485-ae0b-e7fe463caf18?onlyOutdated=false&onlyDirect=false&searchText=&sortName=name&sortOrder=asc&pageSize=25&pageNumber=1

For paginated REST endpoints, DT will fall back to pageNumber=1 and pageSize=100 when not set explicitly:

https://github.com/stevespringett/Alpine/blob/cd6aa7ed05376935ab32bc43819eba0e3a525b7f/alpine-infra/src/main/java/alpine/persistence/Pagination.java#L58-L65

If the intention is to truly fetch all components, we'll need a way to deal with DT's default pagination behavior here.

nscuro avatar Jul 25 '23 16:07 nscuro

Hey @nscuro , thank you for looking into it. My understanding is that the export-table functionality sets the pagesize to the amount of items in the list, then pulls from them that way. But if you're saying it only does that up to a maximum 100 that would be a problem. If we want to keep using these plugins we'd have to look into how DT does the pagination like you mentioned. Another option may be to just grab the data that's returned from the request to fill the table and put it into a file. Not sure if there's a good plugin for this, maybe something we'd have to make from scratch. Let me know your thoughts, and thanks again!

nvcastelli avatar Jul 25 '23 16:07 nvcastelli

My understanding is that the export-table functionality sets the pagesize to the amount of items in the list, then pulls from them that way.

In that case I'd have expected it to set pageNumber=1&pageSize=N for a project with N components, but that was not happening when I tested it.

If we want to keep using these plugins we'd have to look into how DT does the pagination like you mentioned.

Maybe there's a hook or callback we can use to manually populate the request parameters?

Another option may be to just grab the data that's returned from the request to fill the table and put it into a file.

Yeah, at that point it may be easier to do it in the API server altogether. I personally do not have strong feelings about the bootstrap plugins, but I understand Steve would appreciate us making it work somehow using this plugin.

nscuro avatar Jul 25 '23 17:07 nscuro

hi @stevespringett looks like the recommended plugin isn't working as we'd like. there's some discussion around researching other directions to implement this, would you be open to us researching other plugins or getting the data from the backend instead?

leec94 avatar Aug 30 '23 17:08 leec94