diff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx deleted file mode 100644 index f631d52c94b..00000000000 --- a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx +++ /dev/null @@ -1,141 +0,0 @@ -import { useState } from 'react' - -import AlertError from 'components/ui/AlertError' -import { useWorkflowRunLogsQuery } from 'data/workflow-runs/workflow-run-logs-query' -import { useWorkflowRunsQuery } from 'data/workflow-runs/workflow-runs-query' -import dayjs from 'dayjs' -import { ArrowLeft, ArrowRight } from 'lucide-react' -import { - Button, - cn, - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogSection, - DialogSectionSeparator, - DialogTitle, - DialogTrigger, -} from 'ui' -import { GenericSkeletonLoader } from 'ui-patterns' -import BranchStatusBadge from './BranchStatusBadge' - -interface WorkflowLogsProps { - projectRef: string -} - -const WorkflowLogs = ({ projectRef }: WorkflowLogsProps) => { - const [isOpen, setIsOpen] = useState(false) - - const { - data: workflowRuns, - isSuccess: isWorkflowRunsSuccess, - isLoading: isWorkflowRunsLoading, - isError: isWorkflowRunsError, - error: workflowRunsError, - } = useWorkflowRunsQuery( - { - projectRef, - }, - { - enabled: isOpen, - } - ) - - const [selectedWorkflowRunId, setSelectedWorkflowRunId] = useState(undefined) - - const { - data: workflowRunLogs, - isSuccess: isWorkflowRunLogsSuccess, - isLoading: isWorkflowRunLogsLoading, - isError: isWorkflowRunLogsError, - error: workflowRunLogsError, - } = useWorkflowRunLogsQuery( - { - workflowRunId: selectedWorkflowRunId, - }, - { - enabled: isOpen && selectedWorkflowRunId !== undefined, - } - ) - - return ( - - - - - - - - Workflow Logs - - Select a workflow run to view logs - - - - - - {selectedWorkflowRunId === undefined ? ( - <> - {isWorkflowRunsLoading && } - {isWorkflowRunsError && } - {isWorkflowRunsSuccess && - (workflowRuns.length > 0 ? ( -
    - {workflowRuns.map((workflowRun) => ( -
  • - -
  • - ))} -
- ) : ( -

- No workflow runs found. -

- ))} - - ) : ( -
- - - {isWorkflowRunLogsLoading && } - {isWorkflowRunLogsError && ( - - )} - {isWorkflowRunLogsSuccess && ( -
-                  {workflowRunLogs}
-                
- )} -
- )} -
-
-
- ) -} - -export default WorkflowLogs diff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsContent.tsx b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsContent.tsx new file mode 100644 index 00000000000..e2863226f70 --- /dev/null +++ b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsContent.tsx @@ -0,0 +1,103 @@ +import AlertError from "components/ui/AlertError" +import { Button, cn } from "ui" +import { GenericSkeletonLoader } from "ui-patterns" +import BranchStatusBadge from "../BranchStatusBadge" +import { ArrowLeft, ArrowRight } from "lucide-react" +import dayjs from "dayjs" +import { UseWorkflowLogsType } from "./useWorkflowLogs" + +interface WorkflowLogsContentProps { + workflowRuns: UseWorkflowLogsType['workflowRuns'] + isWorkflowRunsSuccess: boolean + isWorkflowRunsLoading: boolean + isWorkflowRunsError: boolean + workflowRunsError: UseWorkflowLogsType['workflowRunsError'] + workflowRunLogs: string | undefined + isWorkflowRunLogsSuccess: boolean + isWorkflowRunLogsLoading: boolean + isWorkflowRunLogsError: boolean + workflowRunLogsError: UseWorkflowLogsType['workflowRunLogsError'] + selectedWorkflowRunId: string | undefined + onSelectWorkflowRun: (id: string | undefined) => void + onBack: () => void + maxHeight?: boolean + } + + export const WorkflowLogsContent = ({ + workflowRuns = [], + isWorkflowRunsSuccess, + isWorkflowRunsLoading, + isWorkflowRunsError, + workflowRunsError, + workflowRunLogs = '', + isWorkflowRunLogsSuccess, + isWorkflowRunLogsLoading, + isWorkflowRunLogsError, + workflowRunLogsError, + selectedWorkflowRunId, + onSelectWorkflowRun, + onBack, + maxHeight + }: WorkflowLogsContentProps) => { + return ( +
+ {selectedWorkflowRunId === undefined ? ( + <> + {isWorkflowRunsLoading && } + {isWorkflowRunsError && } + {isWorkflowRunsSuccess && + (workflowRuns.length > 0 ? ( +
    + {workflowRuns.map((workflowRun) => ( +
  • + +
  • + ))} +
+ ) : ( +

+ No workflow runs found. +

+ ))} + + ) : ( +
+ + + {isWorkflowRunLogsLoading && } + {isWorkflowRunLogsError && ( + + )} + {isWorkflowRunLogsSuccess && ( +
+                {workflowRunLogs}
+              
+ )} +
+ )} +
+ ) + } \ No newline at end of file diff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsDialog.tsx b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsDialog.tsx new file mode 100644 index 00000000000..59ab53f2305 --- /dev/null +++ b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsDialog.tsx @@ -0,0 +1,51 @@ +import { useState } from 'react' + +import { + Button, + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogSection, + DialogSectionSeparator, + DialogTitle, + DialogTrigger, +} from 'ui' +import { useWorkflowLogs } from "./useWorkflowLogs" +import { WorkflowLogsContent } from "./WorkflowLogsContent" + +interface WorkflowLogsDialogProps { + projectRef: string +} + + +export const WorkflowLogsDialog = ({ projectRef }: WorkflowLogsDialogProps) => { + const [isOpen, setIsOpen] = useState(false) + const workflowLogs = useWorkflowLogs(projectRef, isOpen) + + return ( + + + + + + + + Workflow Logs + Select a workflow run to view logs + + + + + + workflowLogs.setSelectedWorkflowRunId(undefined)} + /> + + + + ) + } \ No newline at end of file diff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsPage.tsx b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsPage.tsx new file mode 100644 index 00000000000..db3036f9464 --- /dev/null +++ b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/WorkflowLogsPage.tsx @@ -0,0 +1,29 @@ +import { useRouter } from "next/router" +import { useWorkflowLogs } from "./useWorkflowLogs" +import { WorkflowLogsContent } from "./WorkflowLogsContent" + +interface WorkflowLogsPageProps { + projectRef: string + workflowRunId?: string +} + + +export const WorkflowLogsPage = ({ projectRef, workflowRunId }: WorkflowLogsPageProps) => { + const router = useRouter() + const workflowLogs = useWorkflowLogs(projectRef, true, workflowRunId) + + return ( +
+
+

Workflow Logs

+

Select a workflow run to view its execution logs

+
+
+ router.push(`/project/${projectRef}/branches/logs/workflow/${id}`)} + onBack={() => router.push(`/project/${projectRef}/branches/logs/workflow`)} + /> +
+ ) + } \ No newline at end of file diff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/index.tsx b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/index.tsx new file mode 100644 index 00000000000..9087aa362e8 --- /dev/null +++ b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/index.tsx @@ -0,0 +1,7 @@ + +import { WorkflowLogsDialog } from './WorkflowLogsDialog'; +import { WorkflowLogsPage } from './WorkflowLogsPage'; + +export { WorkflowLogsPage }; + +export default WorkflowLogsDialog diff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/useWorkflowLogs.ts b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/useWorkflowLogs.ts new file mode 100644 index 00000000000..03b8f9fb64a --- /dev/null +++ b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs/useWorkflowLogs.ts @@ -0,0 +1,54 @@ +import { useState } from 'react' +import { useWorkflowRunLogsQuery } from 'data/workflow-runs/workflow-run-logs-query' +import { useWorkflowRunsQuery } from 'data/workflow-runs/workflow-runs-query' + +export const useWorkflowLogs = (projectRef: string, isOpen: boolean, workflowRunId?: string) => { + const [selectedWorkflowRunId, setSelectedWorkflowRunId] = useState(workflowRunId) + + const { + data: workflowRuns, + isSuccess: isWorkflowRunsSuccess, + isLoading: isWorkflowRunsLoading, + isError: isWorkflowRunsError, + error: workflowRunsError, + } = useWorkflowRunsQuery( + { + projectRef, + }, + { + enabled: isOpen, + } + ) + + const { + data: workflowRunLogs, + isSuccess: isWorkflowRunLogsSuccess, + isLoading: isWorkflowRunLogsLoading, + isError: isWorkflowRunLogsError, + error: workflowRunLogsError, + } = useWorkflowRunLogsQuery( + { + workflowRunId: selectedWorkflowRunId, + }, + { + enabled: isOpen && selectedWorkflowRunId !== undefined, + } + ) + + return { + workflowRuns, + isWorkflowRunsSuccess, + isWorkflowRunsLoading, + isWorkflowRunsError, + workflowRunsError, + workflowRunLogs, + isWorkflowRunLogsSuccess, + isWorkflowRunLogsLoading, + isWorkflowRunLogsError, + workflowRunLogsError, + selectedWorkflowRunId, + setSelectedWorkflowRunId, + } +} + +export type UseWorkflowLogsType = ReturnType \ No newline at end of file diff --git a/apps/studio/pages/project/[ref]/branches.tsx b/apps/studio/pages/project/[ref]/branches/index.tsx similarity index 100% rename from apps/studio/pages/project/[ref]/branches.tsx rename to apps/studio/pages/project/[ref]/branches/index.tsx diff --git a/apps/studio/pages/project/[ref]/branches/logs/workflow/[workflow_run_id]/index.tsx b/apps/studio/pages/project/[ref]/branches/logs/workflow/[workflow_run_id]/index.tsx new file mode 100644 index 00000000000..d1606941d49 --- /dev/null +++ b/apps/studio/pages/project/[ref]/branches/logs/workflow/[workflow_run_id]/index.tsx @@ -0,0 +1,18 @@ +import { useParams } from 'common' +import { WorkflowLogsPage } from 'components/interfaces/BranchManagement/WorkflowLogs' +import { ProjectLayoutWithAuth } from 'components/layouts/ProjectLayout/ProjectLayout' +import { useSelectedProject } from 'hooks/misc/useSelectedProject' +import type { NextPageWithLayout } from 'types' + +const WorkflowRunIdLogs: NextPageWithLayout = () => { + const project = useSelectedProject() + const { workflow_run_id } = useParams() + if (!project?.ref) { + return null + } + return +} + +WorkflowRunIdLogs.getLayout = (page) => {page} + +export default WorkflowRunIdLogs diff --git a/apps/studio/pages/project/[ref]/branches/logs/workflow/index.tsx b/apps/studio/pages/project/[ref]/branches/logs/workflow/index.tsx new file mode 100644 index 00000000000..1171087ce9d --- /dev/null +++ b/apps/studio/pages/project/[ref]/branches/logs/workflow/index.tsx @@ -0,0 +1,16 @@ +import { useParams } from 'common' +import { WorkflowLogsPage } from 'components/interfaces/BranchManagement/WorkflowLogs' +import { ProjectLayoutWithAuth } from 'components/layouts/ProjectLayout/ProjectLayout' +import type { NextPageWithLayout } from 'types' + +const WorkflowRunLogs: NextPageWithLayout = () => { + const { ref } = useParams() + if (!ref) { + return null + } + return +} + +WorkflowRunLogs.getLayout = (page) => {page} + +export default WorkflowRunLogs