Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/src/import-export/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy {
}

private onUpdate(blocks: string[]): void {
if (this.readonly || this.loading) {
if (this.readonly) {
return;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
},
);
}
Expand Down Expand Up @@ -440,7 +425,6 @@ export class GlobalEventsReaderBlockComponent implements OnInit, OnDestroy {
return;
}

this.loading = true;
this.setRowSaving(row, true);

const payload = {
Expand All @@ -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);
},
);
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy {
return;
}

this.setLoading(true);

const payload = {
operation: 'Update',
streams: [
Expand All @@ -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 {
Expand Down Expand Up @@ -305,7 +294,6 @@ export class GlobalEventsWriterBlockComponent implements OnInit, OnDestroy {
}

this.addTopicModalError = '';
this.setLoading(true);

this.addTopicModalOpen = false;
this.addTopicModalError = '';
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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);
},
);
}
}
Loading