From 3653700572860f0f7da603eeb8767291c6507458 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sat, 12 Feb 2022 14:31:17 +0100 Subject: [PATCH] wip(lab): Work on workbench - Moved the various tabs on the draft view to their own views. - Renames modes to views - Started to group various aspects of the workbench state under `_state` in the gist to prevent it from getting all mixed up with the core settings. - Updated events title to make it more clear not all events might be present - Removed valid state in measurements input since it was only getting updated on keyboard input but now when preloading measurements (which it does now) --- .../components/layouts/default.js | 6 +- .../components/workbench/draft/error.js | 2 +- .../components/workbench/draft/events.js | 36 -------- .../components/workbench/draft/index.js | 27 +----- .../components/workbench/events.js | 44 +++++++++ .../workbench/inputs/measurement.js | 34 ++++--- .../components/workbench/json.js | 9 ++ .../workbench/measurements/index.js | 12 +-- .../components/workbench/menu/index.js | 6 +- .../workbench/menu/{modes.js => view.js} | 37 +++++--- .../components/workbench/yaml.js | 9 ++ .../components/wrappers/workbench.js | 89 ++++++++----------- 12 files changed, 155 insertions(+), 156 deletions(-) delete mode 100644 packages/freesewing.shared/components/workbench/draft/events.js create mode 100644 packages/freesewing.shared/components/workbench/events.js create mode 100644 packages/freesewing.shared/components/workbench/json.js rename packages/freesewing.shared/components/workbench/menu/{modes.js => view.js} (68%) create mode 100644 packages/freesewing.shared/components/workbench/yaml.js diff --git a/packages/freesewing.shared/components/layouts/default.js b/packages/freesewing.shared/components/layouts/default.js index db23949310a..d372adfd946 100644 --- a/packages/freesewing.shared/components/layouts/default.js +++ b/packages/freesewing.shared/components/layouts/default.js @@ -121,7 +121,7 @@ const DefaultLayout = ({ sm:flex-row-reverse ${workbench && collapsePrimaryNav ? 'sm:px-0 sm:w-16' - : 'sm:px-1 md:px-4 lg:px-8 xl:px-16 2xl:px-32 sm:w-[38.2%]' + : 'sm:px-1 md:px-4 lg:px-8 sm:w-[38.2%]' } `}> {workbench && ( @@ -144,7 +144,7 @@ const DefaultLayout = ({ sm:px-1 md:px-4 lg:px-8 ${workbench && collapsePrimaryNav ? '' - : 'max-w-61.8% xl:px-16 2xl:px-32' + : 'max-w-61.8%' } `}>
@@ -164,7 +164,7 @@ const DefaultLayout = ({ sm:flex-row ${workbench && collapseAltMenu ? 'sm:px-0 sm:w-16' - : 'sm:px-1 md:px-4 lg:px-8 xl:px-16 2xl:px-32 sm:w-[38.2%]' + : 'sm:px-1 md:px-4 lg:px-8 sm:w-[38.2%]' } `}>
diff --git a/packages/freesewing.shared/components/workbench/draft/error.js b/packages/freesewing.shared/components/workbench/draft/error.js index 43fc2e2f316..d48f19424d4 100644 --- a/packages/freesewing.shared/components/workbench/draft/error.js +++ b/packages/freesewing.shared/components/workbench/draft/error.js @@ -1,5 +1,5 @@ import Robot from 'shared/components/robot/index.js' -import Events from './events.js' +import Events from '../events.js' import { useTranslation } from 'next-i18next' const Error = props => { diff --git a/packages/freesewing.shared/components/workbench/draft/events.js b/packages/freesewing.shared/components/workbench/draft/events.js deleted file mode 100644 index e7c8020e627..00000000000 --- a/packages/freesewing.shared/components/workbench/draft/events.js +++ /dev/null @@ -1,36 +0,0 @@ -import Markdown from 'react-markdown' -import { linkClasses } from 'shared/components/navigation/primary.js' - -const eventBlock = events => events.join(" \n") - -const EventGroup = ({ type='info', events=[] }) => events.length > 0 ? ( -
-

{type}

-
- {eventBlock(events)} -
-
-) : null - -const order = [ - 'error', - 'warning', - 'info', - 'debug' -] - -const Events = props => ( -
-
    - {order.map(type => ( -
  • - {type} - {type === 'debug' ? '' : |} -
  • - ))} -
- {order.map(type => )} -
-) - -export default Events diff --git a/packages/freesewing.shared/components/workbench/draft/index.js b/packages/freesewing.shared/components/workbench/draft/index.js index cb4549d10f8..a00c5f86e90 100644 --- a/packages/freesewing.shared/components/workbench/draft/index.js +++ b/packages/freesewing.shared/components/workbench/draft/index.js @@ -1,25 +1,12 @@ -import React, { useState } from 'react' import SvgWrapper from './svg-wrapper' import Error from './error.js' -import Events from './events.js' -import Json from 'shared/components/json.js' -import Yaml from 'shared/components/yaml.js' import { capitalize } from 'shared/utils.js' import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch" -const tabClasses = active => ` - tab tab-bordered font-bold text-4xl pb-12 capitalize - ${active && 'text-base-content tab-active'} -` - -const Wrap = props =>
{props.children}
- const LabDraft = props => { const { app, draft, pattern, gist, updateGist, unsetGist } = props if (!draft) return null - const [tab, setTab] = useState(props.pattern.config.name) - if (gist?.renderer === 'svg') { // Render as SVG let svg @@ -41,24 +28,14 @@ const LabDraft = props => { return (
-
- {[props.pattern.config.name, 'events', 'yaml', 'json'].map(name => )} -
- {tab === 'events' && } - {tab === 'json' && {JSON.stringify(props.gist, null, 2)}} - {tab === 'yaml' && } - {tab === props.pattern.config.name && } + />
) } diff --git a/packages/freesewing.shared/components/workbench/events.js b/packages/freesewing.shared/components/workbench/events.js new file mode 100644 index 00000000000..107cb50ee72 --- /dev/null +++ b/packages/freesewing.shared/components/workbench/events.js @@ -0,0 +1,44 @@ +import Markdown from 'react-markdown' +import { linkClasses } from 'shared/components/navigation/primary.js' + +const eventBlock = events => events.join(" \n") + +const EventGroup = ({ type='info', events=[] }) => events.length > 0 ? ( +
+

{type}

+
+ {eventBlock(events)} +
+
+) : null + +const order = [ + 'error', + 'warning', + 'info', + 'debug' +] +const Events = props => ( +
+
+
    + {order.map(type => (props.draft.events[type].length > 0) + ? ( +
  • + {type} + {type === 'debug' ? '' : |} +
  • + ) : ( +
  • + {type} + {type === 'debug' ? '' : |} +
  • + ) + )} +
+ {order.map(type => )} +
+
+) + +export default Events diff --git a/packages/freesewing.shared/components/workbench/inputs/measurement.js b/packages/freesewing.shared/components/workbench/inputs/measurement.js index c0021d4df67..a6529114749 100644 --- a/packages/freesewing.shared/components/workbench/inputs/measurement.js +++ b/packages/freesewing.shared/components/workbench/inputs/measurement.js @@ -13,15 +13,17 @@ const MeasurementInput = ({ m, gist, app, updateMeasurements }) => { const { t } = useTranslation(['app', 'measurements']) const prefix = (app.site === 'org') ? '' : 'https://freesewing.org' const title = t(`measurements:${m}`) - const isValid = input => { - if (input === '') return '' - return !isNaN(input) - } + + const isValValid = val => (typeof val === 'undefined' || val === '') + ? null + : !isNaN(val) + const isValid = (newVal) => (typeof newVal === 'undefined') + ? isValValid(gist?.measurements?.[m]) + : isValValid(newVal) const update = evt => { setVal(evt.target.value) const ok = isValid(evt.target.value) - console.log({ok}) if (ok) { setValid(true) updateMeasurements(evt.target.value*10, m) @@ -29,10 +31,6 @@ const MeasurementInput = ({ m, gist, app, updateMeasurements }) => { } const [val, setVal] = useState(gist?.measurements?.[m] || '') - const [valid, setValid] = useState(typeof gist?.measurements?.[m] === 'undefined' - ? '' : - isValid(gist.measurements[m]) - ) useEffect(() => { if (gist?.measurements?.[m]) setVal(gist.measurements[m]/10) @@ -40,6 +38,7 @@ const MeasurementInput = ({ m, gist, app, updateMeasurements }) => { if (!m) return null + const valid = isValid() return (