Skip to content

Commit

Permalink
merge: #4049
Browse files Browse the repository at this point in the history
4049: Fix detachment for current schema variant. Allow users to delete funcs with attachments r=jobelenus a=britmyerss

<div><img src="https://media0.giphy.com/media/xULW8N9O5WD32L5052/giphy.gif?cid=5a38a5a2rjxm94xzfse8ar5v0cc1p9poa62hs0h2qdedyhym&amp;ep=v1_gifs_search&amp;rid=giphy.gif&amp;ct=g" style="border:0;height:225px;width:300px"/><br/>via <a href="https://giphy.com/pixelsbyskab/">Skab</a> on <a href="https://giphy.com/gifs/bird-homer-simpson-xULW8N9O5WD32L5052">GIPHY</a></div>

Co-authored-by: John Obelenus <[email protected]>
  • Loading branch information
si-bors-ng[bot] and jobelenus authored Jun 26, 2024
2 parents d278821 + 9e80536 commit d26167c
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 20 deletions.
7 changes: 2 additions & 5 deletions app/web/src/components/FuncEditor/FuncDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ const funcStore = useFuncStore();
const assetStore = useAssetStore();
const emit = defineEmits<{
(e: "detached"): void;
(e: "expandPanel"): void;
}>();
Expand Down Expand Up @@ -389,7 +388,7 @@ const execFunc = () => {
const isDetaching = ref(false);
const detachFunc = async () => {
if (detachRef.value && "detachFunc" in detachRef.value) {
await detachRef.value.detachFunc();
const associations = await detachRef.value.detachFunc();
if (assetStore.selectedAssetId)
assetStore.LOAD_ASSET(assetStore.selectedAssetId); // reloads the fn list
if (funcStore.selectedFuncId)
Expand All @@ -401,16 +400,14 @@ const detachFunc = async () => {
);
funcStore.selectedFuncId = undefined; // brings you back to the asset detail
/* this code was never reachable
if (associations && editingFunc.value) {
isDetaching.value = true;
await funcStore.UPDATE_FUNC({
...editingFunc.value,
associations,
});
emit("detached");
isDetaching.value = false;
} */
}
}
};
Expand Down
7 changes: 0 additions & 7 deletions app/web/src/components/Workspace/WorkspaceCustomizeAssets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
:funcId="funcStore.selectedFuncId"
:schemaVariantId="assetStore.selectedAsset?.defaultSchemaVariantId"
allowTestPanel
@detached="onDetach"
@expand-panel="rightResizablePanelRef?.maximize()"
/>
<!-- the key here is to force remounting so we get the proper asset
Expand Down Expand Up @@ -185,12 +184,6 @@ onBeforeUnmount(() => {
window.removeEventListener("keydown", onKeyDown);
});

const onDetach = async () => {
if (assetStore.selectedAssetId && funcStore.selectedFuncId) {
assetStore.closeFunc(assetStore.selectedAssetId, funcStore.selectedFuncId);
}
};

watch(
() => assetStore.selectedAssets.length,
(newVal, oldVal) => {
Expand Down
37 changes: 36 additions & 1 deletion lib/dal/src/action/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use thiserror::Error;
use veritech_client::{ActionRunResultSuccess, ResourceStatus};

use crate::{
action::ActionId,
component::ComponentUpdatedPayload,
diagram::{DiagramError, SummaryDiagramComponent},
func::{
Expand Down Expand Up @@ -421,9 +422,43 @@ impl ActionPrototype {
}
Ok(triggered_actions)
}

async fn find_enqueued_actions(
ctx: &DalContext,
id: ActionPrototypeId,
) -> ActionPrototypeResult<Vec<ActionId>> {
let mut enqueued_actions = vec![];

for (_, tail_node_idx, _head_node_idx) in ctx
.workspace_snapshot()?
.edges_directed_for_edge_weight_kind(id, Incoming, EdgeWeightKindDiscriminants::Use)
.await?
{
if let NodeWeight::Action(node_weight) = ctx
.workspace_snapshot()?
.get_node_weight(tail_node_idx)
.await?
{
enqueued_actions.push(node_weight.id().into());
}
}
Ok(enqueued_actions)
}

pub async fn remove(ctx: &DalContext, id: ActionPrototypeId) -> ActionPrototypeResult<()> {
let change_set = ctx.change_set()?;

// check if there are existing actions queued for this prototype and remove them
let enqueued_actions = dbg!(Self::find_enqueued_actions(ctx, id).await?);

for action in enqueued_actions {
ctx.workspace_snapshot()?
.remove_node_by_id(change_set, action)
.await?;
WsEvent::action_list_updated(ctx)
.await?
.publish_on_commit(ctx)
.await?;
}
ctx.workspace_snapshot()?
.remove_node_by_id(change_set, id)
.await?;
Expand Down
36 changes: 32 additions & 4 deletions lib/dal/src/func/authoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use std::sync::Arc;
use telemetry::prelude::*;
use thiserror::Error;

use crate::action::prototype::{ActionKind, ActionPrototypeError};
use crate::action::prototype::{ActionKind, ActionPrototype, ActionPrototypeError};
use crate::attribute::prototype::argument::{
AttributePrototypeArgument, AttributePrototypeArgumentError,
};
Expand All @@ -59,9 +59,10 @@ use crate::func::FuncKind;
use crate::prop::PropError;
use crate::socket::output::OutputSocketError;
use crate::{
AttributePrototypeId, ComponentError, ComponentId, DalContext, Func, FuncBackendKind,
FuncBackendResponseType, FuncError, FuncId, OutputSocketId, PropId, SchemaVariantError,
SchemaVariantId, TransactionsError, WorkspaceSnapshotError, WsEventError,
AttributePrototype, AttributePrototypeId, ComponentError, ComponentId, DalContext, Func,
FuncBackendKind, FuncBackendResponseType, FuncError, FuncId, OutputSocketId, PropId,
SchemaVariant, SchemaVariantError, SchemaVariantId, TransactionsError, WorkspaceSnapshotError,
WsEventError,
};

use super::runner::{FuncRunner, FuncRunnerError};
Expand Down Expand Up @@ -438,6 +439,33 @@ impl FuncAuthoringClient {
Ok(())
}

/// For a given [`FuncId`], regardless of what kind of [`Func`] it is, look for all associated bindings and remove
/// them from every currently attached [`SchemaVariant`]
pub async fn detach_func_from_everywhere(
ctx: &DalContext,
func_id: FuncId,
) -> FuncAuthoringResult<()> {
// first check for attribute prototypes
let maybe_attribute_prototypes =
AttributePrototype::list_ids_for_func_id(ctx, func_id).await?;
for attribute_prototype in maybe_attribute_prototypes {
save::reset_attribute_prototype(ctx, attribute_prototype, true).await?;
}

// then check for and remove authentication prototypes
for schema_variant_id in
SchemaVariant::list_schema_variant_ids_using_auth_func_id(ctx, func_id).await?
{
SchemaVariant::remove_authentication_prototype(ctx, func_id, schema_variant_id).await?;
}

// then check for and remove action prototypes
for action_prototype_id in ActionPrototype::list_for_func_id(ctx, func_id).await? {
ActionPrototype::remove(ctx, action_prototype_id).await?;
}
Ok(())
}

/// Compiles types corresponding to "lang-js".
pub fn compile_langjs_types() -> &'static str {
ts_types::compile_langjs_types()
Expand Down
Loading

0 comments on commit d26167c

Please sign in to comment.