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, + })) }