Skip to content

Commit

Permalink
Set default metadata in options
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhickman committed Jun 4, 2023
1 parent 4cb3193 commit b1213d0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/app/body/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ impl MethodTabState {
MethodTabState {
address: address::AddressState::with_options(&service_options),
stream: stream::State::new(),
request: request::State::empty(method.input()),
request: request::State::empty(
method.input(),
service_options.default_metadata.clone(),
),
service_options,
method,
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/body/method/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ struct RequestLayout {
}

impl State {
pub fn empty(request: prost_reflect::MessageDescriptor) -> Self {
pub fn empty(request: prost_reflect::MessageDescriptor, metadata: metadata::State) -> Self {
let json = make_template_message_json(request.clone());
State::with_text(request, json, metadata::State::default())
State::with_text(request, json, metadata)
}

pub fn with_text(
Expand Down
1 change: 1 addition & 0 deletions src/app/body/options/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ where
) {
if old_data.default_address.uri() != data.default_address.uri()
|| old_data.verify_certs != data.verify_certs
|| !old_data.default_metadata.same(&data.default_metadata)
{
ctx.submit_command(
command::SET_SERVICE_OPTIONS.with((data.service.clone(), data.service_options())),
Expand Down
15 changes: 14 additions & 1 deletion src/app/body/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use prost_reflect::ServiceDescriptor;
use crate::{
app::{
body::address::{self, AddressState},
command,
command, metadata,
sidebar::service::ServiceOptions,
},
theme,
Expand All @@ -26,13 +26,16 @@ pub struct OptionsTabState {
service: ServiceDescriptor,
default_address: AddressState,
verify_certs: bool,
default_metadata: metadata::EditableState,
}

pub fn build_body() -> impl Widget<OptionsTabState> {
let id = WidgetId::next();

let tls_checkbox = theme::check_box_scope(Checkbox::new("Enable certificate verification"));

let default_metadata = metadata::build_editable();

Flex::column()
.with_child(
Label::new("Default address")
Expand All @@ -43,6 +46,14 @@ pub fn build_body() -> impl Widget<OptionsTabState> {
.with_child(build_address_bar(id))
.with_spacer(theme::BODY_SPACER)
.with_child(tls_checkbox.lens(OptionsTabState::verify_certs))
.with_spacer(theme::BODY_SPACER)
.with_child(
Label::new("Default metadata")
.with_font(theme::font::HEADER_TWO)
.align_left(),
)
.with_spacer(theme::BODY_SPACER)
.with_child(default_metadata.lens(OptionsTabState::default_metadata))
.must_fill_main_axis(true)
.cross_axis_alignment(CrossAxisAlignment::Start)
.padding(theme::BODY_PADDING)
Expand Down Expand Up @@ -88,6 +99,7 @@ impl OptionsTabState {
None => AddressState::default(),
},
verify_certs: options.verify_certs,
default_metadata: metadata::EditableState::new(options.default_metadata),
}
}

Expand All @@ -103,6 +115,7 @@ impl OptionsTabState {
ServiceOptions {
default_address: self.default_address.uri().cloned(),
verify_certs: self.verify_certs,
default_metadata: self.default_metadata.to_state(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/sidebar/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
use crate::{
app::{
command::{REMOVE_SERVICE, SELECT_OR_CREATE_OPTIONS_TAB},
metadata,
sidebar::method,
},
theme,
Expand Down Expand Up @@ -45,13 +46,15 @@ pub struct ServiceOptions {
#[serde(with = "serde_opt_uri")]
pub default_address: Option<Uri>,
pub verify_certs: bool,
pub default_metadata: metadata::State,
}

impl Default for ServiceOptions {
fn default() -> Self {
Self {
default_address: Default::default(),
verify_certs: true,
default_metadata: metadata::State::default(),
}
}
}
Expand Down

0 comments on commit b1213d0

Please sign in to comment.