Skip to content

Commit cc00542

Browse files
committed
Include workflow chat ai sessions and fix layout
1 parent bd31989 commit cc00542

File tree

4 files changed

+53
-26
lines changed

4 files changed

+53
-26
lines changed

lib/lightning/projects.ex

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,27 @@ defmodule Lightning.Projects do
9797
end
9898

9999
defp projects_overview_query(user_id) do
100-
chat_session_exists_query =
100+
job_code_sessions_query =
101101
from cs in ChatSession,
102102
join: j in Job,
103103
on: cs.job_id == j.id,
104104
join: w in Workflow,
105105
on: j.workflow_id == w.id,
106106
where:
107-
cs.user_id == ^user_id and w.project_id == parent_as(:project).id and
107+
cs.user_id == ^user_id and
108+
w.project_id == parent_as(:project).id and
109+
cs.session_type == "job_code" and
108110
is_nil(w.deleted_at),
109111
select: 1
110112

113+
workflow_template_sessions_query =
114+
from cs in ChatSession,
115+
where:
116+
cs.user_id == ^user_id and
117+
cs.project_id == parent_as(:project).id and
118+
cs.session_type == "workflow_template",
119+
select: 1
120+
111121
from(p in Project,
112122
as: :project,
113123
left_join: w in assoc(p, :workflows),
@@ -122,7 +132,9 @@ defmodule Lightning.Projects do
122132
workflows_count: count(w.id, :distinct),
123133
collaborators_count: count(pu_all.user_id, :distinct),
124134
last_updated_at: max(w.updated_at),
125-
has_ai_chat: exists(chat_session_exists_query)
135+
has_ai_chat:
136+
exists(job_code_sessions_query) or
137+
exists(workflow_template_sessions_query)
126138
}
127139
)
128140
end

lib/lightning/workflows.ex

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,22 @@ defmodule Lightning.Workflows do
349349
end
350350

351351
def get_workflows_for(%Project{id: project_id}, %User{id: user_id}, opts) do
352-
chat_session_exists_query =
352+
job_code_sessions_query =
353353
from cs in ChatSession,
354354
join: j in Job,
355355
on: cs.job_id == j.id,
356-
join: w in Workflow,
357-
on: j.workflow_id == w.id,
358-
where: cs.user_id == ^user_id,
359-
where: w.project_id == ^project_id and is_nil(w.deleted_at),
356+
where:
357+
cs.user_id == ^user_id and
358+
cs.session_type == "job_code" and
359+
j.workflow_id == parent_as(:workflow).id,
360+
select: 1
361+
362+
workflow_template_sessions_query =
363+
from cs in ChatSession,
364+
where:
365+
cs.user_id == ^user_id and
366+
cs.session_type == "workflow_template" and
367+
cs.workflow_id == parent_as(:workflow).id,
360368
select: 1
361369

362370
include = Keyword.get(opts, :include, [:triggers])
@@ -366,7 +374,12 @@ defmodule Lightning.Workflows do
366374
from(w in Workflow,
367375
as: :workflow,
368376
where: w.project_id == ^project_id and is_nil(w.deleted_at),
369-
select: %{w | has_ai_chat: exists(chat_session_exists_query)},
377+
select: %{
378+
w
379+
| has_ai_chat:
380+
exists(job_code_sessions_query) or
381+
exists(workflow_template_sessions_query)
382+
},
370383
preload: ^include
371384
)
372385

lib/lightning_web/live/dashboard_live/components.ex

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ defmodule LightningWeb.DashboardLive.Components do
7979
</div>
8080
</div>
8181
<div>
82-
<.table id="projects-table">
82+
<.table id="projects-table" class="table-fixed">
8383
<:header>
8484
<.tr>
8585
<.th
@@ -113,22 +113,23 @@ defmodule LightningWeb.DashboardLive.Components do
113113
class="hover:bg-gray-100 transition-colors duration-200"
114114
onclick={JS.navigate(~p"/projects/#{project.id}/w")}
115115
>
116-
<% dbg(project) %>
117116
<.td>
118-
<.icon
119-
:if={project.has_ai_chat}
120-
name="hero-sparkles"
121-
class="size-4"
122-
/>
123-
{project.name}
117+
<div class="flex items-center gap-1 max-w-[15rem]">
118+
<span class="truncate">{project.name}</span>
119+
<.icon
120+
:if={project.has_ai_chat}
121+
name="hero-sparkles"
122+
class="size-4 flex-shrink-0"
123+
/>
124+
</div>
124125
</.td>
125-
<.td class="break-words max-w-[25rem]">
126+
<.td>
126127
{String.capitalize(to_string(project.role))}
127128
</.td>
128-
<.td class="break-words max-w-[10rem]">
129+
<.td>
129130
{project.workflows_count}
130131
</.td>
131-
<.td class="break-words max-w-[5rem]">
132+
<.td>
132133
<.link
133134
class="link"
134135
href={~p"/projects/#{project.id}/settings#collaboration"}

lib/lightning_web/live/workflow_live/dashboard_components.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,15 @@ defmodule LightningWeb.WorkflowLive.DashboardComponents do
318318
tooltip={@workflow.name}
319319
>
320320
<div class="text-sm">
321-
<div class="flex items-center">
322-
<span
323-
class="flex-shrink truncate text-gray-900 font-medium workflow-name"
324-
style="max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
325-
>
326-
<.icon :if={@workflow.has_ai_chat} name="hero-sparkles" class="size-4" />
321+
<div class="flex items-center gap-1 max-w-[15rem]">
322+
<span class="truncate text-gray-900 font-medium workflow-name">
327323
{@workflow.name}
328324
</span>
325+
<.icon
326+
:if={@workflow.has_ai_chat}
327+
name="hero-sparkles"
328+
class="size-4 flex-shrink-0"
329+
/>
329330
</div>
330331
<%= if @trigger_enabled do %>
331332
<p class="text-gray-500 text-xs mt-1">

0 commit comments

Comments
 (0)