From 7c466704fd7af02c7ecd1a3a3eb76521629745fb Mon Sep 17 00:00:00 2001 From: Hein Jeong <73264629+hein-j@users.noreply.github.com> Date: Tue, 31 May 2022 10:26:01 -0700 Subject: [PATCH] chore: add form-related types (#469) Co-authored-by: Hein Jeong --- packages/codegen-ui/lib/types/data.ts | 24 ++++++++ packages/codegen-ui/lib/types/form/fields.ts | 46 +++++++++++++++ .../lib/types/form/form-definition.ts | 39 ++++++++++++ packages/codegen-ui/lib/types/form/index.ts | 44 ++++++++++++++ .../codegen-ui/lib/types/form/input-config.ts | 59 +++++++++++++++++++ .../codegen-ui/lib/types/form/position.ts | 16 +++++ .../lib/types/form/sectional-element.ts | 42 +++++++++++++ packages/codegen-ui/lib/types/form/style.ts | 33 +++++++++++ packages/codegen-ui/lib/types/index.ts | 2 + 9 files changed, 305 insertions(+) create mode 100644 packages/codegen-ui/lib/types/data.ts create mode 100644 packages/codegen-ui/lib/types/form/fields.ts create mode 100644 packages/codegen-ui/lib/types/form/form-definition.ts create mode 100644 packages/codegen-ui/lib/types/form/index.ts create mode 100644 packages/codegen-ui/lib/types/form/input-config.ts create mode 100644 packages/codegen-ui/lib/types/form/position.ts create mode 100644 packages/codegen-ui/lib/types/form/sectional-element.ts create mode 100644 packages/codegen-ui/lib/types/form/style.ts diff --git a/packages/codegen-ui/lib/types/data.ts b/packages/codegen-ui/lib/types/data.ts new file mode 100644 index 000000000..10a15cd83 --- /dev/null +++ b/packages/codegen-ui/lib/types/data.ts @@ -0,0 +1,24 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +type FieldType = string | { model: string } | { nonModel: string } | { enum: string }; + +export type DataStoreModelField = { + name: string; + type: FieldType; + isReadOnly: boolean; + isRequired: boolean; + isArray: boolean; +}; diff --git a/packages/codegen-ui/lib/types/form/fields.ts b/packages/codegen-ui/lib/types/form/fields.ts new file mode 100644 index 000000000..8184de6c1 --- /dev/null +++ b/packages/codegen-ui/lib/types/form/fields.ts @@ -0,0 +1,46 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +import { StudioFieldPosition } from './position'; +import { StudioFieldInputConfig } from './input-config'; + +/** + * Field configurations for StudioForm + */ +type StudioFieldConfig = { + label?: string; + + position?: StudioFieldPosition; +}; + +/** + * If a field is excluded, it should have no other properties. + */ +type ExcludedStudioFieldConfig = { + excluded: true; +}; + +type StudioGenericFieldConfig = { + /** + * The configuration for what type of input is used. + */ + inputType?: StudioFieldInputConfig; +} & StudioFieldConfig; + +export type StudioFormFieldConfig = StudioGenericFieldConfig | ExcludedStudioFieldConfig; + +export type StudioFormFields = { + [field: string]: StudioFormFieldConfig; +}; diff --git a/packages/codegen-ui/lib/types/form/form-definition.ts b/packages/codegen-ui/lib/types/form/form-definition.ts new file mode 100644 index 000000000..97d0976d4 --- /dev/null +++ b/packages/codegen-ui/lib/types/form/form-definition.ts @@ -0,0 +1,39 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +import { StudioFormStyle } from './style'; + +export type FormDefinitionElementProps = { + isReadOnly?: boolean; + isRequired?: boolean; + label?: string; + placeholder?: string; + minValue?: number; + maxValue?: number; + step?: number; + level?: number; + text?: string; +}; + +export type FormDefinition = { + form: { + props: { + layoutStyle: StudioFormStyle; + }; + }; + elements: { [element: string]: { componentType: string; dataType?: string; props: FormDefinitionElementProps } }; + buttons: { [key: string]: string }; + elementMatrix: string[][]; +}; diff --git a/packages/codegen-ui/lib/types/form/index.ts b/packages/codegen-ui/lib/types/form/index.ts new file mode 100644 index 000000000..84cb0dd98 --- /dev/null +++ b/packages/codegen-ui/lib/types/form/index.ts @@ -0,0 +1,44 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +import { StudioFormStyle } from './style'; +import { StudioFormFields, StudioFormFieldConfig } from './fields'; +import { SectionalElement } from './sectional-element'; +import { FormDefinition, FormDefinitionElementProps } from './form-definition'; + +/** + * Data type definition for StudioForm + */ +type StudioFormDataType = { + dataSourceType: 'DataStore' | 'Custom'; + + dataTypeName: string; +}; + +/** + * This is the base type for all StudioForms + */ +export type StudioForm = { + dataType: StudioFormDataType; + + fields: StudioFormFields; + + sectionalElements: SectionalElement[]; + + style: StudioFormStyle; +}; + +export type { StudioFormStyle, SectionalElement, StudioFormFieldConfig, FormDefinition, FormDefinitionElementProps }; diff --git a/packages/codegen-ui/lib/types/form/input-config.ts b/packages/codegen-ui/lib/types/form/input-config.ts new file mode 100644 index 000000000..74af60777 --- /dev/null +++ b/packages/codegen-ui/lib/types/form/input-config.ts @@ -0,0 +1,59 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +type StudioFieldBaseConfig = { + required?: boolean; + + readOnly?: boolean; +}; + +type StudioFieldTextFieldConfig = { + type: 'TextField'; + + placeholder?: string; +}; + +type StudioFieldSelectListFieldConfig = { + type: 'SelectField'; + + placeholder?: string; + + valueMappings: { value: string; displayValue: string }[]; +}; + +type StudioFieldRadioListFieldConfig = { + type: 'RadioGroupField'; + + valueMappings: { value: string; displayValue: string }[]; +}; + +type StudioFieldSliderFieldConfig = { + type: 'SliderField'; + + minValue: number; + + maxValue: number; + + step: number; +}; + +export type StudioFieldInputConfig = ( + | StudioFieldTextFieldConfig + | StudioFieldSelectListFieldConfig + | StudioFieldRadioListFieldConfig + | StudioFieldSliderFieldConfig +) & + StudioFieldBaseConfig; diff --git a/packages/codegen-ui/lib/types/form/position.ts b/packages/codegen-ui/lib/types/form/position.ts new file mode 100644 index 000000000..a05577ab9 --- /dev/null +++ b/packages/codegen-ui/lib/types/form/position.ts @@ -0,0 +1,16 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +export type StudioFieldPosition = { fixed: 'first' } | { rightOf: string } | { below: string }; diff --git a/packages/codegen-ui/lib/types/form/sectional-element.ts b/packages/codegen-ui/lib/types/form/sectional-element.ts new file mode 100644 index 000000000..fdfc5f870 --- /dev/null +++ b/packages/codegen-ui/lib/types/form/sectional-element.ts @@ -0,0 +1,42 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +import { StudioFieldPosition } from './position'; +/** + * Sectional elements are visual helpers for the form. They don't have any data associated with them. + */ +type HeadingSectionalElement = { + type: 'Heading'; + + level: 1 | 2 | 3 | 4 | 5 | 6; + + text: string; +}; + +type TextSectionalElement = { + type: 'Text'; + + text: string; +}; + +type DividerSectionalElement = { + type: 'Divider'; +}; + +export type SectionalElement = { position: StudioFieldPosition; name: string } & ( + | HeadingSectionalElement + | DividerSectionalElement + | TextSectionalElement +); diff --git a/packages/codegen-ui/lib/types/form/style.ts b/packages/codegen-ui/lib/types/form/style.ts new file mode 100644 index 000000000..3414bee29 --- /dev/null +++ b/packages/codegen-ui/lib/types/form/style.ts @@ -0,0 +1,33 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +type FormStyleConfigCommon = { + tokenReference?: string; +}; + +type FormStyleConfig = { + value?: string; +} & FormStyleConfigCommon; + +type FormAlignmentConfig = { + value?: 'left' | 'center' | 'right'; +} & FormStyleConfigCommon; + +export type StudioFormStyle = { + horizontalGap?: FormStyleConfig; + verticalGap?: FormStyleConfig; + outerPadding?: FormStyleConfig; + alignment?: FormAlignmentConfig; +}; diff --git a/packages/codegen-ui/lib/types/index.ts b/packages/codegen-ui/lib/types/index.ts index 435e3855d..e459e1fe1 100644 --- a/packages/codegen-ui/lib/types/index.ts +++ b/packages/codegen-ui/lib/types/index.ts @@ -22,3 +22,5 @@ export * from './properties'; export * from './theme'; export * from './relational-operator'; export * from './studio-schema'; +export * from './form'; +export * from './data';