From 4a9749522c408116f9eee91c01207bbd629821be Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 11 Sep 2023 21:18:13 +0300 Subject: [PATCH] feat(dal,sdf-server,web): Add ability to display the func display names as part of the ActionSprite --- app/web/src/api/sdf/dal/change_set.ts | 2 ++ app/web/src/components/ActionSprite.vue | 4 +-- .../ComponentOutline/ComponentOutlineNode.vue | 2 +- lib/dal/src/action_prototype.rs | 22 +++++++++++----- lib/dal/src/diagram/node.rs | 11 ++++---- .../change_set/list_open_change_sets.rs | 26 +++++++++++-------- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/app/web/src/api/sdf/dal/change_set.ts b/app/web/src/api/sdf/dal/change_set.ts index 501b11fa58..f22479a703 100644 --- a/app/web/src/api/sdf/dal/change_set.ts +++ b/app/web/src/api/sdf/dal/change_set.ts @@ -12,6 +12,7 @@ export type ActionPrototypeId = string; export interface ActionPrototype { id: ActionPrototypeId; name: string; + displayName: string; } export interface NewAction { @@ -19,6 +20,7 @@ export interface NewAction { prototypeId: ActionPrototypeId; name: string; componentId: ComponentId; + displayName: string; } export type ActionId = string; diff --git a/app/web/src/components/ActionSprite.vue b/app/web/src/components/ActionSprite.vue index e5369fde2c..152a455a85 100644 --- a/app/web/src/components/ActionSprite.vue +++ b/app/web/src/components/ActionSprite.vue @@ -7,9 +7,7 @@ >
- {{ actionName }} {{ component?.schemaName ?? "" }} + {{ actionName }} { return _.map(component.value.actions, (a: ActionPrototype) => { return { prototypeId: a.id, - name: a.name, + name: a.displayName !== "" ? a.displayName : a.name, componentId, } as NewAction; }); diff --git a/lib/dal/src/action_prototype.rs b/lib/dal/src/action_prototype.rs index bac00f97e9..a99e2673e0 100644 --- a/lib/dal/src/action_prototype.rs +++ b/lib/dal/src/action_prototype.rs @@ -12,9 +12,9 @@ use telemetry::prelude::*; use crate::{ component::view::ComponentViewError, func::backend::js_action::ActionRunResult, impl_standard_model, pk, standard_model, standard_model_accessor, Component, ComponentId, - ComponentView, DalContext, FuncBinding, FuncBindingError, FuncBindingReturnValueError, FuncId, - HistoryEventError, SchemaVariantId, StandardModel, StandardModelError, Tenancy, Timestamp, - TransactionsError, Visibility, WsEvent, WsEventError, + ComponentView, DalContext, Func, FuncBinding, FuncBindingError, FuncBindingReturnValueError, + FuncId, HistoryEventError, SchemaVariantId, StandardModel, StandardModelError, Tenancy, + Timestamp, TransactionsError, Visibility, WsEvent, WsEventError, }; const FIND_FOR_CONTEXT: &str = include_str!("./queries/action_prototype/find_for_context.sql"); @@ -29,11 +29,20 @@ const FIND_FOR_CONTEXT_AND_FUNC: &str = pub struct ActionPrototypeView { id: ActionPrototypeId, name: String, + display_name: Option, } impl ActionPrototypeView { - pub fn new(prototype: ActionPrototype) -> Self { - Self { + pub async fn new( + ctx: &DalContext, + prototype: ActionPrototype, + ) -> ActionPrototypeResult { + let mut display_name = None; + let func_details = Func::get_by_id(ctx, &prototype.func_id).await?; + if let Some(func) = func_details { + display_name = func.display_name().map(|dname| dname.to_string()) + }; + Ok(Self { id: prototype.id, name: prototype.name().map_or_else( || match prototype.kind() { @@ -44,7 +53,8 @@ impl ActionPrototypeView { }, ToOwned::to_owned, ), - } + display_name, + }) } } diff --git a/lib/dal/src/diagram/node.rs b/lib/dal/src/diagram/node.rs index 873da209d8..313e9c0a35 100644 --- a/lib/dal/src/diagram/node.rs +++ b/lib/dal/src/diagram/node.rs @@ -247,10 +247,11 @@ impl DiagramComponentView { }, ) .await?; - let actions = action_prototypes - .into_iter() - .map(ActionPrototypeView::new) - .collect(); + let mut action_views: Vec = Vec::new(); + for action_prototype in action_prototypes { + let view = ActionPrototypeView::new(ctx, action_prototype).await?; + action_views.push(view); + } Ok(Self { id: *component.id(), @@ -273,7 +274,7 @@ impl DiagramComponentView { node_type: component.get_type(ctx).await?, change_status, resource, - actions, + actions: action_views, created_info, updated_info, deleted_info, diff --git a/lib/sdf-server/src/server/service/change_set/list_open_change_sets.rs b/lib/sdf-server/src/server/service/change_set/list_open_change_sets.rs index 37799d63e6..a6eeeaf285 100644 --- a/lib/sdf-server/src/server/service/change_set/list_open_change_sets.rs +++ b/lib/sdf-server/src/server/service/change_set/list_open_change_sets.rs @@ -2,8 +2,8 @@ use super::ChangeSetResult; use crate::server::extract::{AccessBuilder, HandlerContext}; use axum::Json; use dal::{ - ActionId, ActionKind, ChangeSet, ChangeSetPk, ChangeSetStatus, ComponentId, StandardModel, - Visibility, + ActionId, ActionKind, ChangeSet, ChangeSetPk, ChangeSetStatus, ComponentId, Func, + StandardModel, Visibility, }; use serde::{Deserialize, Serialize}; @@ -39,18 +39,22 @@ pub async fn list_open_change_sets( let a = cs.actions(&ctx).await?; let mut actions = Vec::with_capacity(a.len()); for action in a { + let mut display_name = None; let prototype = action.prototype(&ctx).await?; + let func_details = Func::get_by_id(&ctx, &prototype.func_id()).await?; + if let Some(func) = func_details { + if func.display_name().is_some() { + display_name = func.display_name().map(|dname| dname.to_string()); + } + } actions.push(ActionView { id: *action.id(), - name: prototype.name().map_or_else( - || match prototype.kind() { - ActionKind::Create => "create".to_owned(), - ActionKind::Delete => "delete".to_owned(), - ActionKind::Other => "other".to_owned(), - ActionKind::Refresh => " refresh".to_owned(), - }, - ToOwned::to_owned, - ), + name: display_name.unwrap_or_else(|| match prototype.kind() { + ActionKind::Create => "create".to_owned(), + ActionKind::Delete => "delete".to_owned(), + ActionKind::Other => "other".to_owned(), + ActionKind::Refresh => " refresh".to_owned(), + }), component_id: *action.component_id(), }); }