Skip to content

Commit c00134f

Browse files
committed
coar-notify-7 item submission coar section send patch remove on blanking services
1 parent b94167a commit c00134f

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/app/submission/sections/section-coar-notify/section-coar-notify.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
7373
*/
7474
protected subs: Subscription[] = [];
7575

76+
private filteredServicesByPattern = {};
77+
7678
constructor(protected ldnServicesService: LdnServicesService,
7779
// protected formOperationsService: SectionFormOperationsService,
7880
protected operationsBuilder: JsonPatchOperationsBuilder,
@@ -139,11 +141,14 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
139141
if (hasPrevValueStored) {
140142
// when there is a previous value stored and it is different from the new one
141143
this.operationsBuilder.flushOperation(this.pathCombiner.getPath([pattern, '-']));
144+
if (this.filteredServicesByPattern[pattern]?.includes(this.previousServices[pattern].services[index])){
145+
this.operationsBuilder.remove(this.pathCombiner.getPath([pattern, index.toString()]));
146+
}
142147
}
143148

144-
if (!hasPrevValueStored || (selectedService?.id && hasPrevValueStored) || (!hasValue(selectedService) && hasPrevValueStored)) {
149+
if (!hasPrevValueStored || (selectedService?.id && hasPrevValueStored)) {
145150
// add the path when there is no previous value stored
146-
this.operationsBuilder.add(this.pathCombiner.getPath([pattern, '-']), hasValue(selectedService) ? [selectedService.id] : [], false, true);
151+
this.operationsBuilder.add(this.pathCombiner.getPath([pattern, '-']), [selectedService.id], false, true);
147152
}
148153
// set the previous value to the new value
149154
this.previousServices[pattern].services[index] = this.ldnServiceByPattern[pattern].services[index];
@@ -239,6 +244,14 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
239244
filter((rd) => rd.hasSucceeded),
240245
getRemoteDataPayload(),
241246
getPaginatedListPayload(),
247+
tap(res => {
248+
if (!this.filteredServicesByPattern[pattern]){
249+
this.filteredServicesByPattern[pattern] = [];
250+
}
251+
if (this.filteredServicesByPattern[pattern].length === 0) {
252+
this.filteredServicesByPattern[pattern].push(...res);
253+
}
254+
}),
242255
map((res: LdnService[]) => res.filter((service) => {
243256
if (!this.hasSectionData){
244257
this.hasSectionData = this.hasInboundPattern(service, pattern);

0 commit comments

Comments
 (0)