-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
993ba6a
commit 2b95202
Showing
11 changed files
with
224 additions
and
136 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
16 changes: 16 additions & 0 deletions
16
src/pages/pipeline-details/components/ReserveLogs/components/AllLogs/index.tsx
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,16 @@ | ||
import React from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { LogViewer } from '../../../../../../components/LogViewer'; | ||
import { PipelineRouteParams } from '../../../../types'; | ||
import { AllLogsProps } from './types'; | ||
|
||
export const AllLogs = ({ logs }: AllLogsProps) => { | ||
const { name } = useParams<PipelineRouteParams>(); | ||
|
||
return ( | ||
<LogViewer | ||
logs={logs.all} | ||
downloadName={`fallback-logs-${name}.log`} | ||
/> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
src/pages/pipeline-details/components/ReserveLogs/components/AllLogs/types.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,5 @@ | ||
import { NormalizedLogs } from '../../../../providers/DynamicData/types'; | ||
|
||
export interface AllLogsProps { | ||
logs: NormalizedLogs; | ||
} |
116 changes: 116 additions & 0 deletions
116
src/pages/pipeline-details/components/ReserveLogs/components/LogsByTask/index.tsx
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,116 @@ | ||
import { Accordion, Divider, Grid, Paper, Stack, Typography, useTheme } from '@mui/material'; | ||
import React from 'react'; | ||
import { useHistory, useLocation, useParams } from 'react-router-dom'; | ||
import { LogViewer } from '../../../../../../components/LogViewer'; | ||
import { StyledAccordionSummary } from '../../../../styles'; | ||
import { PipelineRouteParams } from '../../../../types'; | ||
import { StyledDetailsBody, StyledDetailsHeader } from '../../../Details/styles'; | ||
import { LogsByTaskProps } from './types'; | ||
|
||
export const LogsByTask = ({ logs }: LogsByTaskProps) => { | ||
const { name } = useParams<PipelineRouteParams>(); | ||
|
||
const location = useLocation(); | ||
const history = useHistory(); | ||
const queryParams = new URLSearchParams(location.search); | ||
|
||
const setQueryParams = React.useCallback( | ||
(taskRun: string) => { | ||
const queryParams = new URLSearchParams(); | ||
if (taskRun) { | ||
queryParams.set('taskRun', taskRun); | ||
} | ||
|
||
history.push({ search: queryParams.toString() }); | ||
}, | ||
[history] | ||
); | ||
|
||
const queryParamTaskRun = queryParams.get('taskRun'); | ||
|
||
const initialTaskRunName = logs.order[0]; | ||
|
||
const handleAccordionChange = (taskRun: string) => () => { | ||
setQueryParams(taskRun); | ||
}; | ||
|
||
React.useEffect(() => { | ||
if (!queryParamTaskRun) { | ||
setQueryParams(initialTaskRunName); | ||
} | ||
}, [initialTaskRunName, queryParamTaskRun, setQueryParams]); | ||
|
||
const theme = useTheme(); | ||
|
||
const renderDetails = React.useCallback(() => { | ||
if (!queryParamTaskRun) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Paper> | ||
<StyledDetailsHeader> | ||
<Stack spacing={1}> | ||
<Stack direction="row" alignItems="center" spacing={2}> | ||
<Typography fontSize={(t) => t.typography.pxToRem(20)} fontWeight={500}> | ||
{queryParamTaskRun} | ||
</Typography> | ||
</Stack> | ||
</Stack> | ||
</StyledDetailsHeader> | ||
<Divider orientation="horizontal" /> | ||
<StyledDetailsBody> | ||
<LogViewer | ||
logs={logs?.map?.[queryParamTaskRun] || []} | ||
downloadName={`fallback-logs-${name}-${queryParamTaskRun}.log`} | ||
/> | ||
</StyledDetailsBody> | ||
</Paper> | ||
); | ||
}, [logs?.map, name, queryParamTaskRun]); | ||
|
||
return ( | ||
<Grid container rowSpacing={3}> | ||
<Grid item xs={2}> | ||
<Stack> | ||
{logs && | ||
logs.order?.map((taskRunName) => { | ||
const isExpanded = queryParamTaskRun === taskRunName; | ||
const isActive = queryParamTaskRun === taskRunName; | ||
|
||
return ( | ||
<Accordion | ||
key={taskRunName} | ||
expanded={isExpanded} | ||
onChange={handleAccordionChange(taskRunName)} | ||
sx={{ | ||
borderLeft: isExpanded ? `2px solid ${theme.palette.primary.main}` : null, | ||
maxWidth: isExpanded ? '100%' : '90%', | ||
|
||
'&.Mui-expanded': { | ||
margin: 0, | ||
|
||
'&::before': { | ||
opacity: 1, | ||
}, | ||
}, | ||
}} | ||
> | ||
<StyledAccordionSummary | ||
isActive={isActive} | ||
disableRipple={false} | ||
disableTouchRipple={false} | ||
> | ||
<Typography>{taskRunName}</Typography> | ||
</StyledAccordionSummary> | ||
</Accordion> | ||
); | ||
})} | ||
</Stack> | ||
</Grid> | ||
<Grid item xs={10}> | ||
{renderDetails()} | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
src/pages/pipeline-details/components/ReserveLogs/components/LogsByTask/types.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,5 @@ | ||
import { NormalizedLogs } from '../../../../providers/DynamicData/types'; | ||
|
||
export interface LogsByTaskProps { | ||
logs: NormalizedLogs; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/pages/pipeline-details/components/ReserveLogs/hooks/useTabs.tsx
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,43 @@ | ||
import { Box } from '@mui/material'; | ||
import React from 'react'; | ||
import { LoadingWrapper } from '../../../../../components/LoadingWrapper'; | ||
import { useDynamicDataContext } from '../../../providers/DynamicData/hooks'; | ||
import { AllLogs } from '../components/AllLogs'; | ||
import { LogsByTask } from '../components/LogsByTask'; | ||
|
||
export const useTabs = () => { | ||
const { logs } = useDynamicDataContext(); | ||
|
||
return React.useMemo(() => { | ||
return [ | ||
{ | ||
label: 'All Logs', | ||
component: ( | ||
<Box | ||
sx={{ | ||
pt: (t) => t.typography.pxToRem(24), | ||
}} | ||
> | ||
<LoadingWrapper isLoading={logs.isLoading}> | ||
<AllLogs logs={logs.data} /> | ||
</LoadingWrapper> | ||
</Box> | ||
), | ||
}, | ||
{ | ||
label: 'Logs By Task', | ||
component: ( | ||
<Box | ||
sx={{ | ||
pt: (t) => t.typography.pxToRem(24), | ||
}} | ||
> | ||
<LoadingWrapper isLoading={logs.isLoading}> | ||
<LogsByTask logs={logs.data} /> | ||
</LoadingWrapper> | ||
</Box> | ||
), | ||
}, | ||
]; | ||
}, [logs.data, logs.isLoading]); | ||
}; |
119 changes: 7 additions & 112 deletions
119
src/pages/pipeline-details/components/ReserveLogs/index.tsx
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 |
---|---|---|
@@ -1,116 +1,11 @@ | ||
import { Accordion, Divider, Grid, Paper, Stack, Typography, useTheme } from '@mui/material'; | ||
import React from 'react'; | ||
import { useHistory, useLocation, useParams } from 'react-router-dom'; | ||
import { LogViewer } from '../../../../components/LogViewer'; | ||
import { StyledAccordionSummary } from '../../styles'; | ||
import { PipelineRouteParams } from '../../types'; | ||
import { StyledDetailsBody, StyledDetailsHeader } from '../Details/styles'; | ||
import { ReserveLogsProps } from './types'; | ||
import { Tabs } from '../../../../providers/Tabs/components/Tabs'; | ||
import { useTabsContext } from '../../../../providers/Tabs/hooks'; | ||
import { useTabs } from './hooks/useTabs'; | ||
|
||
export const ReserveLogs = ({ logs }: ReserveLogsProps) => { | ||
const { name } = useParams<PipelineRouteParams>(); | ||
export const ReserveLogs = () => { | ||
const tabs = useTabs(); | ||
const { handleChangeTab, activeTab } = useTabsContext(); | ||
|
||
const location = useLocation(); | ||
const history = useHistory(); | ||
const queryParams = new URLSearchParams(location.search); | ||
|
||
const setQueryParams = React.useCallback( | ||
(taskRun: string) => { | ||
const queryParams = new URLSearchParams(); | ||
if (taskRun) { | ||
queryParams.set('taskRun', taskRun); | ||
} | ||
|
||
history.push({ search: queryParams.toString() }); | ||
}, | ||
[history] | ||
); | ||
|
||
const queryParamTaskRun = queryParams.get('taskRun'); | ||
|
||
const initialTaskRunName = logs.order[0]; | ||
|
||
const handleAccordionChange = (taskRun: string) => () => { | ||
setQueryParams(taskRun); | ||
}; | ||
|
||
React.useEffect(() => { | ||
if (!queryParamTaskRun) { | ||
setQueryParams(initialTaskRunName); | ||
} | ||
}, [initialTaskRunName, queryParamTaskRun, setQueryParams]); | ||
|
||
const theme = useTheme(); | ||
|
||
const renderDetails = React.useCallback(() => { | ||
if (!queryParamTaskRun) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Paper> | ||
<StyledDetailsHeader> | ||
<Stack spacing={1}> | ||
<Stack direction="row" alignItems="center" spacing={2}> | ||
<Typography fontSize={(t) => t.typography.pxToRem(20)} fontWeight={500}> | ||
{queryParamTaskRun} | ||
</Typography> | ||
</Stack> | ||
</Stack> | ||
</StyledDetailsHeader> | ||
<Divider orientation="horizontal" /> | ||
<StyledDetailsBody> | ||
<LogViewer | ||
logs={logs?.map?.[queryParamTaskRun] || []} | ||
downloadName={`fallback-logs-${name}.log`} | ||
/> | ||
</StyledDetailsBody> | ||
</Paper> | ||
); | ||
}, [logs?.map, name, queryParamTaskRun]); | ||
|
||
return ( | ||
<Grid container rowSpacing={3}> | ||
<Grid item xs={2}> | ||
<Stack> | ||
{logs && | ||
logs.order?.map((taskRunName) => { | ||
const isExpanded = queryParamTaskRun === taskRunName; | ||
const isActive = queryParamTaskRun === taskRunName; | ||
|
||
return ( | ||
<Accordion | ||
key={taskRunName} | ||
expanded={isExpanded} | ||
onChange={handleAccordionChange(taskRunName)} | ||
sx={{ | ||
borderLeft: isExpanded ? `2px solid ${theme.palette.primary.main}` : null, | ||
maxWidth: isExpanded ? '100%' : '90%', | ||
|
||
'&.Mui-expanded': { | ||
margin: 0, | ||
|
||
'&::before': { | ||
opacity: 1, | ||
}, | ||
}, | ||
}} | ||
> | ||
<StyledAccordionSummary | ||
isActive={isActive} | ||
disableRipple={false} | ||
disableTouchRipple={false} | ||
> | ||
<Typography>{taskRunName}</Typography> | ||
</StyledAccordionSummary> | ||
</Accordion> | ||
); | ||
})} | ||
</Stack> | ||
</Grid> | ||
<Grid item xs={10}> | ||
{renderDetails()} | ||
</Grid> | ||
</Grid> | ||
); | ||
return <Tabs tabs={tabs} activeTabIdx={activeTab} handleChangeTab={handleChangeTab} />; | ||
}; |
This file was deleted.
Oops, something went wrong.
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.