Commits
Alexandre Vryghem authored 227d47154ce
12 12 | import { |
13 13 | AddFieldUpdateAction, |
14 14 | DiscardObjectUpdatesAction, |
15 15 | InitializeFieldsAction, |
16 16 | ReinstateObjectUpdatesAction, |
17 17 | RemoveFieldUpdateAction, |
18 18 | SelectVirtualMetadataAction, |
19 19 | SetEditableFieldUpdateAction, |
20 20 | SetValidFieldUpdateAction |
21 21 | } from './object-updates.actions'; |
22 - | import { distinctUntilChanged, filter, map, switchMap } from 'rxjs/operators'; |
22 + | import { distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators'; |
23 23 | import { |
24 24 | hasNoValue, |
25 25 | hasValue, |
26 26 | isEmpty, |
27 27 | isNotEmpty, |
28 28 | hasValueOperator |
29 29 | } from '../../../shared/empty.util'; |
30 30 | import { INotification } from '../../../shared/notifications/models/notification.model'; |
31 31 | import { Operation } from 'fast-json-patch'; |
32 32 | import { PatchOperationService } from './patch-operation-service/patch-operation.service'; |
191 191 | }), |
192 192 | distinctUntilChanged() |
193 193 | ); |
194 194 | } |
195 195 | |
196 196 | /** |
197 197 | * Calls the saveFieldUpdate method with FieldChangeType.ADD |
198 198 | * @param url The page's URL for which the changes are saved |
199 199 | * @param field An updated field for the page's object |
200 200 | */ |
201 - | saveAddFieldUpdate(url: string, field: Identifiable) { |
201 + | saveAddFieldUpdate(url: string, field: Identifiable): Observable<boolean> { |
202 + | const update$: Observable<boolean> = this.getFieldUpdatesExclusive(url, [field]).pipe( |
203 + | filter((fieldUpdates: FieldUpdates) => fieldUpdates[field.uuid].changeType === FieldChangeType.ADD), |
204 + | take(1), |
205 + | map(() => true), |
206 + | ); |
202 207 | this.saveFieldUpdate(url, field, FieldChangeType.ADD); |
208 + | return update$; |
203 209 | } |
204 210 | |
205 211 | /** |
206 212 | * Calls the saveFieldUpdate method with FieldChangeType.REMOVE |
207 213 | * @param url The page's URL for which the changes are saved |
208 214 | * @param field An updated field for the page's object |
209 215 | */ |
210 - | saveRemoveFieldUpdate(url: string, field: Identifiable) { |
216 + | saveRemoveFieldUpdate(url: string, field: Identifiable): Observable<boolean> { |
217 + | const update$: Observable<boolean> = this.getFieldUpdatesExclusive(url, [field]).pipe( |
218 + | filter((fieldUpdates: FieldUpdates) => fieldUpdates[field.uuid].changeType === FieldChangeType.REMOVE), |
219 + | take(1), |
220 + | map(() => true), |
221 + | ); |
211 222 | this.saveFieldUpdate(url, field, FieldChangeType.REMOVE); |
223 + | return update$; |
212 224 | } |
213 225 | |
214 226 | /** |
215 227 | * Calls the saveFieldUpdate method with FieldChangeType.UPDATE |
216 228 | * @param url The page's URL for which the changes are saved |
217 229 | * @param field An updated field for the page's object |
218 230 | */ |
219 231 | saveChangeFieldUpdate(url: string, field: Identifiable) { |
220 232 | this.saveFieldUpdate(url, field, FieldChangeType.UPDATE); |
221 233 | } |