From 8fb36e1d318f7e63c34f7be8caff511f2c9584e0 Mon Sep 17 00:00:00 2001 From: George Date: Fri, 26 May 2023 17:52:00 +0300 Subject: [PATCH] RED-6786, made saving faster. --- .../dictionary/dictionary-screen.component.ts | 1 + .../components/editor/editor.component.html | 2 +- .../components/editor/editor.component.ts | 6 ++++-- .../entity-services/dictionary.service.ts | 19 +++++++------------ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.ts index 94063d2b9..0364da8ed 100644 --- a/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.ts @@ -58,6 +58,7 @@ export class DictionaryScreenComponent implements OnInit { null, true, DICTIONARY_TO_ENTRY_TYPE_MAP[this.type], + false, ); await this._loadEntries(); } catch (e) { diff --git a/apps/red-ui/src/app/modules/shared/components/editor/editor.component.html b/apps/red-ui/src/app/modules/shared/components/editor/editor.component.html index 10abee1e3..201ed93dc 100644 --- a/apps/red-ui/src/app/modules/shared/components/editor/editor.component.html +++ b/apps/red-ui/src/app/modules/shared/components/editor/editor.component.html @@ -1,7 +1,7 @@ dossierId: string, showToast = true, dictionaryEntryType = DictionaryEntryTypes.ENTRY, + removeCurrent = true, ) { const entriesToAdd: Array = []; const initialEntriesSet = new Set(initialEntries); let hasInvalidRows = false; - let hasNewEntries = false; for (let i = 0; i < entries.length; i++) { const entry = entries.at(i); - if (!entry.trim()) { + if (!entry.trim() || initialEntriesSet.has(entry)) { continue; } - if (entry.length < MIN_WORD_LENGTH) { - hasInvalidRows = true; - } - if (!hasNewEntries && !initialEntriesSet.has(entry)) { - hasNewEntries = true; - } - + hasInvalidRows ||= entry.length < MIN_WORD_LENGTH; entriesToAdd.push(entry); } if (hasInvalidRows) { @@ -132,8 +126,8 @@ export class DictionaryService extends EntitiesService if (deletedEntries.length) { await this._deleteEntries(deletedEntries, dossierTemplateId, type, dictionaryEntryType, dossierId); } - if (hasNewEntries) { - await this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId); + if (entriesToAdd.length) { + await this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId, removeCurrent); } if (showToast) { @@ -241,11 +235,12 @@ export class DictionaryService extends EntitiesService type: string, dictionaryEntryType: DictionaryEntryType, dossierId: string, + removeCurrent = true, ) { const queryParams: List = [ { key: 'dossierId', value: dossierId }, { key: 'dictionaryEntryType', value: dictionaryEntryType }, - { key: 'removeCurrent', value: true }, + { key: 'removeCurrent', value: removeCurrent }, ]; const url = `${this._defaultModelPath}/${type}/${dossierTemplateId}`; return firstValueFrom(this._post(entries, url, queryParams));