Skip to content

Commit

Permalink
Added UI functionality to edit workflow executions
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsidhu85 committed Jan 9, 2025
1 parent a01a678 commit 32ced55
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 13 deletions.
9 changes: 9 additions & 0 deletions app/components/inline_edit_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= form_with(
url: url,
method: :get,
class: "w-full"
) do |form| %>

<%= form.text_field input_name.to_sym, value: value, class: "form-control" %>
<%= form.hidden_field :format, value: "turbo_stream" %>
<% end %>
12 changes: 12 additions & 0 deletions app/components/inline_edit_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

# Component to render activity
class InlineEditComponent < Component
attr_accessor :url, :input_name, :value

def initialize(url:, input_name:, value:)
@url = url
@input_name = input_name
@value = value
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
@search_params[:name_or_id_cont],
highlighter: '<mark class="bg-primary-300 dark:bg-primary-600">\1</mark>',
) %>
</span>
</span>
<% else %>
<%= workflow_execution[column.to_sym] %>
<% end %>
Expand Down
20 changes: 16 additions & 4 deletions app/controllers/concerns/workflow_execution_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,30 @@ def index
end

def edit
authorize! @namespace
authorize! @workflow_execution

respond_to do |format|
format.turbo_stream do
render status: :ok
end
end
end

def update
def update # rubocop:disable Metrics/MethodLength
respond_to do |format|
format.turbo_stream do
@updated = WorkflowExecutions::UpdateService.new(@workflow_execution, current_user,
workflow_execution_update_params).execute
if @updated
render status: :ok
render status: :ok,
locals: { type: 'success',
message: t('concerns.workflow_execution_actions.update.success',
workflow_name: @workflow_execution.metadata['workflow_name']) }
else
render status: :unprocessable_entity
render status: :unprocessable_entity, locals: {
type: 'alert', message: t('concerns.workflow_execution_actions.update.error',
workflow_name: @workflow_execution.metadata['workflow_name'])
}
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions app/policies/workflow_execution_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def cancel? # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
false
end

def edit?
return true if record.submitter.id == user.id
return true if effective_access_level >= Member::AccessLevel::ANALYST

details[:id] = record.id
false
end

def update?
return true if record.submitter.id == user.id
return true if effective_access_level >= Member::AccessLevel::ANALYST
Expand Down
54 changes: 54 additions & 0 deletions app/views/projects/workflow_executions/_edit_dialog.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<%= viral_dialog(open: open,classes: ["overflow-visible"]) do |dialog| %>
<%= dialog.with_header(
title:
t(
"projects.workflow_executions.edit_dialog.title",
workflow_execution_id: @workflow_execution.id,
),
) %>
<%= dialog.with_section do %>

<div class="mb-6 text-lg font-normal text-slate-500 dark:text-slate-400">
<p class="dark:text-slate-400">
<%= t(
"projects.workflow_executions.edit_dialog.description",
workflow_execution_id: @workflow_execution.id,
) %>
</p>
</div>

<div class="mb-4">
<%= turbo_frame_tag("edit_workflow_execution_error_alert") %>
</div>

<%= form_with(model: workflow_execution, url: namespace_project_workflow_execution_path, method: :patch, class: "grid gap-4") do |form| %>
<div class="form-field">
<%= form.label :name %>
<%= form.text_field :name,
autofocus: true,
value: @workflow_execution.name,
placeholder:
t("projects.workflow_executions.edit_dialog.name_placeholder") %>

</div>

<div class="mt-4">
<%= form.submit t("projects.workflow_executions.edit_dialog.submit_button"),
class:
"focus:outline-none text-sm text-white bg-primary-700 hover:bg-primary-800 focus:ring-0 rounded-md p-2 dark:text-white dark:bg-primary-600 dark:hover:bg-primary-700 cursor-pointer" %>

<button
type="button"
class="
focus:outline-none text-sm text-slate-900 border border-slate-200 bg-white
hover:bg-slate-100 hover:text-slate-950 focus:ring-0 rounded-md p-2
dark:text-white dark:bg-slate-600 dark:hover:bg-slate-700
"
data-action="click->viral--dialog#close"
>
<%= t("projects.workflow_executions.edit_dialog.cancel_button") %>
</button>
</div>
<% end %>
<% end %>
<% end %>
5 changes: 4 additions & 1 deletion app/views/projects/workflow_executions/_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
<% unless @workflow_execution.name.blank? %>
<div class="flex flex-col pb-3">
<dt class="mb-1 text-slate-500 md:text-lg dark:text-slate-400"><%= t(:".name") %></dt>
<dd class="text-lg font-semibold text-slate-900 dark:text-white"><%= @workflow_execution.name %></dd>
<dd class="text-lg font-semibold text-slate-900 dark:text-white">
<%= turbo_frame_tag('we_name') do %>
<%= @workflow_execution.name %></dd>
<% end %>
</div>
<% end %>
<div class="flex flex-col py-3">
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/workflow_executions/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace: namespace,
search_params: @search_params,
abilities: {
select_workflow_executions: allowed_to?(:export_data?, namespace)
select_workflow_executions: allowed_to?(:export_data?, namespace),
},
row_actions: {
cancel: allowed_to?(:update?, namespace),
Expand Down
6 changes: 6 additions & 0 deletions app/views/projects/workflow_executions/edit.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= turbo_stream.update "edit_dialog",
partial: "edit_dialog",
locals: {
open: true,
workflow_execution: @workflow_execution,
} %>
21 changes: 18 additions & 3 deletions app/views/projects/workflow_executions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<%= turbo_frame_tag "export_dialog" %>

<%= turbo_frame_tag "edit_dialog" %>

<%= render Viral::PageHeaderComponent.new(title: @workflow_execution.id, id: t("workflow_executions.state.#{@workflow_execution.state}"), id_color: find_pill_color_for_state(@workflow_execution.state)) do |component| %>
<%= component.with_icon(name: "beaker", classes: "h-14 w-14 text-primary-700") %>
<%= component.with_buttons do %>
Expand All @@ -16,7 +18,7 @@
analysis_type: "project",
namespace_id: @namespace.id,
workflow_execution_id: @workflow_execution.id,
single_workflow: true
single_workflow: true,
),
data: {
turbo_stream: true,
Expand All @@ -29,7 +31,7 @@
analysis_type: "project",
namespace_id: @namespace.id,
workflow_execution_id: @workflow_execution.id,
single_workflow: true
single_workflow: true,
),
data: {
turbo_stream: true,
Expand All @@ -38,7 +40,6 @@
"button button--size-default button--state-default pointer-events-none cursor-not-allowed bg-slate-100 text-slate-600 mr-2 dark:bg-slate-600 dark:text-slate-300" %>
<% end %>
<% end %>

<% if @workflow_execution.cancellable? && allowed_to?(:cancel?, @workflow_execution) %>
<%= link_to(
t("projects.workflow_executions.show.cancel_button"),
Expand All @@ -55,6 +56,20 @@
class: "button button--state-default button--size-default mr-1",
) %>
<% end %>
<% if allowed_to?(:update?, @workflow_execution) %>
<%= link_to(
t("projects.workflow_executions.show.edit_button"),
edit_namespace_project_workflow_execution_path(
@namespace.parent,
@namespace.project,
@workflow_execution,
),
data: {
turbo_stream: true,
},
class: "button button--state-default button--size-default mr-1",
) %>
<% end %>
<% if @workflow_execution.deletable? && allowed_to?(:destroy?, @workflow_execution) %>
<%= link_to(
t("projects.workflow_executions.show.remove_button"),
Expand Down
21 changes: 21 additions & 0 deletions app/views/projects/workflow_executions/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<% unless @workflow_execution.errors.any? %>
<%= turbo_stream.append "flashes" do %>
<%= viral_flash(type:, data: message) %>
<% end %>
<% end %>

<% if @updated %>
<%= turbo_stream.update "edit_dialog",
partial: "edit_dialog",
locals: {
open: @workflow_execution.errors.any?,
workflow_execution: @workflow_execution,
} %>

<%= turbo_stream.update "we_name" do %>
<%= @workflow_execution.name %>
<% end %>
<% else %>
<%= turbo_stream.update "edit_workflow_execution_error_alert",
viral_alert(type:, message:, classes: "mb-4") %>
<% end %>
48 changes: 48 additions & 0 deletions app/views/workflow_executions/_edit_dialog.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%= viral_dialog(open: open,classes: ["overflow-visible"]) do |dialog| %>
<%= dialog.with_header(title: t("workflow_executions.edit_dialog.title")) %>
<%= dialog.with_section do %>

<div class="mb-6 text-lg font-normal text-slate-500 dark:text-slate-400">
<p class="dark:text-slate-400">
<%= t(
"workflow_executions.edit_dialog.description",
workflow_execution_id: @workflow_execution.id,
) %>
</p>
</div>

<div class="mb-4">
<%= turbo_frame_tag("edit_workflow_execution_error_alert") %>
</div>

<%= form_with(model: workflow_execution, url: workflow_execution_path, method: :patch, class: "grid gap-4") do |form| %>
<div class="form-field">
<%= form.label :name %>
<%= form.text_field :name,
autofocus: true,
value: @workflow_execution.name,
placeholder:
t("workflow_executions.edit_dialog.name_placeholder") %>

</div>

<div class="mt-4">
<%= form.submit t("workflow_executions.edit_dialog.submit_button"),
class:
"focus:outline-none text-sm text-white bg-primary-700 hover:bg-primary-800 focus:ring-0 rounded-md p-2 dark:text-white dark:bg-primary-600 dark:hover:bg-primary-700 cursor-pointer" %>

<button
type="button"
class="
focus:outline-none text-sm text-slate-900 border border-slate-200 bg-white
hover:bg-slate-100 hover:text-slate-950 focus:ring-0 rounded-md p-2
dark:text-white dark:bg-slate-600 dark:hover:bg-slate-700
"
data-action="click->viral--dialog#close"
>
<%= t("workflow_executions.edit_dialog.cancel_button") %>
</button>
</div>
<% end %>
<% end %>
<% end %>
6 changes: 5 additions & 1 deletion app/views/workflow_executions/_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
<% unless @workflow_execution.name.blank? %>
<div class="flex flex-col pb-3">
<dt class="mb-1 text-slate-500 md:text-lg dark:text-slate-400"><%= t(:".name") %></dt>
<dd class="text-lg font-semibold text-slate-900 dark:text-white"><%= @workflow_execution.name %></dd>
<dd class="text-lg font-semibold text-slate-900 dark:text-white">
<%= turbo_frame_tag('we_name') do %>
<%= @workflow_execution.name %>
<% end %>
</dd>
</div>
<% end %>
<div class="flex flex-col py-3">
Expand Down
2 changes: 1 addition & 1 deletion app/views/workflow_executions/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
q,
search_params: @search_params,
abilities: {
select_workflow_executions: true
select_workflow_executions: true,
},
row_actions: {
cancel: true,
Expand Down
6 changes: 6 additions & 0 deletions app/views/workflow_executions/edit.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= turbo_stream.update "edit_dialog",
partial: "edit_dialog",
locals: {
open: true,
workflow_execution: @workflow_execution,
} %>
15 changes: 14 additions & 1 deletion app/views/workflow_executions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

<%= turbo_frame_tag "export_dialog" %>

<%= render Viral::PageHeaderComponent.new(title: @workflow_execution.name.blank? ? @workflow_execution.metadata["workflow_name"] : @workflow_execution.name, id: @workflow_execution.id, id_color: find_pill_color_for_state(@workflow_execution.state)) do |component| %>
<%= turbo_frame_tag "edit_dialog" %>

<%= render Viral::PageHeaderComponent.new(title: @workflow_execution.name.blank? ? @workflow_execution.metadata["workflow_name"] :
turbo_frame_tag('we_name_header') do @workflow_execution.name end, id: @workflow_execution.id, id_color: find_pill_color_for_state(@workflow_execution.state)) do |component| %>
<%= component.with_icon(name: "beaker", classes: "h-14 w-14 text-primary-700") %>
<%= component.with_buttons do %>
<div class="flex flex-row">
Expand Down Expand Up @@ -45,6 +48,16 @@
class: "button button--state-default button--size-default mr-1"
) %>
<% end %>
<% if allowed_to?(:update?, @workflow_execution) %>
<%= link_to(
t("workflow_executions.show.edit_button"),
edit_workflow_execution_path(id: @workflow_execution.id),
data: {
turbo_stream: true
},
class: "button button--state-default button--size-default mr-1"
) %>
<% end %>
<% if @workflow_execution.deletable? %>
<%= link_to(
t("workflow_executions.show.remove_button"),
Expand Down
25 changes: 25 additions & 0 deletions app/views/workflow_executions/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<% unless @workflow_execution.errors.any? %>
<%= turbo_stream.append "flashes" do %>
<%= viral_flash(type:, data: message) %>
<% end %>
<% end %>

<% if @updated %>
<%= turbo_stream.update "edit_dialog",
partial: "edit_dialog",
locals: {
open: @workflow_execution.errors.any?,
workflow_execution: @workflow_execution,
} %>

<%= turbo_stream.update "we_name" do %>
<%= @workflow_execution.name %>
<% end %>

<%= turbo_stream.update "we_name_header" do %>
<%= @workflow_execution.name %>
<% end %>
<% else %>
<%= turbo_stream.update "edit_workflow_execution_error_alert",
viral_alert(type:, message:, classes: "mb-4") %>
<% end %>
Loading

0 comments on commit 32ced55

Please sign in to comment.