Canvas is a plugin for Kibana, therefore its [contribution guidelines](../../../CONTRIBUTING.md) apply to Canvas development, as well. This document contains Canvas-specific guidelines that extend from the Kibana guidelines.
These singletons can then be changed at will, as well as audited for unused methods, (and therefore unused i18n strings).
## Component Code Structure
Canvas uses Redux. Component code is divided into React components and Redux containers. This way, components can be reused, their containers can be edited, and both can be tested independently.
Canvas is actively migrating to a structure which uses the `index.ts` file as a thin exporting index, rather than functional code:
```
- components
- foo <-directoryrepresentingthecomponent
- foo.ts <-reduxcontainer
- foo.component.tsx <-reactcomponent
- foo.scss
- index.ts <-thinexportingindex,(noredux)
- bar <-directoryrepresentingthecomponent
- bar.ts
- bar.component.tsx
- bar.scss
- bar_dep.ts <-reduxsubcontainer
- bar_dep.component.tsx <-subcomponent
- index.ts
```
The exporting file would be:
```
export { Foo } from './foo';
export { Foo as FooComponent } from './foo.component';
```
### Why?
Canvas has been using an "index-export" structure that has served it well, until recently. In this structure, the `index.ts` file serves as the primary export of the Redux component, (and holds that code). The component is then named-- `component.tsx`-- and consumed in the `index` file.
The problem we've run into is when you have sub-components which are also connected to Redux. To maintain this structure, each sub-component and its Redux container would then be stored in a subdirectory, (with only two files in it).
> NOTE: if a PR touches component code that is in the older structure, it should be migrated to the structure above.
## Storybook
Canvas uses [Storybook](https://storybook.js.org) to test and develop components. This has a number of benefits:
- Developing components without needing to start ES + Kibana.
- Testing components interactively without starting ES + Kibana.