Skip to content

Commit

Permalink
fix(document): import with many identifiers
Browse files Browse the repository at this point in the history
If the size of the query exceeds 1024 characters, we truncate
the identifiers and display a warning message to the user.

* Closes rero/rero-ils#3118.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Apr 10, 2024
1 parent 92eb92e commit b2b4ae9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ <h5 translate>Documents are available</h5>
</li>
}
</ul>
@if (warningMessages.length > 0) {
<div class="mt-3 row">
<div class="col-1">
<i class="fa fa-exclamation-circle fa-2x text-danger" aria-hidden="true"></i>
</div>
<div class="col-11">
@for (message of warningMessages; track message) {
<p class="mb-2 font-weight-bold">{{ message }}</p>
}
</div>
</div>
}
<div class="font-weight-bold mt-3" translate>Do you want to import this document?</div>
</div>
<div class="modal-footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class DialogImportComponent {
/** Available record */
records: any[];

/** Message */
warningMessages: string[] = [];

/** Observable for action */
confirmation$: Subject<boolean> = new Subject<boolean>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ export class DocumentDetailComponent extends DetailComponent {
this.router.navigate(route, { queryParams: data });
} else {
// Find documents(s) with query params
const query = queryParams.join(' OR ');
let warning = false;
let query = queryParams.join(' OR ');
if (query.length > 1024) {
query = query.substring(0, query.substring(0, 1024).lastIndexOf('OR') - 1);
warning = true;
}
this.recordService.getRecords(
'documents', query, 1, undefined, undefined, undefined, { accept: 'application/rero+json' }
).subscribe((response: Record) => {
Expand All @@ -163,9 +168,16 @@ export class DocumentDetailComponent extends DetailComponent {
} else {
const config = {
initialState: {
records: response.hits.hits
records: response.hits.hits,
warningMessages: []
}
};
if (warning) {
config.initialState.warningMessages = [
this.translate.instant('All the identifiers have not been checked.'),
this.translate.instant('Please, check manually if a record is already present in the catalog.')
];
}
const bsModalRef = this.bsModalService.show(DialogImportComponent, config);
bsModalRef.content.confirmation$.subscribe((confirmation: boolean) => {
if (confirmation) {
Expand Down

0 comments on commit b2b4ae9

Please sign in to comment.