From fe51c528d2c9b3db88801056c66433efc8e89ef9 Mon Sep 17 00:00:00 2001 From: Michael Schramm Date: Tue, 1 Mar 2022 15:21:51 +0100 Subject: [PATCH] change default form layout to card --- .eslintrc.js | 1 + CHANGELOG.md | 3 + .../form/admin/export.submission.action.tsx | 7 +- components/form/admin/field.card.tsx | 5 +- components/form/admin/fields.tab.tsx | 4 +- components/form/admin/submission.values.tsx | 16 +- components/form/admin/types/index.ts | 22 --- components/form/layouts/card/field.tsx | 13 +- components/form/layouts/card/index.tsx | 9 +- components/form/layouts/slider/field.tsx | 12 +- components/form/layouts/slider/index.tsx | 1 + components/form/types/abstract.type.tsx | 38 +++++ .../checkbox/checkbox.admin.tsx} | 4 +- .../checkbox.input.tsx} | 31 ++-- components/form/types/checkbox/index.ts | 15 ++ .../date/date.admin.tsx} | 4 +- .../{date.type.tsx => date/date.input.tsx} | 24 ++- components/form/types/date/index.ts | 24 +++ .../dropdown/dropdown.admin.tsx} | 4 +- .../dropdown.input.tsx} | 20 ++- components/form/types/dropdown/index.ts | 15 ++ .../email/email.admin.tsx} | 4 +- .../{email.type.tsx => email/email.input.tsx} | 22 ++- components/form/types/email/index.ts | 15 ++ .../field.admin.props.ts} | 2 +- .../form/types/field.input.builder.type.ts | 6 + .../{type.props.ts => field.input.props.ts} | 2 +- .../hidden/hidden.admin.tsx} | 4 +- components/form/types/hidden/index.ts | 15 ++ .../image/image.admin.tsx} | 0 .../form/types/{ => image}/image.type.tsx | 0 components/form/types/image/index.ts | 15 ++ components/form/types/index.ts | 57 +++---- components/form/types/link/index.ts | 15 ++ .../link/link.admin.tsx} | 4 +- .../{link.type.tsx => link/link.input.tsx} | 22 ++- components/form/types/location/index.ts | 34 ++++ .../location/location.admin.tsx} | 6 +- .../form/types/location/location.input.tsx | 153 ++++++++++++++++++ components/form/types/map.type.tsx | 0 components/form/types/number/index.ts | 19 +++ .../number/number.admin.tsx} | 4 +- .../number.input.tsx} | 22 ++- components/form/types/radio/index.ts | 15 ++ .../radio/radio.admin.tsx} | 4 +- .../{radio.type.tsx => radio/radio.input.tsx} | 22 ++- components/form/types/rating/index.ts | 19 +++ .../rating/rating.admin.tsx} | 4 +- .../rating.input.tsx} | 20 ++- components/form/types/slider/index.ts | 19 +++ .../slider/slider.admin.tsx} | 4 +- .../slider.input.tsx} | 21 ++- components/form/types/textarea/index.ts | 15 ++ .../textarea/textarea.admin.tsx} | 4 +- .../textarea.input.tsx} | 22 ++- components/form/types/textfield/index.ts | 15 ++ .../textfield/textfield.admin.tsx} | 4 +- .../textfield.input.tsx} | 29 +++- components/form/types/yes_no/index.tsx | 36 +++++ .../yes_no/yes_no.admin.tsx} | 4 +- .../yes_no.input.tsx} | 20 ++- components/use.submission.ts | 18 ++- pages/admin/forms/create.tsx | 1 - 63 files changed, 786 insertions(+), 203 deletions(-) delete mode 100644 components/form/admin/types/index.ts create mode 100644 components/form/types/abstract.type.tsx rename components/form/{admin/types/checkbox.type.tsx => types/checkbox/checkbox.admin.tsx} (95%) rename components/form/types/{checkbox.type.tsx => checkbox/checkbox.input.tsx} (56%) create mode 100644 components/form/types/checkbox/index.ts rename components/form/{admin/types/date.type.tsx => types/date/date.admin.tsx} (91%) rename components/form/types/{date.type.tsx => date/date.input.tsx} (77%) create mode 100644 components/form/types/date/index.ts rename components/form/{admin/types/dropdown.type.tsx => types/dropdown/dropdown.admin.tsx} (95%) rename components/form/types/{dropdown.type.tsx => dropdown/dropdown.input.tsx} (74%) create mode 100644 components/form/types/dropdown/index.ts rename components/form/{admin/types/email.type.tsx => types/email/email.admin.tsx} (79%) rename components/form/types/{email.type.tsx => email/email.input.tsx} (61%) create mode 100644 components/form/types/email/index.ts rename components/form/{admin/types/type.props.ts => types/field.admin.props.ts} (78%) create mode 100644 components/form/types/field.input.builder.type.ts rename components/form/types/{type.props.ts => field.input.props.ts} (86%) rename components/form/{admin/types/hidden.type.tsx => types/hidden/hidden.admin.tsx} (75%) create mode 100644 components/form/types/hidden/index.ts rename components/form/{admin/types/image.type.tsx => types/image/image.admin.tsx} (100%) rename components/form/types/{ => image}/image.type.tsx (100%) create mode 100644 components/form/types/image/index.ts create mode 100644 components/form/types/link/index.ts rename components/form/{admin/types/link.type.tsx => types/link/link.admin.tsx} (79%) rename components/form/types/{link.type.tsx => link/link.input.tsx} (61%) create mode 100644 components/form/types/location/index.ts rename components/form/{admin/types/location.type.tsx => types/location/location.admin.tsx} (95%) create mode 100644 components/form/types/location/location.input.tsx delete mode 100644 components/form/types/map.type.tsx create mode 100644 components/form/types/number/index.ts rename components/form/{admin/types/number.type.tsx => types/number/number.admin.tsx} (76%) rename components/form/types/{number.type.tsx => number/number.input.tsx} (61%) create mode 100644 components/form/types/radio/index.ts rename components/form/{admin/types/radio.type.tsx => types/radio/radio.admin.tsx} (95%) rename components/form/types/{radio.type.tsx => radio/radio.input.tsx} (69%) create mode 100644 components/form/types/rating/index.ts rename components/form/{admin/types/rating.type.tsx => types/rating/rating.admin.tsx} (78%) rename components/form/types/{rating.type.tsx => rating/rating.input.tsx} (60%) create mode 100644 components/form/types/slider/index.ts rename components/form/{admin/types/slider.type.tsx => types/slider/slider.admin.tsx} (94%) rename components/form/types/{slider.type.tsx => slider/slider.input.tsx} (80%) create mode 100644 components/form/types/textarea/index.ts rename components/form/{admin/types/textarea.type.tsx => types/textarea/textarea.admin.tsx} (76%) rename components/form/types/{textarea.type.tsx => textarea/textarea.input.tsx} (57%) create mode 100644 components/form/types/textfield/index.ts rename components/form/{admin/types/text.type.tsx => types/textfield/textfield.admin.tsx} (73%) rename components/form/types/{text.type.tsx => textfield/textfield.input.tsx} (50%) create mode 100644 components/form/types/yes_no/index.tsx rename components/form/{admin/types/yes_no.type.tsx => types/yes_no/yes_no.admin.tsx} (77%) rename components/form/types/{yes_no.type.tsx => yes_no/yes_no.input.tsx} (61%) diff --git a/.eslintrc.js b/.eslintrc.js index ea72d4e..e222e14 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -25,6 +25,7 @@ module.exports = { '@typescript-eslint/no-unsafe-assignment': 'off', '@typescript-eslint/no-unsafe-argument': 'off', '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-explicit-any': 'off', 'react/prop-types': 'off', '@typescript-eslint/no-empty-interface': 'off', 'jsx-a11y/no-autofocus': 'off', diff --git a/CHANGELOG.md b/CHANGELOG.md index 42db32c..3bab40e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,11 +16,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - update translations (https://github.com/ohmyform/ui/pull/70) - show warning icon in form list if not public - default form layout is now "card" +- creating of new fields combined in new field types ### Fixed - locale scripts were missing dependency - edit user shows now email in title +- focus is now passed also do slide layout fields +- empty fields are no longer submitted ### Security diff --git a/components/form/admin/export.submission.action.tsx b/components/form/admin/export.submission.action.tsx index aa6b37a..1c3b747 100644 --- a/components/form/admin/export.submission.action.tsx +++ b/components/form/admin/export.submission.action.tsx @@ -4,6 +4,7 @@ import { useCallback, useState } from 'react' import { SubmissionFragment } from '../../../graphql/fragment/submission.fragment' import { useFormQuery } from '../../../graphql/query/form.query' import { useSubmissionPagerImperativeQuery } from '../../../graphql/query/submission.pager.query' +import { fieldTypes } from '../types' interface Props { form: string @@ -66,9 +67,9 @@ export const ExportSubmissionAction: React.FC = (props) => { data.fields.forEach((field) => { try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const decoded: { value: CellValue } = JSON.parse(field.value) - row.push(decoded.value || '') + fieldTypes[field.type]?.stringifyValue(field.value) + + row.push(fieldTypes[field.type]?.stringifyValue(field.value)) } catch (e) { row.push('') } diff --git a/components/form/admin/field.card.tsx b/components/form/admin/field.card.tsx index 11c35e8..788f0e8 100644 --- a/components/form/admin/field.card.tsx +++ b/components/form/admin/field.card.tsx @@ -6,9 +6,8 @@ import { FieldData } from 'rc-field-form/lib/interface' import React, { useCallback, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { FormFieldFragment, FormFieldLogicFragment } from '../../../graphql/fragment/form.fragment' +import { fieldTypes } from '../types' import { LogicBlock } from './logic.block' -import { adminTypes } from './types' -import { TextType } from './types/text.type' interface Props { form: FormInstance @@ -34,7 +33,7 @@ export const FieldCard: React.FC = ({ const type = form.getFieldValue([ 'form', 'fields', field.name as string, 'type', ]) as string - const TypeComponent = adminTypes[type] || TextType + const TypeComponent = (fieldTypes[type] || fieldTypes['textfield']).adminFormField() const [shouldUpdate, setShouldUpdate] = useState(false) const [nextTitle, setNextTitle] = useState( diff --git a/components/form/admin/fields.tab.tsx b/components/form/admin/fields.tab.tsx index 3ab66cd..b9d2593 100644 --- a/components/form/admin/fields.tab.tsx +++ b/components/form/admin/fields.tab.tsx @@ -7,8 +7,8 @@ import { FieldData } from 'rc-field-form/lib/interface' import React, { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import { FormFieldFragment } from '../../../graphql/fragment/form.fragment' +import { fieldTypes } from '../types' import { FieldCard } from './field.card' -import { adminTypes } from './types' const logger = debug('FieldsTab') @@ -61,7 +61,7 @@ export const FieldsTab: React.FC = (props) => { }} >