-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOP-20067] run list and run detail (#41)
* [DOP-20067] run list and run detail * [DOP-20067] move RunStatus enum from types to constants --------- Co-authored-by: Zabilsya <[email protected]>
- Loading branch information
Showing
44 changed files
with
439 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export enum RunStatus { | ||
CREATED = 'CREATED', | ||
STARTED = 'STARTED', | ||
FAILED = 'FAILED', | ||
SEND_STOP_SIGNAL = 'SEND STOP SIGNAL', | ||
STOPPED = 'STOPPED', | ||
FINISHED = 'FINISHED', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useGetRun'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useSuspenseQuery, UseSuspenseQueryResult } from '@tanstack/react-query'; | ||
|
||
import { GetRunRequest, Run } from '../../types'; | ||
import { RunQueryKey } from '../../keys'; | ||
import { runService } from '../../runService'; | ||
|
||
/** Hook for getting run info from backend */ | ||
export const useGetRun = ({ id }: GetRunRequest): UseSuspenseQueryResult<Run> => { | ||
return useSuspenseQuery({ | ||
queryKey: [RunQueryKey.GET_RUN, id], | ||
queryFn: () => runService.getRun({ id }), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './runService'; | ||
export * from './types'; | ||
export * from './keys'; | ||
export * from './hooks'; | ||
export * from './constants'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const RunQueryKey = { | ||
GET_RUNS: 'GET_RUNS', | ||
GET_RUN: 'GET_RUN', | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { axiosInstance } from '@shared/config'; | ||
import { PaginationResponse } from '@shared/types'; | ||
|
||
import { GetRunRequest, Run, GetRunsRequest } from './types'; | ||
|
||
export const runService = { | ||
getRuns: (params: GetRunsRequest): Promise<PaginationResponse<Run>> => { | ||
return axiosInstance.get('runs', { params }); | ||
}, | ||
|
||
getRun: ({ id }: GetRunRequest): Promise<Run> => { | ||
return axiosInstance.get(`runs/${id}`); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { PaginationRequest } from '@shared/types'; | ||
|
||
import { RunStatus } from './constants'; | ||
|
||
export interface Run { | ||
id: number; | ||
transfer_id: number; | ||
started_at: string | null; | ||
ended_at: string | null; | ||
status: keyof typeof RunStatus; | ||
log_url: string | null; | ||
} | ||
|
||
export interface GetRunsRequest extends PaginationRequest { | ||
transfer_id: number; | ||
} | ||
|
||
export interface GetRunRequest { | ||
id: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './api'; | ||
export * from './ui'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React, { memo } from 'react'; | ||
import { Badge } from 'antd'; | ||
import { RunStatus } from '@entities/run'; | ||
|
||
import { RunStatusBadgeProps } from './types'; | ||
import { getRunStatusColor } from './utils'; | ||
|
||
export const RunStatusBadge = memo(({ status }: RunStatusBadgeProps) => { | ||
const statusText = RunStatus[status]; | ||
return <Badge count={statusText} status={getRunStatusColor(statusText)} />; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { RunStatus } from '../../api'; | ||
|
||
export interface RunStatusBadgeProps { | ||
status: keyof typeof RunStatus; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/entities/run/ui/RunStatusBadge/utils/getRunStatusColor/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { RunStatus } from '@entities/run'; | ||
import { BadgeProps } from 'antd'; | ||
|
||
/** Util for getting value of prop "status" for run status badge */ | ||
export const getRunStatusColor = (status: RunStatus): BadgeProps['status'] => { | ||
switch (status) { | ||
case RunStatus.CREATED: | ||
case RunStatus.STARTED: | ||
return 'default'; | ||
case RunStatus.FAILED: | ||
return 'error'; | ||
case RunStatus.SEND_STOP_SIGNAL: | ||
case RunStatus.STOPPED: | ||
return 'warning'; | ||
case RunStatus.FINISHED: | ||
return 'success'; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './getRunStatusColor'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './RunStatusBadge'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import { Descriptions } from 'antd'; | ||
import { Link } from 'react-router-dom'; | ||
import { RunStatusBadge } from '@entities/run'; | ||
import { Typography } from 'antd'; | ||
|
||
const { Text } = Typography; | ||
|
||
import { RunDetailInfoProps } from './types'; | ||
|
||
export const RunDetailInfo = ({ run, transfer, ...props }: RunDetailInfoProps) => { | ||
return ( | ||
<Descriptions title="Run info" bordered {...props}> | ||
<Descriptions.Item label="Id" span={3}> | ||
{run.id} | ||
</Descriptions.Item> | ||
<Descriptions.Item label="Status" span={3}> | ||
<RunStatusBadge status={run.status} /> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="Started at" span={3}> | ||
{/* //TODO: [DOP-20067] Rewrite on dayjs when "started_at" field will have not null value */} | ||
{run.started_at || ''} | ||
</Descriptions.Item> | ||
<Descriptions.Item label="Ended at" span={3}> | ||
{/* //TODO: [DOP-20067] Rewrite on dayjs when "ended_at" field will have not null value */} | ||
{run.ended_at || ''} | ||
</Descriptions.Item> | ||
<Descriptions.Item label="Log url" span={3}> | ||
{run.log_url ? ( | ||
<Text> | ||
<a href={run.log_url} target="_blank" rel="noreferrer"> | ||
{run.log_url} | ||
</a> | ||
</Text> | ||
) : ( | ||
'' | ||
)} | ||
</Descriptions.Item> | ||
<Descriptions.Item label="Transfer" span={3}> | ||
<Link to={`/transfers/${transfer.id}`}>{transfer.name}</Link> | ||
</Descriptions.Item> | ||
</Descriptions> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Run } from '@entities/run'; | ||
import { Transfer } from '@entities/transfer'; | ||
import { DescriptionsProps } from 'antd'; | ||
|
||
export interface RunDetailInfoProps extends DescriptionsProps { | ||
run: Run; | ||
transfer: Transfer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { PaginationResponse } from '@shared/types'; | ||
import { TableColumns } from '@shared/ui'; | ||
import { Run, RunStatusBadge } from '@entities/run'; | ||
import { Typography } from 'antd'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
const { Text } = Typography; | ||
|
||
export const RUN_LIST_COLUMNS: TableColumns<PaginationResponse<Run>> = [ | ||
{ | ||
title: 'Id', | ||
dataIndex: 'id', | ||
render: (id, record) => <Link to={`/transfers/runs/${record.id}`}>{id}</Link>, | ||
width: 150, | ||
}, | ||
{ | ||
title: 'Status', | ||
dataIndex: 'status', | ||
render: (value, record) => <RunStatusBadge status={record.status} />, | ||
width: 150, | ||
}, | ||
{ | ||
title: 'Started at', | ||
dataIndex: 'started_at', | ||
//TODO: [DOP-20067] Rewrite on dayjs when "started_at" field will have not null value | ||
width: 150, | ||
}, | ||
{ | ||
title: 'Ended at', | ||
dataIndex: 'ended_at', | ||
//TODO: [DOP-20067] Rewrite on dayjs when "ended_at" field will have not null value | ||
width: 150, | ||
}, | ||
{ | ||
title: 'Log url', | ||
dataIndex: 'log_url', | ||
render: (value, record) => | ||
record.log_url ? ( | ||
<Text> | ||
<a href={record.log_url} target="_blank" rel="noreferrer"> | ||
{record.log_url} | ||
</a> | ||
</Text> | ||
) : ( | ||
'' | ||
), | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { ManagedTable } from '@shared/ui'; | ||
import { PaginationRequest } from '@shared/types'; | ||
import { RunQueryKey, runService } from '@entities/run'; | ||
|
||
import { RUN_LIST_COLUMNS } from './constants'; | ||
import { RunListProps } from './types'; | ||
|
||
export const RunList = ({ transferId }: RunListProps) => { | ||
const handleGetRuns = (params: PaginationRequest) => { | ||
return runService.getRuns({ ...params, transfer_id: transferId }); | ||
}; | ||
|
||
return ( | ||
<ManagedTable | ||
queryKey={[RunQueryKey.GET_RUNS, transferId]} | ||
queryFunction={handleGetRuns} | ||
columns={RUN_LIST_COLUMNS} | ||
isHiddenRowActions | ||
rowKey="id" | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface RunListProps { | ||
transferId: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './RunList'; | ||
export * from './RunDetailInfo'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.