-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storybook - Add stories for Canvas component
- Loading branch information
Showing
7 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
packages/ui-tests/cypress/fixtures/complexRouteMock.json
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,100 @@ | ||
{ | ||
"route": { | ||
"from": { | ||
"uri": "webhook", | ||
"parameters": {}, | ||
"steps": [ | ||
{ | ||
"to": { | ||
"id": "to-2015", | ||
"uri": "log", | ||
"parameters": {} | ||
} | ||
}, | ||
{ | ||
"choice": { | ||
"when": [ | ||
{ | ||
"when": {}, | ||
"steps": [ | ||
{ | ||
"to": { | ||
"id": "to-1528", | ||
"uri": "log", | ||
"parameters": {} | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "when-1938", | ||
"simple": "${header.foo} == 1", | ||
"steps": [ | ||
{ | ||
"log": { | ||
"id": "log-2139", | ||
"message": "${body}" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"otherwise": { | ||
"id": "otherwise-3846", | ||
"steps": [ | ||
{ | ||
"log": { | ||
"id": "log-1723", | ||
"message": "${body}" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"to": { | ||
"id": "to-2118", | ||
"uri": "aws2-s3", | ||
"parameters": {} | ||
} | ||
}, | ||
{ | ||
"doTry": { | ||
"id": "doTry-1388", | ||
"doCatch": [ | ||
{ | ||
"doCatch": {} | ||
}, | ||
{ | ||
"id": "doCatch-2642", | ||
"steps": [] | ||
} | ||
], | ||
"doFinally": { | ||
"id": "doFinally-6670", | ||
"steps": [] | ||
}, | ||
"steps": [] | ||
} | ||
}, | ||
{ | ||
"to": { | ||
"id": "to-2744", | ||
"uri": "log", | ||
"parameters": {} | ||
} | ||
}, | ||
{ | ||
"to": { | ||
"id": "to-2300", | ||
"uri": "kafka", | ||
"parameters": {} | ||
} | ||
} | ||
], | ||
"id": "from-5869" | ||
}, | ||
"id": "route-8888" | ||
} | ||
} |
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,95 @@ | ||
import { | ||
Canvas, | ||
CamelRouteVisualEntity, | ||
VisibleFlowsContext, | ||
VisibleFLowsContextResult, | ||
pipeJson, | ||
CatalogTilesProvider, | ||
CatalogLoaderProvider, | ||
PipeVisualEntity, | ||
EntitiesProvider, | ||
SchemasLoaderProvider, | ||
SourceCodeProvider, | ||
} from '@kaoto-next/ui/testing'; | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
import complexRouteMock from '../cypress/fixtures/complexRouteMock.json'; | ||
|
||
const emptyPipeJson = { | ||
apiVersion: 'camel.apache.org/v1', | ||
kind: 'Pipe', | ||
metadata: { | ||
name: 'new-pipe-template', | ||
}, | ||
spec: { | ||
source: {}, | ||
sink: {}, | ||
}, | ||
}; | ||
|
||
const emptyCamelRouteJson = { | ||
route: { | ||
id: 'route-8888', | ||
from: { | ||
uri: '', | ||
steps: [], | ||
}, | ||
}, | ||
}; | ||
|
||
const camelRouteEntity = new CamelRouteVisualEntity(complexRouteMock.route); | ||
const emptyCamelRouteEntity = new CamelRouteVisualEntity(emptyCamelRouteJson.route); | ||
const pipeEntity = new PipeVisualEntity(pipeJson.spec!); | ||
const emptyPipeEntity = new PipeVisualEntity(emptyPipeJson.spec!); | ||
|
||
const ContextDecorator = (Story: StoryFn) => ( | ||
<SourceCodeProvider> | ||
<EntitiesProvider> | ||
<SchemasLoaderProvider> | ||
<CatalogLoaderProvider> | ||
<CatalogTilesProvider> | ||
<Story /> | ||
</CatalogTilesProvider> | ||
</CatalogLoaderProvider> | ||
</SchemasLoaderProvider> | ||
</EntitiesProvider> | ||
</SourceCodeProvider> | ||
); | ||
|
||
export default { | ||
title: 'Canvas/Canvas', | ||
component: Canvas, | ||
decorators: [ContextDecorator], | ||
} as Meta<typeof Canvas>; | ||
|
||
const Template: StoryFn<typeof Canvas> = (args) => { | ||
const visibleId = args.entities[0].getId(); | ||
const firstVisibleEntity: unknown = { visibleFlows: { [visibleId]: true } }; | ||
|
||
return ( | ||
<div style={{ height: '600px', width: '100%' }}> | ||
<VisibleFlowsContext.Provider value={firstVisibleEntity as VisibleFLowsContextResult}> | ||
<Canvas {...args} /> | ||
</VisibleFlowsContext.Provider> | ||
</div> | ||
); | ||
}; | ||
|
||
export const CamelRouteVisualization = Template.bind({}); | ||
CamelRouteVisualization.args = { | ||
entities: [camelRouteEntity], | ||
}; | ||
|
||
export const PipeVisualization = Template.bind({}); | ||
PipeVisualization.args = { | ||
entities: [pipeEntity], | ||
}; | ||
|
||
export const EmptyPipeVisualization = Template.bind({}); | ||
EmptyPipeVisualization.args = { | ||
entities: [emptyPipeEntity], | ||
}; | ||
|
||
export const EmptyCamelRouteVisualization = Template.bind({}); | ||
EmptyCamelRouteVisualization.args = { | ||
entities: [emptyCamelRouteEntity], | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './visualization-node'; | ||
export * from './flows'; |
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,3 @@ | ||
export * from './camel-route'; | ||
export * from './kamelet-binding-route'; | ||
export * from './pipe'; |
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