Skip to content

Commit

Permalink
fix field imports in create new
Browse files Browse the repository at this point in the history
  • Loading branch information
elewis2 committed May 1, 2024
1 parent 0d692c8 commit 32aefc5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/components/FormLayout/FieldGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import FormContext from '@/components/FormContext';
import FormField from '@/components/FormField';
import { FORM_VARIANT } from '@/components/util';

import { schema as schemaDefn } from '@bcgsc-pori/graphkb-schema'

/**
* returns an array of strings without any of the indicated exclusion values
*
Expand Down Expand Up @@ -55,7 +57,7 @@ const FieldGroup = ({
model, ordering, exclusions, disabled,
}: FieldGroupProps) => {
const { formVariant, formContent } = useContext(FormContext);
const { properties: { out, in: tgt, ...properties } } = model;
const properties = schemaDefn.getProperties(model.name);

// get the form content
const fields = [];
Expand Down
2 changes: 1 addition & 1 deletion src/components/RecordForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const RecordForm = ({

useEffect(() => {
if (modelName) {
const { properties } = schemaDefn.get(modelName);
const properties = schemaDefn.getProperties(modelName);
setFieldDefs(properties);
setIsEdge(schema.isEdge(modelName));
}
Expand Down
14 changes: 10 additions & 4 deletions src/components/util.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as qs from 'qs';
import { NavigateFunction } from 'react-router-dom';
import { schema as schemaDefn } from '@bcgsc-pori/graphkb-schema';
import { ContactsOutlined } from '@material-ui/icons';

const CLASS_MODEL_PROP = '@class';

Expand Down Expand Up @@ -41,10 +43,14 @@ const sortAndGroupFields = (model, opt = {}) => {

const groupMap = {};

if (!model) {
if (!model || !model.name) {
return { extraFields: [], fields: [] };
}
const { properties } = model;

let properties;
if (model.name) {
properties = schemaDefn.getProperties(model.name);
}

groups.forEach((groupItems) => {
// assume each field only can belong to a single group, overwrite others
Expand All @@ -71,7 +77,7 @@ const sortAndGroupFields = (model, opt = {}) => {

const visited = new Set();

const sortedPropModels = Object.values(model.properties)
const sortedPropModels = Object.values(properties)
.sort((p1, p2) => {
if (p1.mandatory === p2.mandatory || variant === FORM_VARIANT.VIEW) {
return p1.name.localeCompare(p2.name);
Expand Down Expand Up @@ -124,12 +130,12 @@ const sortAndGroupFields = (model, opt = {}) => {
visited.add(...fields);
}
}

return { fields: mainFields, extraFields };
};

const cleanLinkedRecords = (content) => {
const newContent = {};

Object.keys(content).forEach((key) => {
if (content[key] !== undefined) {
if (Array.isArray(content[key])) {
Expand Down

0 comments on commit 32aefc5

Please sign in to comment.