Skip to content

Commit

Permalink
Rework features so that "item_interactions" and `"item_state_exampl…
Browse files Browse the repository at this point in the history
…e"` are not always enabled.
  • Loading branch information
azriel91 committed Oct 19, 2024
1 parent 3a5fab1 commit 23e2cf9
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 29 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ output_progress = [
item_interactions = [
"dep:peace_item_model",
"peace_cfg/item_interactions",
"peace_webi?/item_interactions",
"peace_webi_components?/item_interactions",
]
item_state_example = [
"peace_cfg/item_state_example",
"peace_cmd/item_state_example",
"peace_data/item_state_example",
"peace_params/item_state_example",
"peace_rt_model/item_state_example",
"peace_webi?/item_state_example",
"peace_webi_components?/item_state_example",
]
ssr = [
"peace_webi?/ssr",
Expand Down
8 changes: 8 additions & 0 deletions crate/webi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ peace_webi_output = { workspace = true, optional = true }

[features]
default = []
item_interactions = [
"peace_webi_components/item_interactions",
"peace_webi_output?/item_interactions",
]
item_state_example = [
"peace_webi_components/item_state_example",
"peace_webi_output?/item_state_example",
]
output_progress = [
"peace_webi_model/output_progress",
"peace_webi_output?/output_progress",
Expand Down
14 changes: 12 additions & 2 deletions crate/webi_components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ gloo-timers = { workspace = true, features = ["futures"] }
leptos = { workspace = true }
leptos_meta = { workspace = true }
leptos_router = { workspace = true }
peace_cmd = { workspace = true, features = ["item_state_example"] }
peace_cmd = { workspace = true }
peace_cmd_model = { workspace = true }
peace_core = { workspace = true }
peace_flow_model = { workspace = true }
peace_item_model = { workspace = true }
peace_params = { workspace = true }
peace_resource_rt = { workspace = true }
peace_rt_model = { workspace = true, features = ["item_interactions", "item_state_example"] }
peace_rt_model = { workspace = true }
peace_webi_model = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
Expand All @@ -43,6 +43,16 @@ serde_yaml = { workspace = true }

[features]
default = []

# Technically always needed, but we need to put these in its own feature so that
# these aren't enabled in the underlying crates when `--no-default-features` is
# used.
item_interactions = ["peace_rt_model/item_interactions"]
item_state_example = [
"peace_cmd/item_state_example",
"peace_rt_model/item_state_example",
]

ssr = [
"dot_ix/ssr",
"leptos/ssr",
Expand Down
1 change: 1 addition & 0 deletions crate/webi_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ serde = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }

[features]
default = []
error_reporting = ["dep:miette"]
output_progress = [
"dep:peace_item_model",
Expand Down
8 changes: 8 additions & 0 deletions crate/webi_output/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ tower-http = { workspace = true, features = ["fs"] }

[features]
default = []
item_interactions = [
"peace_rt_model/item_interactions",
"peace_webi_components/item_interactions",
]
item_state_example = [
"peace_rt_model/item_state_example",
"peace_webi_components/item_state_example",
]
output_progress = [
"peace_cmd_model/output_progress",
"peace_core/output_progress",
Expand Down
10 changes: 7 additions & 3 deletions crate/webi_output/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
pub use crate::{
cmd_exec_spawn_ctx::CmdExecSpawnCtx, cmd_exec_to_leptos_ctx::CmdExecToLeptosCtx,
flow_webi_fns::FlowWebiFns, outcome_info_graph_calculator::OutcomeInfoGraphCalculator,
webi_output::WebiOutput, webi_server::WebiServer,
flow_webi_fns::FlowWebiFns, webi_output::WebiOutput, webi_server::WebiServer,
};

#[cfg(feature = "item_interactions")]
pub use crate::outcome_info_graph_calculator::OutcomeInfoGraphCalculator;

#[cfg(feature = "output_progress")]
pub use crate::progress_info_graph_calculator::ProgressInfoGraphCalculator;

Expand All @@ -14,9 +16,11 @@ pub mod assets;
mod cmd_exec_spawn_ctx;
mod cmd_exec_to_leptos_ctx;
mod flow_webi_fns;
mod outcome_info_graph_calculator;
mod webi_output;
mod webi_server;

#[cfg(feature = "item_interactions")]
mod outcome_info_graph_calculator;

#[cfg(feature = "output_progress")]
mod progress_info_graph_calculator;
77 changes: 54 additions & 23 deletions crate/webi_output/src/webi_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ use leptos_axum::LeptosRoutes;
use peace_cmd_model::CmdExecutionId;
use peace_core::FlowId;
use peace_webi_components::{ChildrenFn, Home};
use peace_webi_model::{OutcomeInfoGraphVariant, WebUiUpdate, WebiError};
use peace_webi_model::{WebUiUpdate, WebiError};
use tokio::{io::AsyncWriteExt, sync::mpsc};
use tower_http::services::ServeDir;

use crate::{
CmdExecSpawnCtx, CmdExecToLeptosCtx, FlowWebiFns, OutcomeInfoGraphCalculator, WebiOutput,
};
use crate::{CmdExecSpawnCtx, CmdExecToLeptosCtx, FlowWebiFns, WebiOutput};

#[cfg(feature = "item_interactions")]
use crate::OutcomeInfoGraphCalculator;
#[cfg(feature = "item_interactions")]
use peace_webi_model::OutcomeInfoGraphVariant;

#[cfg(feature = "output_progress")]
use std::collections::HashMap;
Expand Down Expand Up @@ -113,12 +116,26 @@ impl WebiServer {
let flow_outcome_example_info_graph = outcome_info_graph_fn(
&mut webi_output_mock,
Box::new(|flow, params_specs, resources| {
OutcomeInfoGraphCalculator::calculate::<E>(
flow,
params_specs,
resources,
OutcomeInfoGraphVariant::Example,
)
#[cfg(all(feature = "item_interactions", feature = "item_state_example"))]
{
OutcomeInfoGraphCalculator::calculate::<E>(
flow,
params_specs,
resources,
OutcomeInfoGraphVariant::Example,
)
}

#[cfg(not(all(feature = "item_interactions", feature = "item_state_example")))]
{
use dot_ix_model::info_graph::InfoGraph;

let _flow = flow;
let _params_specs = params_specs;
let _resources = resources;

InfoGraph::default()
}
}),
)
.await;

Check warning on line 141 in crate/webi_output/src/webi_server.rs

View check run for this annotation

Codecov / codecov/patch

crate/webi_output/src/webi_server.rs#L77-L141

Added lines #L77 - L141 were not covered by tests
Expand Down Expand Up @@ -274,19 +291,33 @@ impl WebiServer {
let item_progress_statuses =
item_progress_statuses_snapshot.clone();

OutcomeInfoGraphCalculator::calculate::<E>(
flow,
params_specs,
resources,
OutcomeInfoGraphVariant::Current {
#[cfg(feature = "output_progress")]
cmd_block_item_interaction_type,
#[cfg(feature = "output_progress")]
item_location_states,
#[cfg(feature = "output_progress")]
item_progress_statuses,
},
)
#[cfg(feature = "item_interactions")]
{
OutcomeInfoGraphCalculator::calculate::<E>(
flow,
params_specs,
resources,
OutcomeInfoGraphVariant::Current {
#[cfg(feature = "output_progress")]
cmd_block_item_interaction_type,
#[cfg(feature = "output_progress")]
item_location_states,
#[cfg(feature = "output_progress")]
item_progress_statuses,
},
)
}

#[cfg(not(feature = "item_interactions"))]
{
use dot_ix_model::info_graph::InfoGraph;

let _flow = flow;
let _params_specs = params_specs;
let _resources = resources;

InfoGraph::default()
}
}),
)
.await;

Check warning on line 323 in crate/webi_output/src/webi_server.rs

View check run for this annotation

Codecov / codecov/patch

crate/webi_output/src/webi_server.rs#L285-L323

Added lines #L285 - L323 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion workspace_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tokio = { workspace = true, features = ["rt", "macros"] }
tynm = { workspace = true }

[features]
default = ["items", "output_in_memory", "webi", "item_interactions", "item_state_example"]
default = ["items", "output_in_memory", "webi"]

# `peace` features
error_reporting = ["peace/error_reporting"]
Expand Down

0 comments on commit 23e2cf9

Please sign in to comment.