QQQ-30: got rid of 'prettier', first pass at eslint configuration pointing only to qqq specific files, reformated all qqq files

This commit is contained in:
Tim Chamberlain
2022-07-12 11:35:24 -05:00
parent cc324fd76d
commit 87d3f070fe
26 changed files with 2099 additions and 1959 deletions

View File

@ -30,11 +30,14 @@ interface Props {
primaryKeyId?: string;
}
function QDynamicForm(props: Props): JSX.Element {
const { formData, formLabel, primaryKeyId } = props;
const { formFields, values, errors, touched } = formData;
function QDynamicForm(props: Props): JSX.Element
{
const { formData, formLabel, primaryKeyId } = props;
const {
formFields, values, errors, touched,
} = formData;
/*
/*
const {
firstName: firstNameV,
lastName: lastNameV,
@ -45,42 +48,45 @@ function QDynamicForm(props: Props): JSX.Element {
} = values;
*/
return (
<MDBox>
<MDBox lineHeight={0}>
<MDTypography variant="h5">{formLabel}</MDTypography>
{/* TODO - help text
return (
<MDBox>
<MDBox lineHeight={0}>
<MDTypography variant="h5">{formLabel}</MDTypography>
{/* TODO - help text
<MDTypography variant="button" color="text">
Mandatory information
</MDTypography>
*/}
</MDBox>
<MDBox mt={1.625}>
<Grid container spacing={3}>
{formFields &&
Object.keys(formFields).length > 0 &&
Object.keys(formFields).map((fieldName: any) => {
const field = formFields[fieldName];
if (primaryKeyId && fieldName === primaryKeyId) {
return null;
}
if (values[fieldName] === undefined) {
values[fieldName] = "";
}
return (
<Grid item xs={12} sm={6} key={fieldName}>
<FormField
type={field.type}
label={field.label}
name={fieldName}
value={values[fieldName]}
error={errors[fieldName] && touched[fieldName]}
/>
</Grid>
);
</MDBox>
<MDBox mt={1.625}>
<Grid container spacing={3}>
{formFields
&& Object.keys(formFields).length > 0
&& Object.keys(formFields).map((fieldName: any) =>
{
const field = formFields[fieldName];
if (primaryKeyId && fieldName === primaryKeyId)
{
return null;
}
if (values[fieldName] === undefined)
{
values[fieldName] = "";
}
return (
<Grid item xs={12} sm={6} key={fieldName}>
<FormField
type={field.type}
label={field.label}
name={fieldName}
value={values[fieldName]}
error={errors[fieldName] && touched[fieldName]}
/>
</Grid>
);
})}
</Grid>
{/*
</Grid>
{/*
<Grid container spacing={3}>
<Grid item xs={12} sm={6}>
<FormField
@ -154,14 +160,14 @@ function QDynamicForm(props: Props): JSX.Element {
</Grid>
</Grid>
*/}
</MDBox>
</MDBox>
</MDBox>
);
);
}
QDynamicForm.defaultProps = {
formLabel: undefined,
primaryKeyId: undefined,
formLabel: undefined,
primaryKeyId: undefined,
};
export default QDynamicForm;

View File

@ -30,51 +30,56 @@ import { QFieldType } from "@kingsrook/qqq-frontend-core/lib/model/metaData/QFie
** Meta-data to represent a single field in a table.
**
*******************************************************************************/
class DynamicFormUtils {
public static getFormData(qqqFormFields: QFieldMetaData[]) {
const dynamicFormFields: any = {};
const formValidations: any = {};
class DynamicFormUtils
{
public static getFormData(qqqFormFields: QFieldMetaData[])
{
const dynamicFormFields: any = {};
const formValidations: any = {};
qqqFormFields.forEach((field) => {
let fieldType: string;
switch (field.type.toString()) {
case QFieldType.DECIMAL:
case QFieldType.INTEGER:
fieldType = "number";
break;
case QFieldType.DATE_TIME:
fieldType = "datetime-local";
break;
case QFieldType.PASSWORD:
case QFieldType.TIME:
case QFieldType.DATE:
fieldType = field.type.toString();
break;
case QFieldType.TEXT:
case QFieldType.HTML:
case QFieldType.STRING:
default:
fieldType = "text";
}
qqqFormFields.forEach((field) =>
{
let fieldType: string;
switch (field.type.toString())
{
case QFieldType.DECIMAL:
case QFieldType.INTEGER:
fieldType = "number";
break;
case QFieldType.DATE_TIME:
fieldType = "datetime-local";
break;
case QFieldType.PASSWORD:
case QFieldType.TIME:
case QFieldType.DATE:
fieldType = field.type.toString();
break;
case QFieldType.TEXT:
case QFieldType.HTML:
case QFieldType.STRING:
default:
fieldType = "text";
}
let label = field.label ? field.label : field.name;
label += field.isRequired ? " *" : "";
let label = field.label ? field.label : field.name;
label += field.isRequired ? " *" : "";
dynamicFormFields[field.name] = {
name: field.name,
label: label,
isRequired: field.isRequired,
type: fieldType,
// todo invalidMsg: "Zipcode is not valid (e.g. 70000).",
};
dynamicFormFields[field.name] = {
name: field.name,
label: label,
isRequired: field.isRequired,
type: fieldType,
// todo invalidMsg: "Zipcode is not valid (e.g. 70000).",
};
if (field.isRequired) {
formValidations[field.name] = Yup.string().required(`${field.label} is required.`);
}
});
if (field.isRequired)
{
formValidations[field.name] = Yup.string().required(`${field.label} is required.`);
}
});
return { dynamicFormFields, formValidations };
}
return { dynamicFormFields, formValidations };
}
}
export default DynamicFormUtils;