Moves TemplateListItem to a functional component

This commit is contained in:
Alex Corey
2020-01-23 11:00:50 -05:00
parent 21890efca6
commit 44db9ad033

View File

@@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { import {
DataListItem, DataListItem,
@@ -22,7 +22,6 @@ import ListActionButton from '@components/ListActionButton';
import VerticalSeparator from '@components/VerticalSeparator'; import VerticalSeparator from '@components/VerticalSeparator';
import { Sparkline } from '@components/Sparkline'; import { Sparkline } from '@components/Sparkline';
import { toTitleCase } from '@util/strings'; import { toTitleCase } from '@util/strings';
import styled from 'styled-components'; import styled from 'styled-components';
const rightStyle = ` const rightStyle = `
@@ -51,17 +50,18 @@ const LeftDataListCell = styled(DataListCell)`
} }
} }
`; `;
const RightDataListCell = styled(DataListCell)` const RightDataListCell = styled(DataListCell)`
${rightStyle} ${rightStyle}
`; `;
const RightActionButtonCell = styled(ActionButtonCell)` const RightActionButtonCell = styled(ActionButtonCell)`
${rightStyle} ${rightStyle}
`; `;
class TemplateListItem extends Component { function TemplateListItem({ i18n, template, isSelected, onSelect }) {
render() {
const { i18n, template, isSelected, onSelect } = this.props;
const canLaunch = template.summary_fields.user_capabilities.start; const canLaunch = template.summary_fields.user_capabilities.start;
const missingResourceIcon = const missingResourceIcon =
template.type === 'job_template' && template.type === 'job_template' &&
(!template.summary_fields.project || (!template.summary_fields.project ||
@@ -110,11 +110,7 @@ class TemplateListItem extends Component {
> >
{toTitleCase(template.type)} {toTitleCase(template.type)}
</RightDataListCell>, </RightDataListCell>,
<RightDataListCell <RightDataListCell css="flex: 1;" righthalf="true" key="sparkline">
css="flex: 1;"
righthalf="true"
key="sparkline"
>
<Sparkline jobs={template.summary_fields.recent_jobs} /> <Sparkline jobs={template.summary_fields.recent_jobs} />
</RightDataListCell>, </RightDataListCell>,
<RightActionButtonCell <RightActionButtonCell
@@ -127,10 +123,7 @@ class TemplateListItem extends Component {
<Tooltip content={i18n._(t`Launch Template`)} position="top"> <Tooltip content={i18n._(t`Launch Template`)} position="top">
<LaunchButton resource={template}> <LaunchButton resource={template}>
{({ handleLaunch }) => ( {({ handleLaunch }) => (
<ListActionButton <ListActionButton variant="plain" onClick={handleLaunch}>
variant="plain"
onClick={handleLaunch}
>
<RocketIcon /> <RocketIcon />
</ListActionButton> </ListActionButton>
)} )}
@@ -154,7 +147,7 @@ class TemplateListItem extends Component {
</DataListItemRow> </DataListItemRow>
</DataListItem> </DataListItem>
); );
}
} }
export { TemplateListItem as _TemplateListItem }; export { TemplateListItem as _TemplateListItem };
export default withI18n()(TemplateListItem); export default withI18n()(TemplateListItem);