Skip to content

Commit

Permalink
FranzCross,workspace: add publish dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Oct 14, 2023
1 parent e7aaec3 commit b8e5308
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 2 deletions.
107 changes: 107 additions & 0 deletions FranzCross/publish-dialog.rkt
Original file line number Diff line number Diff line change
@@ -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")))))
4 changes: 3 additions & 1 deletion FranzCross/view.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
#:min-size `(,width #f)
#:alignment alignment
#:stretch '(#f #t)
(text label))
(if (string? label)
(text label)
label))
v))

(define password
Expand Down
23 changes: 22 additions & 1 deletion FranzCross/workspace-window.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"keychain.rkt"
"mixin.rkt"
"observable.rkt"
"publish-dialog.rkt"
"new-topic-dialog.rkt"
"schema-detail.rkt"
"schema-registry-dialog.rkt"
Expand Down Expand Up @@ -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)))]
Expand Down Expand Up @@ -125,6 +141,10 @@
(render-popup-menu*
workspace-renderer
(popup-menu
(menu-item
"Publish Record..."
(λ () (publish item)))
(menu-item-separator)
(menu-item
"Delete"
(lambda ()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8e5308

Please sign in to comment.