sinequa / sba-angular

Sinequa's Angular-based Search Based Application (SBA) Framework
https://sinequa.github.io/sba-angular/
MIT License
30 stars 23 forks source link

(analytics) add table records, loaded after initial results, to the results object #86

Closed Guillaume-Developer closed 1 year ago

Guillaume-Developer commented 2 years ago

This commit fixes an issue where, in the ag-grid, records loaded after the initial results wouldn't be selectable or cannot be added to the collection or any other functionality requiring selection.

ericleib commented 2 years ago

There is an issue with this fix: the datasource might request you for records at an arbitrary page (like, go from page 1 directly to 100), so you cannot just append these new records at the end of searchService.results.records, that would be inconsistent. What is the issue with selection exactly ? Are you using storage = 'id' or storage = 'record' for your selectionOptions? (cf https://github.com/sinequa/sba-angular/blob/c537f46c5c0107efbd30d0a709f6465d6cf866da/projects/components/selection/selection.service.ts#L30)

Guillaume-Developer commented 2 years ago

I see, it makes sense. The issue is that records are not selected when using the select all button. I am using the storage = 'record'.

ericleib commented 2 years ago

The "select all" button is problematic because there is ambiguity about what "all" means: is it the current page of results ? or is it the entire result set (basically any document returned by the WHERE clause). It's hard to do something in between... In the case of AG Grid, this is all the more an issue because the concept of "results page" is hidden. One possibility is to just remove the "Select All" button, and let users select documents manually. If there is a need for selecting all the results set, then maybe go for a custom implementation (instead of tracking documents 1 by 1, track the WHERE clause?).

Guillaume-Developer commented 2 years ago

Removing the "Select All" button is not a possibility for us unfortunately. This is one of the specification that was accepted and we have to have a select all option. Now unfortunately, tracking the WHERE clause would work if my goal was only the download of all documents and we did not care of the visual impact on the interface, but we need to have the documents selected in the grid, which is only possible through the ag-grid, because they are only accessible there.

Now, how about keeping the part of the code I added, but adding a check on the rank of the records before adding them to the results.records object? The rank should give us the position of the records compared to other records, so I think we could use that to order them.

EDIT

I have tried this in my environment and it does work as expected. If you are okay with it, I will push the change so you can have a look. If you want to not include such a change at all, working or not, let me know, I'll scrap my pull request and only keep the code on my personal project.

ericleib commented 2 years ago

That solution makes sense. My concerns are with the potential sides effects:

Anyway, let's keep the PR open, and feel free to update it with your solution. I am sure this problem will come up again, so this discussion will be very helpful. If all the risks are cleared, I'd be happy to merge it.

Guillaume-Developer commented 2 years ago

Regarding the points you brought up:

Alright, I'll keep the change on my side while we try to resolve the points we talked above. If you find anything else that might be shaky with this modification, let me know!

EDIT

I ran some tests and came up with the following conclusions about point 1 and 2.

ericleib commented 2 years ago

About the burst in memory: AG-Grid only creates DOM elements for the rows/columns that are visible on the screen (even if it has 2000 records loaded in memory), so at most a few dozens of rows and columns. But when you switch to a normal result list, Angular just generates as many DOM elements as there are records, so it's very costly. Resetting the records when you leave the AG-Grid view is a good idea!

Guillaume-Developer commented 2 years ago

I see, I understand now why I am not seeing any burst while using the AG-Grid. I was also wondering, rather than forcing this update on everyone using the AG-Grid we could make it optional via an @Input, but this also requires to add a parameter to the constructor of the datasource.ts.

ag-grid-view.component.ts

/** Activates the possibility to select all the records in the AG-Grid using the SelectionService

  • Please monitor performances when setting to true. This option saves the newly loaded records
  • to the results object, so it can become costly in memory usage */ @Input() activateSelectAll: boolean = false; ... makeDatasource() : IDatasource { if(this.results) { return new SqDatasource(this.results, this.query, this.colDefs, this.searchService, this.appService, this.facetService, this.selectionService, this.activateSelectAll); } return {getRows: () => []}; }

datasource.ts

constructor( public results: Results, public query: Query | undefined, public colDefs: ColDef[], public searchService: SearchService, public appService: AppService, public facetService: FacetService, public selectionService: SelectionService, private selectAllActive: boolean = false )

Guillaume-Developer commented 2 years ago

Did you have a chance to take a look at the changes I pushed?

ericleib commented 2 years ago

Hi Guillaume, Sorry for the delay. Your implementation looks fine, but I had some concerns about the user experience, so I am curious to hear your feedback. Did you deploy these changes to users? Are they happy with it and not confused by the behavior of the select all button? One small implementation detail: rather than completely clearing the results in OnDestroy, I would rather truncate the list to the first pageSize, as it's possible to switch results views without triggering a new search.

Guillaume-Developer commented 2 years ago

Hi Eric, The change has not been tested by users yet, this is a functionality developed for a project not yet in production. Though, the functionality has been made optional with my last push, and it is off by default. Oh, you're right indeed, I'll push this fix next week as I am off until Tuesday.

Guillaume-Developer commented 1 year ago

Hi Eric, did you have a chance to get a look at the changes yet?

ericleib commented 1 year ago

Hi Guillaume, Yes, I did and I think your code is fine from a technical point of view. I am just worried about the side-effects we discussed above. If you tell me that you tried it in prod and users are happy, then let's merge this.

Guillaume-Developer commented 1 year ago

When I first pushed the changes for this pull request, everything was done on my master branch, which left me unable to update it since it was always on standby here. I have now created a dedicated branch for the ag-grid changes, and will create a new pull-request once I have sufficient user feedback.