Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions frontend/src/lib/components/Tooltip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@
}
});
const action = trigger(node);
function handleEscape(event) {
if (event.key !== 'Escape' || !get(open)) return;
open.set(false);
event.preventDefault();
event.stopPropagation();
}
node.addEventListener('keydown', handleEscape, true);
return () => {
node.removeEventListener('keydown', handleEscape, true);
action?.destroy?.();
unsubscribe();
for (const name of ['data-melt-tooltip-trigger', 'data-state']) node.removeAttribute(name);
Expand Down
508 changes: 181 additions & 327 deletions frontend/src/lib/features/actions/ActionFlowEditor.svelte

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions frontend/src/lib/features/actions/ActionsSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

let actions = $state([]);
let statuses = $state([]);
let statusesState = $state('idle');
let loading = $state(true);
let editingAction = $state(null);
let viewingLogsAction = $state(null);
Expand Down Expand Up @@ -171,12 +172,15 @@

async function loadStatuses() {
if (readController.signal.aborted) return;
statusesState = 'loading';
try {
statuses = await workspaces.getStatuses(workspaceId, null, { signal: readController.signal }) || [];
statusesState = 'ready';
} catch (error) {
if (readController.signal.aborted) return;
console.error('Failed to load statuses:', error);
statuses = [];
statusesState = 'error';
}
}

Expand Down Expand Up @@ -277,6 +281,7 @@
<ActionFlowEditor
action={editingAction}
{statuses}
{statusesState}
onSave={handleSaveAction}
onCancel={handleCancelEdit}
/>
Expand Down
72 changes: 12 additions & 60 deletions frontend/src/lib/features/actions/CreateAssetConfigPanel.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import { onMount } from 'svelte';
import { assetCategories, assetSets as assetSetsApi, assetStatuses, assetTypes as assetTypesApi } from '../../api/assets.js';
import { useActionEditorContext } from './shared/actionEditorContext.js';
import PlaceholderFieldLabel from './PlaceholderFieldLabel.svelte';
import { t } from '../../stores/i18n.svelte.js';
import { actionFlowStore } from '../../stores/actionFlowStore.svelte.js';
Expand All @@ -9,7 +8,6 @@
import Textarea from '../../components/Textarea.svelte';
import FieldMappingsEditor from './shared/FieldMappingsEditor.svelte';
import {
useAssetTypeFields,
applyAssetTypeChange,
applyMappingsChange,
} from './shared/assetConfigHelpers.svelte.js';
Expand All @@ -20,62 +18,15 @@
showPlaceholderModal = $bindable(false),
} = $props();

// Data state
let assetSets = $state([]);
let assetTypes = $state([]);
let categories = $state([]);
let statuses = $state([]);
let loading = $state(true);
let assetSetLoadToken = 0;

const assetTypeFields = useAssetTypeFields(
() => selectedNode?.data?.config?.asset_type_id
);

// Load asset sets on mount
onMount(async () => {
try {
assetSets = await assetSetsApi.getAll() || [];
} catch (error) {
console.error('Failed to load asset sets:', error);
} finally {
loading = false;
}
});

// When asset set changes, load types, categories, and statuses
$effect(() => {
const setId = selectedNode?.data?.config?.asset_set_id;
if (setId) {
loadAssetSetData(setId);
} else {
assetSetLoadToken += 1;
assetTypes = [];
categories = [];
statuses = [];
}
});

async function loadAssetSetData(setId) {
const token = ++assetSetLoadToken;
try {
const [typesResult, categoriesResult, statusesResult] = await Promise.all([
assetTypesApi.getAll(setId),
assetCategories.getAll(setId),
assetStatuses.getAll(setId)
]);
if (token !== assetSetLoadToken) return;
assetTypes = typesResult || [];
categories = categoriesResult || [];
statuses = statusesResult || [];
} catch (error) {
if (token !== assetSetLoadToken) return;
console.error('Failed to load asset set data:', error);
assetTypes = [];
categories = [];
statuses = [];
}
}
const editor = useActionEditorContext();
let editorData = $derived(editor.getEditorData());
let scope = $derived(editorData.assetDestinations?.[String(selectedNode.data?.config?.asset_set_id)]);
let assetSets = $derived(editorData.assetSets?.items || []);
let assetTypes = $derived(scope?.types?.items || []);
let categories = $derived(scope?.categories?.items || []);
let statuses = $derived(scope?.statuses?.items || []);
let loading = $derived(editorData.assetSets?.state === 'loading');
let targetFields = $derived(editorData.assetFieldsByType?.[`${selectedNode.data?.config?.asset_set_id}:${selectedNode.data?.config?.asset_type_id}`]?.items || []);

function handleAssetSetChange(e) {
const value = parseInt(e.target.value) || 0;
Expand Down Expand Up @@ -236,7 +187,8 @@
<!-- Step 4: Field mappings -->
<FieldMappingsEditor
mappings={selectedNode.data?.config?.field_mappings || []}
targetFields={assetTypeFields.fields}
{targetFields}
sourceFields={editorData.customFields?.items || []}
bind:showPlaceholderModal
onchange={handleMappingsChange}
/>
Expand Down
24 changes: 10 additions & 14 deletions frontend/src/lib/features/actions/CreateItemConfigPanel.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import { onMount } from 'svelte';
import { itemTypes as itemTypesApi } from '../../api/configuration.js';
import { useActionEditorContext } from './shared/actionEditorContext.js';
import { actionFlowStore } from '../../stores/actionFlowStore.svelte.js';
import WorkspacePicker from '../../pickers/WorkspacePicker.svelte';
import ItemPicker from '../../pickers/ItemPicker.svelte';
Expand All @@ -9,18 +8,11 @@

let { selectedNode, flowStore = actionFlowStore } = $props();

let itemTypes = $state([]);
let loading = $state(true);

onMount(async () => {
try {
itemTypes = await itemTypesApi.getAll() || [];
} catch (error) {
console.error('Failed to load item types:', error);
} finally {
loading = false;
}
});
const editor = useActionEditorContext();
let editorData = $derived(editor.getEditorData());
let scope = $derived(editorData.workspaceDestinations?.[String(selectedNode.data?.config?.workspace_id)]);
let itemTypes = $derived(scope?.types?.items || []);
let loading = $derived(scope?.types?.state === 'loading');

function handleWorkspaceSelect(workspace) {
flowStore.updateNodeConfig(selectedNode.id, {
Expand Down Expand Up @@ -64,6 +56,8 @@
<div>
<div class="block text-xs font-medium mb-1">Workspace</div>
<WorkspacePicker
id="create-item-workspace"
optionTestid={(option) => `create-item-workspace-${option.value}`}
multiple={false}
value={selectedNode.data?.config?.workspace_id || null}
onSelect={handleWorkspaceSelect}
Expand All @@ -74,6 +68,8 @@
<div>
<div class="block text-xs font-medium mb-1">Item Type</div>
<ItemPicker
id="create-item-type"
optionTestid={(option) => `create-item-type-${option.value}`}
items={itemTypes}
value={selectedNode.data?.config?.item_type_id || null}
config={itemTypePickerConfig}
Expand Down
74 changes: 11 additions & 63 deletions frontend/src/lib/features/actions/UpdateAssetConfigPanel.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<script>
import { onMount } from 'svelte';
import { customFields as customFieldsApi } from '../../api/configuration.js';
import { assetTypes as assetTypesApi } from '../../api/assets.js';
import { useActionEditorContext } from './shared/actionEditorContext.js';
import { t } from '../../stores/i18n.svelte.js';
import { actionFlowStore } from '../../stores/actionFlowStore.svelte.js';
import Select from '../../components/Select.svelte';
import FieldMappingsEditor from './shared/FieldMappingsEditor.svelte';
import {
useAssetTypeFields,
applyAssetTypeChange,
applyMappingsChange,
} from './shared/assetConfigHelpers.svelte.js';
Expand All @@ -18,70 +15,20 @@
showPlaceholderModal = $bindable(false),
} = $props();

// Data state
let customFields = $state([]);
let assetFields = $state([]);
let assetTypes = $state([]);
let loading = $state(true);
let assetTypesLoadToken = 0;

const assetTypeFields = useAssetTypeFields(
() => selectedNode?.data?.config?.asset_type_id
);

// Load custom fields on mount
onMount(async () => {
try {
customFields = await customFieldsApi.getAll();
// Filter to only asset type fields
assetFields = customFields.filter(f => f.field_type === 'asset');
} catch (error) {
console.error('Failed to load custom fields:', error);
} finally {
loading = false;
}
});

// When source field changes, load the asset types for that field's asset set
$effect(() => {
const sourceFieldId = selectedNode?.data?.config?.source_field_id;
if (sourceFieldId) {
loadAssetTypes(sourceFieldId);
} else {
assetTypesLoadToken += 1;
assetTypes = [];
}
});

async function loadAssetTypes(sourceFieldId) {
const token = ++assetTypesLoadToken;
const field = assetFields.find(f => f.id === sourceFieldId || f.field_name === sourceFieldId);
if (!field?.field_config?.asset_set_id) {
assetTypes = [];
return;
}

try {
const nextAssetTypes = await assetTypesApi.getAll(field.field_config.asset_set_id) || [];
if (token !== assetTypesLoadToken) return;
assetTypes = nextAssetTypes;
// Update the asset_set_id in config
flowStore.updateNodeConfig(selectedNode.id, {
asset_set_id: field.field_config.asset_set_id
});
} catch (error) {
if (token !== assetTypesLoadToken) return;
console.error('Failed to load asset types:', error);
assetTypes = [];
}
}
const editor = useActionEditorContext();
let editorData = $derived(editor.getEditorData());
let assetFields = $derived((editorData.assetReferenceFields?.items || []).filter((field) => field.field_type === 'asset'));
let setId = $derived(editorData.sourceAssetSet(selectedNode.data?.config));
let assetTypes = $derived(editorData.assetDestinations?.[String(setId)]?.types?.items || []);
let targetFields = $derived(editorData.assetFieldsByType?.[`${setId}:${selectedNode.data?.config?.asset_type_id}`]?.items || []);
let loading = $derived(editorData.assetReferenceFields?.state === 'loading');

function handleSourceFieldChange(e) {
const value = e.target.value;
flowStore.updateNodeConfig(selectedNode.id, {
source_field_id: value,
asset_type_id: 0,
asset_set_id: 0,
asset_set_id: assetFields.find((field) => field.field_name === value)?.field_config?.asset_set_id || 0,
field_mappings: []
});
}
Expand Down Expand Up @@ -126,7 +73,8 @@
{#if selectedNode.data?.config?.asset_type_id}
<FieldMappingsEditor
mappings={selectedNode.data?.config?.field_mappings || []}
targetFields={assetTypeFields.fields}
{targetFields}
sourceFields={editorData.customFields?.items || []}
bind:showPlaceholderModal
onchange={handleMappingsChange}
/>
Expand Down
48 changes: 41 additions & 7 deletions frontend/src/lib/features/actions/conditionOperators.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
// Condition operator options shared by the asset and workspace action flow
// editors. Keeping them in one place stops the two editors from drifting.
export const conditionOperators = [
{ value: 'eq', label: 'Equals' },
{ value: 'ne', label: 'Not Equals' },
{ value: 'contains', label: 'Contains' },
{ value: 'not_contains', label: 'Not Contains' },
{ value: 'starts_with', label: 'Starts With' },
{ value: 'ends_with', label: 'Ends With' },
const operatorKeys = {
eq: 'equals',
ne: 'notEquals',
contains: 'contains',
not_contains: 'notContains',
starts_with: 'startsWith',
ends_with: 'endsWith',
gt: 'greaterThan',
lt: 'lessThan',
is_empty: 'isEmpty',
is_not_empty: 'isNotEmpty',
matches: 'matches',
};
const assetLabels = [
'Equals',
'Not Equals',
'Contains',
'Not Contains',
'Starts With',
'Ends With',
];
export const conditionOperators = [
'eq',
'ne',
'contains',
'not_contains',
'starts_with',
'ends_with',
].map((value, index) => ({ value, label: assetLabels[index] }));

export function conditionOperatorLabel(operator, t) {
return Object.hasOwn(operatorKeys, operator)
? t(`actions.operators.${operatorKeys[operator]}`)
: operator;
}

export function workspaceConditionOperators(t) {
return ['eq', 'ne', 'contains', 'gt', 'lt', 'is_empty', 'is_not_empty'].map((value) => ({
value,
label: conditionOperatorLabel(value, t),
}));
}

// Text-bearing triggers (documents) additionally support regex matching.
export const conditionOperatorsWithRegex = [
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/features/actions/edges/ActionEdge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
: '');
</script>

<g data-testid="action-edge">
<!-- Hide base edge during reconnection -->
{#if !reconnecting}
<BaseEdge
Expand Down Expand Up @@ -81,12 +82,14 @@
>
<div
class="edge-label"
data-testid={`action-edge-branch-${sourceHandleId}`}
style:background-color={edgeColor}
>
{labelText}
</div>
</foreignObject>
{/if}
</g>

<style>
.edge-label {
Expand Down
10 changes: 0 additions & 10 deletions frontend/src/lib/features/actions/nodes/AIAgentNode.svelte

This file was deleted.

Loading
Loading