Skip to content

Commit

Permalink
feat: dev deploy log 2 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsavy committed Dec 15, 2022
1 parent ece2007 commit c178159
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 31 deletions.
50 changes: 50 additions & 0 deletions src/hooks/useDeployLogInfos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useEffect, useState } from 'react'
import { useTdpClient } from 'src/contexts'

import type { DeploymentLogWithOperations } from '@/client-sdk'

// type ApiConfigType = {
// type DeployHeaderType = {
// id: number
// state: string
// }

// export type deploymentType = {
// id: number
// start_time: string
// end_time: string
// state: string
// operations: string[]
// }

export function useDeployLogInfos(
deployLogId: number
): DeploymentLogWithOperations {
const { deployApi } = useTdpClient()

const [deploymentLog, setDeploymentLog] =
useState<DeploymentLogWithOperations>(null)
// const [pastDeploymentsList, setPastDeploymentsList] = useState<{id: number; start_time:string; end_time: string; state: string; operations?: string[] }[]>([])

useEffect(() => {
// async function fetchServicesList() {
async function fetchDeployInfos() {
// const res = await servicesApi.getServicesApiV1ServiceGet()
const res = await deployApi.getDeploymentApiV1DeployDeploymentIdGet(
deployLogId
)
// setServicesList(res.data.map((service) => service.id))
// setPastDeploymentsList(res.data.map((deployment) => deployment.id))
setDeploymentLog(res.data)
// OK mais pas utile ici : setPastDeploymentsList(res.data.map(d =>({id:d['id'],start_time:d["start_time"],end_time:d["end_time"],state:d["state"],operations:d["operations"]})))
// setPastDeploymentsList([{id:1,start_time:'toto',end_time:'titi',state:'Ok'},{id:1,start_time:'toto',end_time:'titi',state:'Ok'}])
// setPastDeploymentsList([{id:1,start_time:'toto',end_time:'titi',state:'Ok'},{id:1,start_time:'toto',end_time:'titi',state:'Ok'}])
}
// fetchServicesList()
deployLogId && fetchDeployInfos()
// }, [servicesApi])
}, [deployApi, deployLogId])

// return servicesList
return deploymentLog
}
8 changes: 4 additions & 4 deletions src/hooks/usePastDeploymentsList.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import { useTdpClient } from 'src/contexts'

import type { Deployment } from '@/client-sdk'
import type { DeploymentLog } from '@/client-sdk'

// type ApiConfigType = {
// type DeployHeaderType = {
Expand All @@ -23,9 +23,9 @@ export function usePastDeploymentsList() {

const [servicesList, setServicesList] = useState([])
// const [pastDeploymentsList, setPastDeploymentsList] = useState([])
const [pastDeploymentsList, setPastDeploymentsList] = useState<Deployment[]>(
[]
)
const [pastDeploymentsList, setPastDeploymentsList] = useState<
DeploymentLog[]
>([])

useEffect(() => {
// async function fetchServicesList() {
Expand Down
19 changes: 9 additions & 10 deletions src/pages/deploy/logs/[deployLogId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { useRouter } from 'next/router'
import { ReactElement } from 'react'
import DashboardLayout from 'src/app/dashboard/layout'
import ServiceLayout from 'src/app/services/layout'
import { VariablesDisplay } from 'src/components'
import { useServiceInfos } from 'src/hooks'
import { useDeployLogInfos } from 'src/hooks'

// const ServicePage = () => {
const DeployLogPage = () => {
Expand All @@ -18,17 +17,17 @@ const DeployLogPage = () => {
: tempDeployLogId
// const { initialInfos, setNewVariables, sendVariables } =
// useServiceInfos(serviceId)
const { initialInfos, setNewVariables, sendVariables } =
useServiceInfos(deployLogId)
const deployLogInfos = useDeployLogInfos(Number(deployLogId))

if (!initialInfos) return <p>Loading</p>
// if (!deployLogInfos) return <p>Loading</p>

return (
<VariablesDisplay
initialVariables={initialInfos.variables}
setNewVariables={setNewVariables}
sendVariables={sendVariables}
/>
<>
<div>
deployLogId : {deployLogId}
{/* {JSON.stringify(deployLogInfos)} */}
</div>
</>
)
}

Expand Down
21 changes: 4 additions & 17 deletions src/pages/deploy/logs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import { ReactElement, useReducer } from 'react'
import DashboardLayout from 'src/app/dashboard/layout'
import {
Button,
FilterField,
DeployTypeField,
RestartField,
OperationsField,
} from 'src/components'
import { Button } from 'src/components'
import { useDeploy } from 'src/hooks'
import { usePastDeploymentsList, usePastDeploymentsRichList } from 'src/hooks'
import { DeployRequest, FilterTypeEnum } from '@/client-sdk'
import {
DeployMethodsEnum,
DeployMethodsType,
DeployStateType,
TfilterType,
} from 'src/types/deployTypes'
import { deployReducer } from 'src/utils/deployReducer'
import { DeployContext } from 'src/contexts/deployContext'
import { DeployMethodsEnum, DeployStateType } from 'src/types/deployTypes'
import { PastDeployLogs } from 'src/components/DeployLogs/TableDeployLogs'

import { ListPastDeployLogs } from 'src/components/DeployLogs/'

import type { Deployment } from '@/client-sdk'
import type { DeploymentLog } from '@/client-sdk'
import type { deploymentType } from 'src/hooks/usePastDeploymentsList'
import Operation from 'src/app/deploy/Operation'
import Link from 'next/link'
Expand Down Expand Up @@ -154,7 +141,7 @@ const PastDeployLogsPage = () => {
start deploy, end deploy and state. Click on a deployment to
view it
</p>
<p>{JSON.stringify(pastDeploymentsList)}</p>
<p>{JSON.stringify(pastDeploymentsRichList)}</p>
<p>
{pastDeploymentsRichList.map(
(d) =>
Expand Down

0 comments on commit c178159

Please sign in to comment.