From c80b626203d75bc8f119fcdb4257ba03265c6a7e Mon Sep 17 00:00:00 2001 From: stack72 Date: Wed, 20 Dec 2023 16:53:19 +0000 Subject: [PATCH] fix(dal, sdf): Update sdf to return whether the component has codegen or not Currently we just return an empty vec so we now enhance this to return whether there we expect any codeviews or not --- lib/dal/src/component/code.rs | 6 ++++-- lib/dal/tests/integration_test/internal/component/code.rs | 2 +- lib/sdf-server/src/server/service/component/get_code.rs | 8 ++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/dal/src/component/code.rs b/lib/dal/src/component/code.rs index b578c8a6b4..b26d811ac4 100644 --- a/lib/dal/src/component/code.rs +++ b/lib/dal/src/component/code.rs @@ -28,7 +28,7 @@ impl Component { pub async fn list_code_generated( ctx: &DalContext, component_id: ComponentId, - ) -> ComponentResult> { + ) -> ComponentResult<(Vec, bool)> { let component = Self::get_by_id(ctx, &component_id) .await? .ok_or(ComponentError::NotFound(component_id))?; @@ -94,8 +94,10 @@ impl Component { code_views.push(CodeView::new(language, code, message)); } + } else { + return Ok((vec![], false)); } - Ok(code_views) + Ok((code_views, true)) } // TODO(nick): big query potential. diff --git a/lib/dal/tests/integration_test/internal/component/code.rs b/lib/dal/tests/integration_test/internal/component/code.rs index b987f03320..8732010ecb 100644 --- a/lib/dal/tests/integration_test/internal/component/code.rs +++ b/lib/dal/tests/integration_test/internal/component/code.rs @@ -151,7 +151,7 @@ async fn add_code_generation_and_list_code_views(ctx: &DalContext) { ); // Ensure the code view looks as we expect it to. - let mut code_views = Component::list_code_generated(ctx, *component.id()) + let (mut code_views, _) = Component::list_code_generated(ctx, *component.id()) .await .expect("could not list code generated for component"); let code_view = code_views.pop().expect("code views are empty"); diff --git a/lib/sdf-server/src/server/service/component/get_code.rs b/lib/sdf-server/src/server/service/component/get_code.rs index d1518818d6..29d5259258 100644 --- a/lib/sdf-server/src/server/service/component/get_code.rs +++ b/lib/sdf-server/src/server/service/component/get_code.rs @@ -17,6 +17,7 @@ pub struct GetCodeRequest { #[serde(rename_all = "camelCase")] pub struct GetCodeResponse { pub code_views: Vec, + pub has_code: bool, } pub async fn get_code( @@ -26,7 +27,10 @@ pub async fn get_code( ) -> ComponentResult> { let ctx = builder.build(request_ctx.build(request.visibility)).await?; - let code_views = Component::list_code_generated(&ctx, request.component_id).await?; + let (code_views, has_code) = Component::list_code_generated(&ctx, request.component_id).await?; - Ok(Json(GetCodeResponse { code_views })) + Ok(Json(GetCodeResponse { + code_views, + has_code, + })) }