diff --git a/webapp/src/components/AutomationList/index.stories.tsx b/webapp/src/components/AutomationList/index.stories.tsx new file mode 100644 index 0000000..e7406fb --- /dev/null +++ b/webapp/src/components/AutomationList/index.stories.tsx @@ -0,0 +1,74 @@ +import { ComponentMeta, ComponentStory } from "@storybook/react"; +import { useState } from "react"; +import { usePageTheme } from "styles/page"; +import { AutomationList } from "."; +import { NODE_HEIGHT, NODE_WIDTH, ADD_HEIGHT, ADD_WIDTH, CIRCLE_SIZE, DISTANCE_FACTOR } from 'components/DAGSvgs/constants'; +import { createMockAuto } from "utils/mocks"; + +export default { + title: 'App/AutomationList', + component: AutomationList, + parameters: { actions: { argTypesRegex: '^on.*' } }, + args: { + dims: { + nodeHeight: NODE_HEIGHT, + nodeWidth: NODE_WIDTH, + addHeight: ADD_HEIGHT, + addWidth: ADD_WIDTH, + circleSize: CIRCLE_SIZE, + distanceFactor: DISTANCE_FACTOR, + } + } +} as ComponentMeta; + + +const Template: ComponentStory = args => { + const { classes } = usePageTheme({}); + const [autos, setAutos] = useState(args.automations) + return
+ { + args.onAdd(a); + setAutos([...autos, a]); + }} + onRemove={i => { + args.onRemove(i); + setAutos([ + ...autos.slice(0, i), + ...autos.slice(i + 1), + ]); + }} + onUpdate={(i, a) => { + args.onUpdate(i, a); + setAutos([ + ...autos.slice(0, i), + a, + ...autos.slice(i + 1), + ]); + }} + /> +
+} + +export const EmptyStart = Template.bind({}) +EmptyStart.args = { + ...EmptyStart.args, + automations: [], +} + +export const FewAutos = Template.bind({}) +FewAutos.args = { + ...FewAutos.args, + automations: [ + createMockAuto(), + createMockAuto(), + createMockAuto(), + createMockAuto(), + createMockAuto(), + createMockAuto(), + createMockAuto(), + createMockAuto(), + createMockAuto(), + createMockAuto(), + ], +} diff --git a/webapp/src/components/AutomationList/index.tsx b/webapp/src/components/AutomationList/index.tsx new file mode 100644 index 0000000..607d48e --- /dev/null +++ b/webapp/src/components/AutomationList/index.tsx @@ -0,0 +1,63 @@ +import "./styles.css"; +import { AutomationEditor } from "components/AutomationEditor"; +import { Button } from "components/Inputs/Button"; +import { FC, useState } from "react"; +import { AutomationData } from "types/automations"; +import { DAGBoardElmDims } from 'components/DAGSvgs/DAGBoard'; +import { defaultAutomation } from '../../utils/defaults'; +import { ArrowIcon, TrashIcon } from "components/Icons"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; + + +interface Props { + automations: AutomationData[]; + onUpdate: (i: number, auto: AutomationData) => void; + onAdd: (auto: AutomationData) => void; + onRemove: (i: number) => void; + dims: DAGBoardElmDims; +} + +export const AutomationList: FC = ({ + automations, + onUpdate, + onAdd, + onRemove, + dims, +}) => { + // state + const [current, setCurrent] = useState(0); + const [hideList, setHideList] = useState(false); + // alias + const currentAuto = automations.length > 0 ? automations[current] : null; + const automationListListCls = "automation-list--list" + (hideList ? " hide" : " show") + // render + return
+
+
+ {automations.map((auto, i) => +
+ + +
+ )} + +
+ setHideList(!hideList)} + className="automation-list--list-hide" + > + {ArrowIcon} + +
+
+ {currentAuto ? onUpdate(current, a)} + dims={dims} + /> : <>} +
+
+} diff --git a/webapp/src/components/AutomationList/styles.css b/webapp/src/components/AutomationList/styles.css new file mode 100644 index 0000000..00bf4eb --- /dev/null +++ b/webapp/src/components/AutomationList/styles.css @@ -0,0 +1,87 @@ +/* root elements */ +.automation-list--root { + width : 100%; + height : 100%; + display : flex; + flex-direction: row; + overflow : hidden; +} + +.automation-list--list { + flex : 1; + min-width: 200px; + max-width: 200px; + position : relative; +} + +.automation-list--viewer { + flex: 6; +} + +/* list children: on hide */ +.automation-list--list.hide>.automation-list--list-box { + display: none; +} + +.automation-list--list.hide { + min-width: 35px; + max-width: 35px; +} + +.automation-list--list.hide>.automation-list--list-hide { + transform: rotate(180deg); +} + +/* list children: normal */ +.automation-list--list { + border-right: solid; + border-width: 1px; +} + +.automation-list--list-hide { + position: absolute; + top : 0; + right : 5px; +} + + +.automation-list--list-box { + overflow : auto; + height : 100%; + display : flex; + flex-direction : column; + justify-content: flex-start; + align-items : center; + padding-top : 10px; + margin-bottom : 10px; +} + +.automation-list--list-box>* { + margin-bottom: 10px; +} + +.automation-list--list-box>:last-child { + background-color: #070; + color : white; +} + +.automation-list--elm { + position: relative; +} + +.automation-list--elm>button { + padding-left : 5px; + padding-right: 5px; +} + +.automation-list--elm>button>span { + font-size: 0.75em; +} + +.automation-list--elm>.automation-list--elm-remove { + position: absolute; + left : -10px; + top : 10%; + padding : 0; + margin : 0; +}