-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Olga Nad <[email protected]>
- Loading branch information
1 parent
b60709d
commit 5a7ac73
Showing
4 changed files
with
159 additions
and
8 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
66 changes: 66 additions & 0 deletions
66
packages/zapp/console/src/components/common/MapTaskExecutionsList/TaskNameList.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,66 @@ | ||
import * as React from 'react'; | ||
import { Typography } from '@material-ui/core'; | ||
import { makeStyles, Theme } from '@material-ui/core/styles'; | ||
import { Core } from 'flyteidl'; | ||
import { | ||
getTaskLogName, | ||
getUniqueTaskExecutionName, | ||
} from 'components/Executions/TaskExecutionsList/utils'; | ||
import { MapTaskExecution, TaskExecution } from 'models/Execution/types'; | ||
import { noLogsFoundString } from 'components/Executions/constants'; | ||
import { useCommonStyles } from '../styles'; | ||
|
||
interface StyleProps { | ||
isLink: boolean; | ||
} | ||
|
||
const useStyles = makeStyles((_theme: Theme) => ({ | ||
taskTitle: ({ isLink }: StyleProps) => ({ | ||
cursor: isLink ? 'pointer' : 'default', | ||
'&:hover': { | ||
textDecoration: isLink ? 'underline' : 'none', | ||
}, | ||
}), | ||
})); | ||
|
||
interface TaskNameListProps { | ||
taskExecution: TaskExecution; | ||
logs: Core.ITaskLog[]; | ||
onTaskSelected: (val: MapTaskExecution) => void; | ||
} | ||
|
||
export const TaskNameList = ({ taskExecution, logs, onTaskSelected }: TaskNameListProps) => { | ||
const commonStyles = useCommonStyles(); | ||
|
||
if (logs.length === 0) { | ||
return <span className={commonStyles.hintText}>{noLogsFoundString}</span>; | ||
} | ||
|
||
const taskName = getUniqueTaskExecutionName(taskExecution); | ||
|
||
return ( | ||
<> | ||
{logs.map((log) => { | ||
const styles = useStyles({ isLink: !!log.uri }); | ||
const taskLogName = getTaskLogName(taskName, log.name ?? ''); | ||
|
||
const handleClick = () => { | ||
onTaskSelected({ ...taskExecution, taskName: taskLogName, log }); | ||
}; | ||
|
||
return ( | ||
<Typography | ||
variant="body1" | ||
color={log.uri ? 'primary' : 'textPrimary'} | ||
onClick={log.uri ? handleClick : undefined} | ||
key={taskLogName} | ||
className={styles.taskTitle} | ||
data-testid="map-task-log" | ||
> | ||
{taskLogName} | ||
</Typography> | ||
); | ||
})} | ||
</> | ||
); | ||
}; |
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
59 changes: 59 additions & 0 deletions
59
packages/zapp/console/src/components/common/MapTaskExecutionsList/test/TaskNameList.test.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,59 @@ | ||
import ThemeProvider from '@material-ui/styles/ThemeProvider'; | ||
import { render } from '@testing-library/react'; | ||
import { muiTheme } from 'components/Theme/muiTheme'; | ||
import * as React from 'react'; | ||
import { mockExecution as mockTaskExecution } from 'models/Execution/__mocks__/mockTaskExecutionsData'; | ||
|
||
import { TaskNameList } from '../TaskNameList'; | ||
|
||
const taskLogs = [ | ||
{ uri: '#', name: 'Kubernetes Logs #0-0' }, | ||
{ uri: '#', name: 'Kubernetes Logs #0-1' }, | ||
{ uri: '#', name: 'Kubernetes Logs #0-2' }, | ||
]; | ||
|
||
const taskLogsWithoutUri = [ | ||
{ name: 'Kubernetes Logs #0-0' }, | ||
{ name: 'Kubernetes Logs #0-1' }, | ||
{ name: 'Kubernetes Logs #0-2' }, | ||
]; | ||
|
||
describe('TaskNameList', () => { | ||
it('should render log names in color if they have URI', async () => { | ||
const { queryAllByTestId } = render( | ||
<ThemeProvider theme={muiTheme}> | ||
<TaskNameList | ||
logs={taskLogs} | ||
taskExecution={mockTaskExecution} | ||
onTaskSelected={jest.fn()} | ||
/> | ||
</ThemeProvider>, | ||
); | ||
|
||
const logs = queryAllByTestId('map-task-log'); | ||
expect(logs).toHaveLength(3); | ||
logs.forEach((log) => { | ||
expect(log).toBeInTheDocument(); | ||
expect(log).toHaveStyle({ color: '#8B37FF' }); | ||
}); | ||
}); | ||
|
||
it('should render log names in black if they have URI', () => { | ||
const { queryAllByTestId } = render( | ||
<ThemeProvider theme={muiTheme}> | ||
<TaskNameList | ||
logs={taskLogsWithoutUri} | ||
taskExecution={mockTaskExecution} | ||
onTaskSelected={jest.fn()} | ||
/> | ||
</ThemeProvider>, | ||
); | ||
|
||
const logs = queryAllByTestId('map-task-log'); | ||
expect(logs).toHaveLength(3); | ||
logs.forEach((log) => { | ||
expect(log).toBeInTheDocument(); | ||
expect(log).toHaveStyle({ color: '#292936' }); | ||
}); | ||
}); | ||
}); |