Skip to content

Commit

Permalink
fix: remove functions imported from devDep
Browse files Browse the repository at this point in the history
  • Loading branch information
Hein Jeong authored and hein-j committed Jan 4, 2023
1 parent 02b2dc2 commit d7544bd
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/codegen-ui-golden-files/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
ConcatenatedStudioComponentProperty,
} from '@aws-amplify/codegen-ui';
import { StudioFormInputFieldProperty } from '@aws-amplify/codegen-ui/lib/types/form/input-config';
import { isEnumFieldType } from '@aws-amplify/datastore';
import {
Expression,
factory,
Expand All @@ -44,7 +43,7 @@ import {
} from '../../react-component-render-helper';
import { buildAccessChain, getRecordsName } from './form-state';
import { getElementAccessExpression, getValidProperty } from './invalid-variable-helpers';
import { isModelDataType } from './render-checkers';
import { isEnumDataType, isModelDataType } from './render-checkers';

export const getDisplayValueObjectName = 'getDisplayValue';

Expand Down Expand Up @@ -450,7 +449,7 @@ export function buildDisplayValueFunction(fieldName: string, fieldConfig: FieldC
}
}

if (isEnumFieldType(fieldConfig.dataType) && fieldConfig.valueMappings && fieldConfig.isArray) {
if (isEnumDataType(fieldConfig) && fieldConfig.valueMappings && fieldConfig.isArray) {
const displayValueMapName = `enumDisplayValueMap`;
additionalStatements = [
factory.createVariableStatement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
limitations under the License.
*/
import { FieldConfigMetadata } from '@aws-amplify/codegen-ui';
import { isEnumFieldType } from '@aws-amplify/datastore';

export const shouldWrapInArrayField = (config: FieldConfigMetadata): boolean => config.isArray || !!config.relationship;

Expand All @@ -23,8 +22,13 @@ export const isModelDataType = (
): config is FieldConfigMetadata & { dataType: { model: string } } =>
!!(config.dataType && typeof config.dataType === 'object' && 'model' in config.dataType);

export const isEnumDataType = (
config: FieldConfigMetadata,
): config is FieldConfigMetadata & { dataType: { enum: string } } =>
!!(config.dataType && typeof config.dataType === 'object' && 'enum' in config.dataType);

export const shouldImplementDisplayValueFunction = (config: FieldConfigMetadata): boolean => {
return isModelDataType(config) || (isEnumFieldType(config.dataType) && shouldWrapInArrayField(config));
return isModelDataType(config) || (isEnumDataType(config) && shouldWrapInArrayField(config));
};

export const shouldImplementIDValueFunction = (config: FieldConfigMetadata): boolean => {
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen-ui-react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/codegen-ui/lib/utils/form-component-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { isEnumFieldType } from '@aws-amplify/datastore';
import { camelCase } from 'change-case';

import {
Expand Down Expand Up @@ -93,7 +92,11 @@ export const mapFormMetadata = (form: StudioForm, formDefinition: FormDefinition
});
}

if ((element.relationship || isEnumFieldType(element.dataType)) && 'valueMappings' in element) {
if (
(element.relationship ||
(element.dataType && typeof element.dataType === 'object' && 'enum' in element.dataType)) &&
'valueMappings' in element
) {
metadata.valueMappings = element.valueMappings;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/codegen-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/test-generator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7544bd

Please sign in to comment.