Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/IKC-203-monaco-editor' into IKC-…
Browse files Browse the repository at this point in the history
…305-schema-registry
  • Loading branch information
Piotr Belke authored and Piotr Belke committed Jul 28, 2023
2 parents b649640 + 03f7983 commit 127477b
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions kouncil-frontend/libs/feat-send/src/lib/send/send.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class SendComponent implements OnDestroy {
Validators.required,
]);
isSendButtonDisabled: boolean = false;
topicName: string;

keySchemaType: MessageFormat;
valueSchemaType: MessageFormat;
Expand All @@ -127,21 +128,23 @@ export class SendComponent implements OnDestroy {
this.messageDataService.messageData$,
this.schemaStateService.isSchemaConfigured$(this.servers.getSelectedServerId())
]).pipe(
switchMap(([messageData, isSchemaConfigured]) =>
iif(() => isSchemaConfigured,
this.schemaFacade.getExampleSchemaData$(this.servers.getSelectedServerId(), messageData.topicName).pipe(
map(exampleData => ({
switchMap(([messageData, isSchemaConfigured]) => {
this.topicName = messageData.topicName;
return iif(() => isSchemaConfigured,
this.schemaFacade.getExampleSchemaData$(this.servers.getSelectedServerId(), messageData.topicName).pipe(
map(exampleData => ({
...messageData,
key: messageData.key ?? JSON.stringify(exampleData.exampleKey),
value: messageData.value ? JSON.stringify(messageData.value, null, 2) :
JSON.stringify(exampleData.exampleValue, null, 2)
})
)),
of({
...messageData,
key: messageData.key ?? JSON.stringify(exampleData.exampleKey),
value: messageData.value ? JSON.stringify(messageData.value, null, 2) :
JSON.stringify(exampleData.exampleValue, null, 2)
})
)),
of({
...messageData,
value: messageData.value ? JSON.stringify(messageData.value, null, 2) : messageData.value
}
))
value: messageData.value ? JSON.stringify(messageData.value, null, 2) : messageData.value
}
))
}
)
);

Expand All @@ -157,20 +160,24 @@ export class SendComponent implements OnDestroy {
private schemaRegistry: SchemaRegistryService,
private monacoEditorService: MonacoEditorService
) {
schemaRegistry.getSchemasConfiguration$().pipe(map(configurations => {
schemaRegistry.getSchemasConfiguration$()
.pipe()
.subscribe(configurations => {
let schemasConfiguration = configurations.find(config => config.serverId === this.servers.getSelectedServerId());
if (schemasConfiguration.hasSchemaRegistry) {
this.fetchSchemas();
}
}))
})
}

ngOnDestroy() {
this.monacoEditorService.clearSchemas();
}

private fetchSchemas(): void {
this.schemaRegistry.getLatestSchemas$(this.servers.getSelectedServerId(), "TestTopic").pipe(map(result => {
this.schemaRegistry.getLatestSchemas$(this.servers.getSelectedServerId(), this.topicName)
.pipe()
.subscribe(result => {
this.keySchemaType = result.keyMessageFormat;
this.valueSchemaType = result.valueMessageFormat;

Expand All @@ -181,7 +188,7 @@ export class SendComponent implements OnDestroy {
this.monacoEditorService.addSchema('value', JSON.parse(result.valuePlainTextSchema));
}
this.monacoEditorService.registerSchemas();
}))
})
}

onSubmit(messageData: MessageData): void {
Expand Down

0 comments on commit 127477b

Please sign in to comment.