Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show launch plan information in workflow's schedules #739

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/console/src/components/Entities/EntityDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const useStyles = makeStyles((theme: Theme) => ({
},
schedulesContainer: {
flex: '1 2 auto',
marginRight: theme.spacing(30),
},
inputsContainer: {
display: 'flex',
Expand Down
75 changes: 60 additions & 15 deletions packages/console/src/components/Entities/EntitySchedules.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Typography } from '@material-ui/core';
import {
Paper,
Typography,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
} from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import {
getScheduleFrequencyString,
Expand All @@ -11,6 +20,7 @@ import { ResourceIdentifier } from 'models/Common/types';
import { identifierToString } from 'models/Common/utils';
import { LaunchPlan } from 'models/Launch/types';
import * as React from 'react';
import { LaunchPlanLink } from 'components/LaunchPlan/LaunchPlanLink';
import { entityStrings } from './constants';
import t, { patternKey } from './strings';

Expand All @@ -25,26 +35,61 @@ const useStyles = makeStyles((theme: Theme) => ({
borderBottom: `1px solid ${theme.palette.divider}`,
marginBottom: theme.spacing(1),
},
headCell: {
color: theme.palette.grey[400],
},
}));

const RenderSchedules: React.FC<{
launchPlans: LaunchPlan[];
}> = ({ launchPlans }) => {
const commonStyles = useCommonStyles();
const styles = useStyles();
return (
<ul className={commonStyles.listUnstyled}>
{launchPlans.map(launchPlan => {
const { schedule } = launchPlan.spec.entityMetadata;
const frequencyString = getScheduleFrequencyString(schedule);
const offsetString = getScheduleOffsetString(schedule);
const scheduleString = offsetString
? `${frequencyString} (offset by ${offsetString})`
: frequencyString;
return (
<li key={identifierToString(launchPlan.id)}>{scheduleString}</li>
);
})}
</ul>
<TableContainer component={Paper}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me sync with our UX team on this; we might want to also show which entity version which schedule is applied to.

<Table size="small">
<TableHead>
<TableRow>
<TableCell>
<Typography className={styles.headCell} variant="h4">
{t(patternKey('launchPlan', 'frequency'))}
</Typography>
</TableCell>
<TableCell className={styles.headCell}>
<Typography className={styles.headCell} variant="h4">
{t(patternKey('launchPlan', 'name'))}
</Typography>
</TableCell>
<TableCell className={styles.headCell}>
<Typography className={styles.headCell} variant="h4">
{t(patternKey('launchPlan', 'version'))}
</Typography>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{launchPlans.map(launchPlan => {
const { schedule } = launchPlan.spec.entityMetadata;
const frequencyString = getScheduleFrequencyString(schedule);
const offsetString = getScheduleOffsetString(schedule);
const scheduleString = offsetString
? `${frequencyString} (offset by ${offsetString})`
: frequencyString;

return (
<TableRow key={launchPlan.id.name}>
<TableCell>{scheduleString}</TableCell>
<TableCell>
<LaunchPlanLink id={launchPlan.id} color="disabled">
{launchPlan.id.name}
</LaunchPlanLink>
</TableCell>
<TableCell>{launchPlan.id.version}</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
);
};

Expand Down
3 changes: 3 additions & 0 deletions packages/console/src/components/Entities/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const str = {
configTestSplitRatio: 'test_split_ratio',
noExpectedInputs: 'This launch plan has no expected inputs.',
noFixedInputs: 'This launch plan has no fixed inputs.',
launchPlan_frequency: 'Frequency',
launchPlan_name: 'Launch Plan',
launchPlan_version: 'Version',
};

export { patternKey } from '@flyteorg/locale';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ResourceIdentifier, ResourceType } from 'models/Common/types';
import { listLaunchPlans } from 'models/Launch/api';
import { LaunchPlan, LaunchPlanState } from 'models/Launch/types';
import * as React from 'react';
import { MemoryRouter } from 'react-router';
import { EntitySchedules } from '../EntitySchedules';
import t from '../strings';

Expand All @@ -26,7 +27,11 @@ describe('EntitySchedules', () => {
let launchPlans: LaunchPlan[];

const renderSchedules = async () => {
const result = render(<EntitySchedules id={id} />);
const result = render(
<MemoryRouter>
<EntitySchedules id={id} />
</MemoryRouter>,
);
await waitFor(() => result.getByText(t('schedulesHeader')));
return result;
};
Expand Down
27 changes: 27 additions & 0 deletions packages/console/src/components/LaunchPlan/LaunchPlanLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import classnames from 'classnames';
import { useCommonStyles } from 'components/common/styles';
import { LaunchPlanId } from 'models/Launch/types';
import * as React from 'react';
import { Link as RouterLink } from 'react-router-dom';
import { Routes } from 'routes/routes';

/** A simple component to render a link to a specific LaunchPlan */
export const LaunchPlanLink: React.FC<{
className?: string;
color?: 'primary' | 'disabled';
id: LaunchPlanId;
}> = ({ className, color = 'primary', id }) => {
const commonStyles = useCommonStyles();
const linkColor =
color === 'disabled'
? commonStyles.secondaryLink
: commonStyles.primaryLink;
return (
<RouterLink
className={classnames(linkColor, className)}
to={`${Routes.LaunchPlanDetails.makeUrl(id.project, id.domain, id.name)}`}
>
{id.name}
</RouterLink>
);
};