Skip to content

Commit

Permalink
chore: add form-related types (#469)
Browse files Browse the repository at this point in the history
Co-authored-by: Hein Jeong <heinje@amazon.com>
  • Loading branch information
hein-j and Hein Jeong authored May 31, 2022
1 parent 3259128 commit 7c46670
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/codegen-ui/lib/types/data.ts
Original file line number Diff line number Diff line change
@@ -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;
};
46 changes: 46 additions & 0 deletions packages/codegen-ui/lib/types/form/fields.ts
Original file line number Diff line number Diff line change
@@ -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;
};
39 changes: 39 additions & 0 deletions packages/codegen-ui/lib/types/form/form-definition.ts
Original file line number Diff line number Diff line change
@@ -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[][];
};
44 changes: 44 additions & 0 deletions packages/codegen-ui/lib/types/form/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
59 changes: 59 additions & 0 deletions packages/codegen-ui/lib/types/form/input-config.ts
Original file line number Diff line number Diff line change
@@ -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;
16 changes: 16 additions & 0 deletions packages/codegen-ui/lib/types/form/position.ts
Original file line number Diff line number Diff line change
@@ -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 };
42 changes: 42 additions & 0 deletions packages/codegen-ui/lib/types/form/sectional-element.ts
Original file line number Diff line number Diff line change
@@ -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
);
33 changes: 33 additions & 0 deletions packages/codegen-ui/lib/types/form/style.ts
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 2 additions & 0 deletions packages/codegen-ui/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export * from './properties';
export * from './theme';
export * from './relational-operator';
export * from './studio-schema';
export * from './form';
export * from './data';

0 comments on commit 7c46670

Please sign in to comment.