Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema: Autofocus related model field & prevent referencing own model #1909

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface InputField {
tooltip?: string;
validate?: Validation[];
inputType?: InputType;
autoFocus?: boolean;
}
export interface DropdownOptions {
label: string;
Expand Down Expand Up @@ -175,7 +176,7 @@ export const FieldFormInput = ({
)}
</Box>
<InputTextField
autoFocus={fieldConfig.name === "label"}
autoFocus={fieldConfig.autoFocus}
data-cy={`FieldFormInput_${fieldConfig.name}`}
name={fieldConfig.name}
required={fieldConfig.required}
Expand Down Expand Up @@ -297,6 +298,7 @@ export const FieldFormInput = ({
{...params}
placeholder={fieldConfig.placeholder}
hiddenLabel
autoFocus={fieldConfig.autoFocus}
/>
)}
isOptionEqualToValue={(option, value) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useState, useEffect, useMemo } from "react";
import { useParams } from "react-router";
import { useDispatch } from "react-redux";
import {
Expand Down Expand Up @@ -126,16 +126,25 @@ export const FieldForm = ({

const isUpdateField = !isEmpty(fieldData);
const isInbetweenField = sortIndex !== null;
const modelsOptions: DropdownOptions[] = allModels?.map((model) => ({
label: model.label,
value: model.ZUID,
}));
const fieldsOptions: DropdownOptions[] = selectedModelFields?.map(
(field) => ({
const modelsOptions: DropdownOptions[] = useMemo(() => {
// Remove the model that the field is from
const _filteredModels = allModels?.filter((model) => model.ZUID !== id);

return _filteredModels?.map((model) => {
if (model.ZUID !== id) {
return {
label: model.label,
value: model.ZUID,
};
}
});
}, [allModels]);
const fieldsOptions: DropdownOptions[] = useMemo(() => {
return selectedModelFields?.map((field) => ({
label: field.label,
value: field.ZUID,
})
);
}));
}, [selectedModelFields]);
const [
deleteContentModelField,
{ isLoading: isDeletingField, isSuccess: isFieldDeleted },
Expand Down Expand Up @@ -190,7 +199,8 @@ export const FieldForm = ({
}
} else {
if (field.type === "checkbox") {
formFields[field.name] = true;
// Only "list" checkbox will be checked by default
formFields[field.name] = field.name === "list";
} else if (field.type === "options") {
formFields[field.name] = [{ "": "" }];
} else if (field.type === "toggle_options") {
Expand Down
15 changes: 13 additions & 2 deletions src/apps/schema/src/appRevamp/components/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ const COMMON_FIELDS: InputField[] = [
gridSize: 12,
tooltip: "The display name of the field seen in Schema.",
validate: ["required", "length"],
autoFocus: true,
},
{
name: "name",
Expand Down Expand Up @@ -483,6 +484,7 @@ const FORM_CONFIG: { [key: string]: FormConfig } = {
required: false,
gridSize: 6,
placeholder: "Select a model",
autoFocus: true,
},
{
name: "relatedFieldZUID",
Expand All @@ -492,7 +494,11 @@ const FORM_CONFIG: { [key: string]: FormConfig } = {
gridSize: 6,
placeholder: "Select a field",
},
...COMMON_FIELDS,
{
...COMMON_FIELDS[0],
autoFocus: false,
},
...COMMON_FIELDS.slice(1),
],
rules: [],
},
Expand All @@ -505,6 +511,7 @@ const FORM_CONFIG: { [key: string]: FormConfig } = {
required: false,
gridSize: 6,
placeholder: "Select a model",
autoFocus: true,
},
{
name: "relatedFieldZUID",
Expand All @@ -514,7 +521,11 @@ const FORM_CONFIG: { [key: string]: FormConfig } = {
gridSize: 6,
placeholder: "Select a field",
},
...COMMON_FIELDS,
{
...COMMON_FIELDS[0],
autoFocus: false,
},
...COMMON_FIELDS.slice(1),
],
rules: [],
},
Expand Down