Skip to content

Commit

Permalink
merge: #2739
Browse files Browse the repository at this point in the history
2739: feat(dal,sdf-server,web): Add ability to display the func display names as part of the ActionSprite r=stack72 a=stack72

This gives us the following when we attach different functions:

<img width="523" alt="Screenshot 2023-09-11 at 21 22 46" src="https://github.com/systeminit/si/assets/227823/72f1a45e-b29b-4381-8553-b04d3a8cf3f6">

<img width="431" alt="Screenshot 2023-09-11 at 21 22 57" src="https://github.com/systeminit/si/assets/227823/b01aff7b-28a3-4c10-8218-1906d04c8bba">


Co-authored-by: stack72 <[email protected]>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Sep 12, 2023
2 parents 8981b91 + 4a97495 commit 32e4c00
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
2 changes: 2 additions & 0 deletions app/web/src/api/sdf/dal/change_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export type ActionPrototypeId = string;
export interface ActionPrototype {
id: ActionPrototypeId;
name: string;
displayName: string;
}

export interface NewAction {
id: never;
prototypeId: ActionPrototypeId;
name: string;
componentId: ComponentId;
displayName: string;
}

export type ActionId = string;
Expand Down
4 changes: 1 addition & 3 deletions app/web/src/components/ActionSprite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
>
<div class="flex flex-col min-w-0 grow">
<span class="font-bold truncate flex flex-row">
<span class="grow"
>{{ actionName }} {{ component?.schemaName ?? "" }}</span
>
<span class="grow">{{ actionName }}</span>
<VButton
v-if="props.action.id"
class="ml-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ const actions = computed((): NewAction[] => {
return _.map(component.value.actions, (a: ActionPrototype) => {
return {
prototypeId: a.id,
name: a.name,
name: a.displayName !== "" ? a.displayName : a.name,
componentId,
} as NewAction;
});
Expand Down
22 changes: 16 additions & 6 deletions lib/dal/src/action_prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -29,11 +29,20 @@ const FIND_FOR_CONTEXT_AND_FUNC: &str =
pub struct ActionPrototypeView {
id: ActionPrototypeId,
name: String,
display_name: Option<String>,
}

impl ActionPrototypeView {
pub fn new(prototype: ActionPrototype) -> Self {
Self {
pub async fn new(
ctx: &DalContext,
prototype: ActionPrototype,
) -> ActionPrototypeResult<ActionPrototypeView> {
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() {
Expand All @@ -44,7 +53,8 @@ impl ActionPrototypeView {
},
ToOwned::to_owned,
),
}
display_name,
})
}
}

Expand Down
11 changes: 6 additions & 5 deletions lib/dal/src/diagram/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ impl DiagramComponentView {
},
)
.await?;
let actions = action_prototypes
.into_iter()
.map(ActionPrototypeView::new)
.collect();
let mut action_views: Vec<ActionPrototypeView> = 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(),
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(),
});
}
Expand Down

0 comments on commit 32e4c00

Please sign in to comment.