|
| 1 | +/* |
| 2 | + * Copyright 2025 The Kubernetes Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { Meta, StoryFn } from '@storybook/react'; |
| 18 | +import { useTranslation } from 'react-i18next'; |
| 19 | +import Job from '../../lib/k8s/job'; |
| 20 | +import { TestContext } from '../../test'; |
| 21 | +import NameValueTable from '../common/NameValueTable'; |
| 22 | +import { jobs } from '../job/storyHelper'; |
| 23 | +import { jobExtraInfo } from './extraInfo'; |
| 24 | + |
| 25 | +// Completed job from storyHelper has both startTime and completionTime, so it |
| 26 | +// has a real duration. The running variant drops completionTime, so |
| 27 | +// getDuration() returns -1 and the Duration row is hidden. |
| 28 | +const completedJob = new Job(jobs[0] as any); |
| 29 | +const runningJob = new Job({ |
| 30 | + ...jobs[0], |
| 31 | + status: { ...jobs[0].status, completionTime: undefined }, |
| 32 | +} as any); |
| 33 | + |
| 34 | +// jobExtraInfo takes a translator; render through NameValueTable to show which |
| 35 | +// rows are actually displayed (hidden rows are dropped by the table). |
| 36 | +function JobExtraInfo({ job }: { job: Job }) { |
| 37 | + const { t } = useTranslation(); |
| 38 | + return <NameValueTable rows={jobExtraInfo(job, t)} />; |
| 39 | +} |
| 40 | + |
| 41 | +export default { |
| 42 | + title: 'workload/JobExtraInfo', |
| 43 | + component: JobExtraInfo, |
| 44 | + decorators: [ |
| 45 | + Story => ( |
| 46 | + <TestContext> |
| 47 | + <Story /> |
| 48 | + </TestContext> |
| 49 | + ), |
| 50 | + ], |
| 51 | +} as Meta; |
| 52 | + |
| 53 | +const Template: StoryFn<{ job: Job }> = args => <JobExtraInfo {...args} />; |
| 54 | + |
| 55 | +// Completed job: the Duration row is shown. |
| 56 | +export const Completed = Template.bind({}); |
| 57 | +Completed.args = { job: completedJob }; |
| 58 | + |
| 59 | +// Running job: getDuration() is -1, so the Duration row is hidden. |
| 60 | +export const Running = Template.bind({}); |
| 61 | +Running.args = { job: runningJob }; |
0 commit comments