From b8e53084c51314ce82ebb0521872e10bf9a86b9b Mon Sep 17 00:00:00 2001 From: Bogdan Popa Date: Sat, 14 Oct 2023 09:23:26 +0300 Subject: [PATCH] FranzCross,workspace: add publish dialog --- FranzCross/publish-dialog.rkt | 107 ++++++++++++++++++++++++++++++++ FranzCross/view.rkt | 4 +- FranzCross/workspace-window.rkt | 23 ++++++- 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 FranzCross/publish-dialog.rkt diff --git a/FranzCross/publish-dialog.rkt b/FranzCross/publish-dialog.rkt new file mode 100644 index 0000000..4e1981a --- /dev/null +++ b/FranzCross/publish-dialog.rkt @@ -0,0 +1,107 @@ +#lang racket/gui/easy + +(require franz/broker + (submod franz/workspace rpc) + "editor.rkt" + "mixin.rkt" + "observable.rkt" + "view.rkt") + +(provide + publish-dialog) + +(define (publish-dialog id [selected-topic-name #f] + #:publish-action [publish void] + #:cancel-action [cancel void]) + (define close! void) + (define metadata + (get-metadata #t id)) + (define labeled* + (make-labeled 80)) + (define selected-topic + (or + (findf + (λ (t) (equal? (Topic-name t) selected-topic-name)) + (Metadata-topics metadata)) + (let ([topics (Metadata-topics metadata)]) + (and (not (null? topics)) (car topics))))) + (define-observables + [@metadata metadata] + [@topic selected-topic] + [@topic-partition (and selected-topic (car (Topic-partitions selected-topic)))] + [@key "{}"] + [@key-enabled? #t] + [@value "{}"] + [@value-enabled? #t]) + (dialog + #:title "Publish Record" + #:mixin + (mix-close-window void (λ (close!-proc) + (set! close! close!-proc))) + (vpanel + #:margin '(10 10) + (labeled* + "Topic:" + (choice + (@metadata . ~> . Metadata-topics) + #:choice->label (compose1 ~truncate Topic-name) + #:selection @topic + (lambda (topic) + (@topic:= topic) + (@topic-partition:= (car (Topic-partitions topic)))))) + (labeled* + "Partition:" + (choice + #:enabled? (@topic . ~> . (compose1 not not)) + (let-observable ([t @topic]) + (if t (Topic-partitions t) null)) + #:choice->label (compose1 number->string TopicPartition-id) + #:selection @topic-partition + @topic-partition:=)) + (labeled* + (vpanel + #:alignment '(right top) + (text "Key:") + (checkbox + #:checked? @key-enabled? + @key-enabled?:=)) + #:alignment '(right top) + (hpanel + #:min-size '(#f 100) + (editor #:lang 'json ^@key @key:=))) + (labeled* + (vpanel + #:alignment '(right top) + (text "Value:") + (checkbox + #:checked? @value-enabled? + @value-enabled?:=)) + #:alignment '(right top) + (hpanel + #:min-size '(#f 100) + (editor #:lang 'json ^@value @value:=))) + (labeled* + "" + (hpanel + (button + "Publish" + #:style '(border) + (lambda () + (publish + (Topic-name ^@topic) + (TopicPartition-id ^@topic-partition) + (and ^@key-enabled? ^@key) + (and ^@value-enabled? ^@value)) + (close!))) + (button + "Cancel" + (lambda () + (cancel) + (close!)))))))) + +(module+ main + (require "testing.rkt") + (call-with-testing-context + (lambda (id) + (render + (publish-dialog id "example-topic"))))) diff --git a/FranzCross/view.rkt b/FranzCross/view.rkt index bdef219..b76d023 100644 --- a/FranzCross/view.rkt +++ b/FranzCross/view.rkt @@ -36,7 +36,9 @@ #:min-size `(,width #f) #:alignment alignment #:stretch '(#f #t) - (text label)) + (if (string? label) + (text label) + label)) v)) (define password diff --git a/FranzCross/workspace-window.rkt b/FranzCross/workspace-window.rkt index 65d8394..51740d2 100644 --- a/FranzCross/workspace-window.rkt +++ b/FranzCross/workspace-window.rkt @@ -17,6 +17,7 @@ "keychain.rkt" "mixin.rkt" "observable.rkt" + "publish-dialog.rkt" "new-topic-dialog.rkt" "schema-detail.rkt" "schema-registry-dialog.rkt" @@ -83,6 +84,21 @@ (create-topic name partitions replication-factor the-options id) (reload-metadata))) (m:get-workspace-renderer id))) + (define (publish [item ^@selected-item]) + (render + (publish-dialog + id (and item + (Topic? item) + (Topic-name item)) + #:publish-action + (lambda (topic-name partition-id key value) + (publish-record + topic-name + partition-id + (and key (string->bytes/utf-8 key)) + (and value (string->bytes/utf-8 value)) + id))) + (m:get-workspace-renderer id))) (define (open-consumer-group gid) (define group (for/first ([g (in-list (Metadata-groups (state-metadata ^@state)))] @@ -125,6 +141,10 @@ (render-popup-menu* workspace-renderer (popup-menu + (menu-item + "Publish Record..." + (λ () (publish item))) + (menu-item-separator) (menu-item "Delete" (lambda () @@ -191,7 +211,8 @@ (menu-item "&New Topic..." #:shortcut (kbd cmd #\n) - new-topic)) + new-topic) + (menu-item "&Publish Record..." publish)) (menu "Schema &Registry" (menu-item