Skip to content

Commit

Permalink
feat: added naming option to workflow builder (#1169)
Browse files Browse the repository at this point in the history
Co-authored-by: Tal <[email protected]>
  • Loading branch information
pehlicd and talboren authored May 12, 2024
1 parent d65de49 commit 16dcb9a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions keep-ui/app/workflows/builder/builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function Builder({
generateWorkflow(
alertUuid,
"",
"",
[],
[],
triggers
Expand Down
5 changes: 5 additions & 0 deletions keep-ui/app/workflows/builder/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export function generateCondition(

export function generateWorkflow(
workflowId: string,
name: string,
description: string,
steps: Step[],
conditions: Step[],
Expand All @@ -194,6 +195,7 @@ export function generateWorkflow(
sequence: [...steps, ...conditions],
properties: {
id: workflowId,
name: name,
description: description,
isLocked: true,
...triggers,
Expand Down Expand Up @@ -273,6 +275,7 @@ export function parseWorkflow(

return generateWorkflow(
workflow.id,
workflow.name,
workflow.description,
steps,
conditions,
Expand Down Expand Up @@ -346,6 +349,7 @@ export function downloadFileFromString(data: string, filename: string) {
export function buildAlert(definition: Definition): Alert {
const alert = definition;
const alertId = alert.properties.id as string;
const name = (alert.properties.name as string) ?? "";
const description = (alert.properties.description as string) ?? "";
const owners = (alert.properties.owners as string[]) ?? [];
const services = (alert.properties.services as string[]) ?? [];
Expand Down Expand Up @@ -461,6 +465,7 @@ export function buildAlert(definition: Definition): Alert {
}
const compiledAlert = {
id: alertId,
name: name,
triggers: triggers,
description: description,
owners: owners,
Expand Down
5 changes: 5 additions & 0 deletions keep/api/routes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ async def update_workflow_by_id(
workflow = await __get_workflow_raw_data(request, None)
parser = Parser()
workflow_interval = parser.parse_interval(workflow)
# In case the workflow name changed to empty string, keep the old name
if workflow.get("name") != "":
workflow_from_db.name = workflow.get("name")
else:
workflow["name"] = workflow_from_db.name
workflow_from_db.description = workflow.get("description")
workflow_from_db.interval = workflow_interval
workflow_from_db.workflow_raw = yaml.dump(workflow)
Expand Down
11 changes: 8 additions & 3 deletions keep/workflowmanager/workflowstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ def create_workflow(self, tenant_id: str, created_by, workflow: dict):
workflow_id = workflow.get("id")
self.logger.info(f"Creating workflow {workflow_id}")
interval = self.parser.parse_interval(workflow)
if workflow.get("name") == "":
workflow_name = workflow_id
workflow["name"] = workflow_name
else:
workflow_name = workflow.get("name")
workflow = add_or_update_workflow(
id=str(uuid.uuid4()),
name=workflow_id,
name=workflow_name,
tenant_id=tenant_id,
description=workflow.get("description"),
created_by=created_by,
Expand All @@ -57,7 +62,7 @@ def delete_workflow(self, tenant_id, workflow_id):

def _parse_workflow_to_dict(self, workflow_path: str) -> dict:
"""
Parse an workflow to a dictionary from either a file or a URL.
Parse a workflow to a dictionary from either a file or a URL.
Args:
workflow_path (str): a URL or a file path
Expand Down Expand Up @@ -183,7 +188,7 @@ def _get_workflows_from_directory(

def _read_workflow_from_stream(self, stream) -> dict:
"""
Parse an workflow from an IO stream.
Parse a workflow from an IO stream.
Args:
stream (IOStream): The stream to read from
Expand Down

0 comments on commit 16dcb9a

Please sign in to comment.