-
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.
chore: add loading state + simplify storybook
Signed-off-by: Nastya Rusina <nastya@union.ai>
- Loading branch information
Showing
9 changed files
with
155 additions
and
84 deletions.
There are no files selected for viewing
49 changes: 14 additions & 35 deletions
49
src/components/Executions/ExecutionDetails/Timeline/BarChart/BarChart.stories.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,46 +1,25 @@ | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import * as React from 'react'; | ||
import { Bar } from 'react-chartjs-2'; | ||
import { NodeExecutionPhase } from 'models/Execution/enums'; | ||
import { generateChartData, getChartData } from './utils'; | ||
import { getBarOptions } from './barOptions'; | ||
|
||
const isFromCache = [false, true, true, false, false, false]; | ||
const phaseStatus = [ | ||
NodeExecutionPhase.FAILED, | ||
NodeExecutionPhase.SUCCEEDED, | ||
NodeExecutionPhase.SUCCEEDED, | ||
NodeExecutionPhase.RUNNING, | ||
NodeExecutionPhase.UNDEFINED, | ||
NodeExecutionPhase.SUCCEEDED, | ||
]; | ||
import { BarChart } from '.'; | ||
|
||
const barItems = [ | ||
{ phase: phaseStatus[0], startOffsetSec: 0, durationSec: 5, isFromCache: isFromCache[0] }, | ||
{ phase: phaseStatus[1], startOffsetSec: 10, durationSec: 2, isFromCache: isFromCache[1] }, | ||
{ phase: phaseStatus[2], startOffsetSec: 0, durationSec: 1, isFromCache: isFromCache[2] }, | ||
{ phase: phaseStatus[3], startOffsetSec: 0, durationSec: 10, isFromCache: isFromCache[3] }, | ||
{ phase: phaseStatus[4], startOffsetSec: 15, durationSec: 25, isFromCache: isFromCache[4] }, | ||
{ phase: phaseStatus[5], startOffsetSec: 7, durationSec: 20, isFromCache: isFromCache[5] }, | ||
{ phase: NodeExecutionPhase.FAILED, startOffsetSec: 0, durationSec: 5, isFromCache: false }, | ||
{ phase: NodeExecutionPhase.SUCCEEDED, startOffsetSec: 10, durationSec: 2, isFromCache: true }, | ||
{ phase: NodeExecutionPhase.SUCCEEDED, startOffsetSec: 0, durationSec: 1, isFromCache: true }, | ||
{ phase: NodeExecutionPhase.RUNNING, startOffsetSec: 0, durationSec: 10, isFromCache: false }, | ||
{ phase: NodeExecutionPhase.UNDEFINED, startOffsetSec: 15, durationSec: 25, isFromCache: false }, | ||
{ phase: NodeExecutionPhase.SUCCEEDED, startOffsetSec: 7, durationSec: 20, isFromCache: false }, | ||
]; | ||
|
||
export default { | ||
title: 'Workflow/Timeline', | ||
component: Bar, | ||
} as ComponentMeta<typeof Bar>; | ||
|
||
const Template: ComponentStory<typeof Bar> = (args) => <Bar {...args} />; | ||
export const BarSingle = Template.bind({}); | ||
const phaseDataSingle = generateChartData([barItems[0]]); | ||
BarSingle.args = { | ||
options: getBarOptions(1, phaseDataSingle.tooltipLabel) as any, | ||
data: getChartData(phaseDataSingle), | ||
}; | ||
component: BarChart, | ||
} as ComponentMeta<typeof BarChart>; | ||
|
||
export const BarSection = () => { | ||
const phaseData = generateChartData(barItems); | ||
// Chart interval - 1s | ||
return ( | ||
<Bar options={getBarOptions(1, phaseData.tooltipLabel) as any} data={getChartData(phaseData)} /> | ||
); | ||
const Template: ComponentStory<typeof BarChart> = (args) => <BarChart {...args} />; | ||
export const BarSection = Template.bind({}); | ||
BarSection.args = { | ||
items: barItems, | ||
chartTimeIntervalSec: 1, | ||
}; |
49 changes: 49 additions & 0 deletions
49
src/components/Executions/ExecutionDetails/Timeline/BarChart/BarChartSingleItem.stories.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,49 @@ | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import * as React from 'react'; | ||
import { NodeExecutionPhase } from 'models/Execution/enums'; | ||
import { BarItemData } from './utils'; | ||
import { BarChart } from '.'; | ||
|
||
const phaseEnumTyping = { | ||
options: Object.values(NodeExecutionPhase), | ||
mapping: Object.values(NodeExecutionPhase), | ||
control: { | ||
type: 'select', | ||
labels: Object.keys(NodeExecutionPhase), | ||
}, | ||
}; | ||
|
||
interface SingleItemProps extends BarItemData { | ||
chartTimeIntervalSec: number; | ||
} | ||
|
||
/** | ||
* This is a fake storybook only component, to allow ease experimentation whith single bar item | ||
*/ | ||
const SingleBarItem = (props: SingleItemProps) => { | ||
const items = [props]; | ||
return <BarChart items={items} chartTimeIntervalSec={props.chartTimeIntervalSec} />; | ||
}; | ||
|
||
export default { | ||
title: 'Workflow/Timeline', | ||
component: SingleBarItem, | ||
// 👇 Creates specific argTypes | ||
argTypes: { | ||
phase: phaseEnumTyping, | ||
}, | ||
} as ComponentMeta<typeof SingleBarItem>; | ||
|
||
const TemplateSingleItem: ComponentStory<typeof SingleBarItem> = (args) => ( | ||
<SingleBarItem {...args} /> | ||
); | ||
|
||
export const BarChartSingleItem = TemplateSingleItem.bind({}); | ||
// const phaseDataSingle = generateChartData([barItems[0]]); | ||
BarChartSingleItem.args = { | ||
phase: NodeExecutionPhase.ABORTED, | ||
startOffsetSec: 15, | ||
durationSec: 30, | ||
isFromCache: false, | ||
chartTimeIntervalSec: 5, | ||
}; |
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
20 changes: 20 additions & 0 deletions
20
src/components/Executions/ExecutionDetails/Timeline/BarChart/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,20 @@ | ||
import * as React from 'react'; | ||
import { Bar } from 'react-chartjs-2'; | ||
import { getBarOptions } from './barOptions'; | ||
import { BarItemData, generateChartData, getChartData } from './utils'; | ||
|
||
interface BarChartProps { | ||
items: BarItemData[]; | ||
chartTimeIntervalSec: number; | ||
} | ||
|
||
export const BarChart = (props: BarChartProps) => { | ||
const phaseData = generateChartData(props.items); | ||
|
||
return ( | ||
<Bar | ||
options={getBarOptions(props.chartTimeIntervalSec, phaseData.tooltipLabel) as any} | ||
data={getChartData(phaseData)} | ||
/> | ||
); | ||
}; |
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
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.