diff --git a/common/src/import-export/utils.ts b/common/src/import-export/utils.ts index 9b761abfe8..95ab57d686 100644 --- a/common/src/import-export/utils.ts +++ b/common/src/import-export/utils.ts @@ -73,6 +73,15 @@ export class ImportExportUtils { results.add(blockConfig[name]); } } + + // globalEventsReaderBlock: schemas are stored in branches[].schema + if (Array.isArray((blockConfig as any).branches)) { + for (const branch of (blockConfig as any).branches) { + if (branch?.schema && typeof branch.schema === 'string') { + results.add(branch.schema); + } + } + } } if ( blockConfig.blockType !== BlockType.Tool && diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/global-events-reader-block/global-events-reader-block.component.ts b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/global-events-reader-block/global-events-reader-block.component.ts index 68ee28d5af..570aecaa2a 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/global-events-reader-block/global-events-reader-block.component.ts +++ b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/global-events-reader-block/global-events-reader-block.component.ts @@ -147,7 +147,7 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy { } private onUpdate(blocks: string[]): void { - if (this.readonly || this.loading) { + if (this.readonly) { return; } @@ -284,26 +284,16 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy { this.addTopicModalError = ''; this.changeDetector.detectChanges(); - this.loading = true; - const payload = { globalTopicId: topicId, active: false, filterFieldsByBranch: {}, }; - this.policyEngineService - .setBlockData(this.id, this.policyId, { - operation: 'AddTopic', - value: { streams: [payload] }, - }) - .subscribe( - () => { - }, - (e) => { - console.error(e?.error || e); - }, - ); + this.submitAndReload({ + operation: 'AddTopic', + value: { streams: [payload] }, + }); } public removeRow(index: number): void { @@ -340,20 +330,15 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy { return; } - this.loading = true; this.setRowSaving(row, true); - this.policyEngineService.setBlockData(this.id, this.policyId, { - operation: 'Delete', - value: { streams: [{ globalTopicId: topicId }] }, - }).pipe( - finalize(() => { + this.submitAndReload( + { + operation: 'Delete', + value: { streams: [{ globalTopicId: topicId }] }, + }, + () => { this.setRowSaving(row, false); - }), - ).subscribe( - () => {}, - (e) => { - console.error(e?.error || e); }, ); } @@ -440,7 +425,6 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy { return; } - this.loading = true; this.setRowSaving(row, true); const payload = { @@ -450,14 +434,13 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy { branchDocumentTypeByBranch: row.branchDocumentTypeByBranch, }; - this.policyEngineService.setBlockData(this.id, this.policyId, { - operation: 'Update', - value: { streams: [payload] }, - }).pipe( - ).subscribe( - () => {}, - (e) => { - console.error(e?.error || e); + this.submitAndReload( + { + operation: 'Update', + value: { streams: [payload] }, + }, + () => { + this.setRowSaving(row, false); }, ); } @@ -581,19 +564,10 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy { return; } - this.loading = true; - - this.policyEngineService - .setBlockData(this.id, this.policyId, { - operation: 'CreateTopic', - value: { streams: [] }, - }) - .subscribe( - () => {}, - (e) => { - console.error(e?.error || e); - }, - ); + this.submitAndReload({ + operation: 'CreateTopic', + value: { streams: [] }, + }); } public onNext(): void { @@ -607,14 +581,24 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy { return; } - this.loading = true; - - const payload = { + this.submitAndReload({ operation: 'Next', - }; + }); + } + + private submitAndReload(payload: any, onFinally?: () => void): void { + this.loading = true; this.policyEngineService .setBlockData(this.id, this.policyId, payload) + .pipe( + finalize(() => { + if (onFinally) { + onFinally(); + } + this.loadData(); + }), + ) .subscribe( () => {}, (e) => { diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/global-events-writer-block/global-events-writer-block.component.ts b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/global-events-writer-block/global-events-writer-block.component.ts index 9cdda4f016..a3c9ab6052 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/global-events-writer-block/global-events-writer-block.component.ts +++ b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/global-events-writer-block/global-events-writer-block.component.ts @@ -206,8 +206,6 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy { return; } - this.setLoading(true); - const payload = { operation: 'Update', streams: [ @@ -219,16 +217,7 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy { ], }; - this.policyEngineService - .setBlockData(this.id, this.policyId, payload) - .subscribe( - () => {}, - (e) => { - console.error(e?.error || e); - this.setLoading(false); - this.loadData(); - }, - ); + this.submitAndReload(payload); } public onStreamDocumentTypeChange(row: WriterStreamRow, value: GlobalDocumentType | null): void { @@ -305,7 +294,6 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy { } this.addTopicModalError = ''; - this.setLoading(true); this.addTopicModalOpen = false; this.addTopicModalError = ''; @@ -321,16 +309,7 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy { ], }; - this.policyEngineService - .setBlockData(this.id, this.policyId, payload) - .subscribe( - () => {}, - (e) => { - console.error(e?.error || e); - this.addTopicModalError = 'Failed to add topic'; - this.changeDetector.detectChanges(); - }, - ); + this.submitAndReload(payload); } public deleteStream(row: WriterStreamRow): void { @@ -359,21 +338,12 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy { return; } - this.setLoading(true); - const payload = { operation: 'Delete', streams: [{ topicId }], }; - this.policyEngineService - .setBlockData(this.id, this.policyId, payload) - .subscribe( - () => {}, - (e) => { - console.error(e?.error || e); - }, - ); + this.submitAndReload(payload) } public openCreateTopicModal(): void { @@ -434,21 +404,12 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy { return; } - this.setLoading(true); - const payload = { operation: 'CreateTopic', streams: [], }; - this.policyEngineService - .setBlockData(this.id, this.policyId, payload) - .subscribe( - () => {}, - (e) => { - console.error(e?.error || e); - }, - ); + this.submitAndReload(payload); } public onNext(): void { @@ -464,21 +425,12 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy { return; } - this.setLoading(true); - const payload = { operation: 'Next', streams: [], }; - this.policyEngineService - .setBlockData(this.id, this.policyId, payload) - .subscribe( - () => {}, - (e) => { - console.error(e?.error || e); - }, - ); + this.submitAndReload(payload); } public isDefaultTopic(topicId: string): boolean { @@ -493,4 +445,22 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy { } return String(index); } + + private submitAndReload(payload: any): void { + this.setLoading(true); + + this.policyEngineService + .setBlockData(this.id, this.policyId, payload) + .pipe( + finalize(() => { + this.loadData(); + }), + ) + .subscribe( + () => {}, + (e) => { + console.error(e?.error || e); + }, + ); + } }