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

Fix/ab#88348 grid does not support is primitive value unchecked #1000

Open
wants to merge 2 commits into
base: 2.x.x
Choose a base branch
from
Open
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
36 changes: 34 additions & 2 deletions src/utils/schema/resolvers/Query/all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLError } from 'graphql';
import { Record, ReferenceData, User } from '@models';
import { Record, ReferenceData, User, Form } from '@models';
import extendAbilityForRecords from '@security/extendAbilityForRecords';
import { decodeCursor, encodeCursor } from '@schema/types';
import getReversedFields from '../../introspection/getReversedFields';
Expand Down Expand Up @@ -706,14 +706,46 @@ export default (entityName: string, fieldsByName: any, idsByName: any) =>
}
}

// List of non-primitive reference data questions
const primitiveReferenceDataFields = [];
// Retrieve the form to get the complete structure
const form = await Form.findOne({
resource: id,
graphQLTypeName: entityName,
});
const formStructure = form?.structure && JSON.parse(form.structure);
if (formStructure) {
// Flatten the structure into a single-level array of questions
const flatElements = formStructure.pages.flatMap(
(page) => page.elements
);
// Find the non-primitive questions
fields.forEach((field) => {
const element = flatElements.find(
(el) => el.name === field.name && el.isPrimitiveValue === false
);
if (element) {
primitiveReferenceDataFields.push(element);
}
});
}

// === CONSTRUCT OUTPUT + RETURN ===
const edges = items.map((r) => {
const record = getAccessibleFields(r, ability);
Object.assign(record, { id: record._id });
const node = display ? { ...record, display, fields } : record;
// Change the non-primitive questions format to make it reusable
primitiveReferenceDataFields.forEach((field) => {
const fieldValue = node.data[field.name]?.value;
if (fieldValue?.id) {
node.data[field.name] = fieldValue.id;
}
});

return {
cursor: encodeCursor(record.id.toString()),
node: display ? Object.assign(record, { display, fields }) : record,
node: node,
meta: {
style: getStyle(r, styleRules),
raw: record.data,
Expand Down
Loading