Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mco/feat(Workflow) can be published, listed and deleted #123

Merged
merged 4 commits into from
Dec 4, 2024
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
7 changes: 6 additions & 1 deletion client_web/src/Config/backend.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ const auth = {
health: `${endpoint}/auth/health`,
}

const workflow = {
create: `${endpoint}/workflow/create`,
}

export {
instance,
instanceWithAuth,
root,
auth
auth,
workflow
}
84 changes: 51 additions & 33 deletions client_web/src/Pages/Workflows/CreateWorkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { normalizeName } from "@/Pages/Workflows/CreateWorkflow.utils";
// Import types correctly
import { About, Service, Action, Reaction, Workflow, Parameter } from "@/types";
import {toast} from "react-toastify";
import {instanceWithAuth} from "@/Config/backend.routes";
import {workflow as workflowRoute} from "@/Config/backend.routes";

const { Title, Text } = Typography;
const { Panel } = Collapse;
Expand Down Expand Up @@ -238,43 +240,59 @@ const CreateWorkflow: React.FC = () => {
const workflow: Workflow = {
name: workflowName,
description: workflowDescription,
actions: selectedActions.map(action => {
const actionDef = about?.server.services
service: about?.server.services.find(service =>
service.actions.some(action => action.name === selectedActions[0]?.name)
)?.name ?? "unknown",
events:
[
...selectedActions.map(action => {
const actionDef = about?.server.services
.flatMap((s: Service) => s.actions)
.find((a: Action) => a.name === action.name);

return {
name: action.name,
parameters: Object.entries(action.parameters || {}).map(([name, value]) => {
const paramDef = actionDef?.parameters.find((p: Parameter) => p.name === name);
return {
name,
type: paramDef?.type || 'string',
value
};
})
};
}),
reactions: selectedReactions.map(reaction => {
const reactionDef = about?.server.services
.flatMap((s: Service) => s.reactions)
.find((r: Reaction) => r.name === reaction.name);

return {
name: reaction.name,
parameters: Object.entries(reaction.parameters || {}).map(([name, value]) => {
const paramDef = reactionDef?.parameters.find((p: Parameter) => p.name === name);
return {
name,
type: paramDef?.type || 'string',
value
};
})
};
return {
name: action.name,
type: 'action' as "action",
description: action.description,
parameters: Object.entries(action.parameters || {}).map(([name, value]) => {
const paramDef = actionDef?.parameters.find((p: Parameter) => p.name === name);
return {
name,
type: paramDef?.type || 'string',
value
};
})
}
}),
...selectedReactions.map(reaction => {
const reactionDef = about?.server.services
.flatMap((s: Service) => s.reactions)
.find((r: Reaction) => r.name === reaction.name);

return {
name: reaction.name,
type: 'reaction' as "reaction",
description: reaction.description,
parameters: Object.entries(reaction.parameters || {}).map(([name, value]) => {
const paramDef = reactionDef?.parameters.find((p: Parameter) => p.name === name);
return {
name,
type: paramDef?.type || 'string',
value
};
})
};
})
]
}
instanceWithAuth.post(workflowRoute.create, workflow)
.then(() => {
toast.success("Workflow successfully published")
//TODO: Go to /workflow/{id}
})
};

toast.error("API not connected yet");
.catch((error) => {
console.error(error);
});
};

const handleFoldAllActions = () => {
Expand Down
14 changes: 4 additions & 10 deletions client_web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,16 @@ export interface WorkflowParameter {

export interface WorkflowDefinition {
name: string;
type: "action" | "reaction";
description: string;
parameters: WorkflowParameter[];
}

export interface WorkflowAction extends WorkflowDefinition {

}

export interface WorkflowReaction extends WorkflowDefinition {

}

export type Workflow = {
name: string;
service: string;
description: string;
actions: WorkflowAction[];
reactions: WorkflowReaction[];
events: WorkflowDefinition[];
};

export interface WorkflowItem {
Expand Down
2 changes: 1 addition & 1 deletion server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"swagger": true,
"cors_origins": [
"https://localhost:8081",
"http://example.com"
"http://localhost:8080"
]
}
Loading
Loading