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

custom_fields: added custom vocab flag #1109

Merged
merged 1 commit into from
Mar 5, 2024
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 @@ -179,13 +179,27 @@ class CommunityProfileForm extends Component {
};
});
const { customFields } = this.props;
const genericVocabFields = [];

if (customFields.ui && customFields.ui.length > 0) {
customFields.ui.forEach((section) => {
if (section.fields && section.fields.length > 0) {
section.fields.forEach((field) => {
if (field.isGenericVocabulary) {
genericVocabFields.push(field.field);
}
});
}
});
}

// Deserialize custom fields
initialValues = new CustomFieldSerializer({
fieldpath: "custom_fields",
deserializedDefault: {},
serializedDefault: {},
vocabularyFields: customFields.vocabularies,
genericVocabularies: genericVocabFields,
}).deserialize(initialValues);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,39 @@ export class CustomFieldSerializer {
serializedDefault = null,
allowEmpty = false,
vocabularyFields = [],
genericVocabularies = [],
}) {
this.fieldpath = fieldpath;
this.deserializedDefault = deserializedDefault;
this.serializedDefault = serializedDefault;
this.allowEmpty = allowEmpty;
this.vocabularyFields = vocabularyFields;
this.genericVocabularies = genericVocabularies;
}

#mapCustomFields(record, customFields, mapValue) {
if (customFields !== null) {
for (const [key, value] of Object.entries(customFields)) {
const isVocabularyField = this.vocabularyFields.includes(key);
const isGenericVocabulary = this.genericVocabularies.includes(key);
const _value = _isArray(value)
? value.map((v, i) => mapValue(v, i, isVocabularyField))
: mapValue(value, null, isVocabularyField);
? value.map((v, i) => mapValue(v, i, isVocabularyField, isGenericVocabulary))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now the isVocabularyField is quite confusing as name because isGenericVocabulary should also be a vocabulary field. Do you intend to split between generic and custom?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because the custom field we added is a non generic vocabulary, hence why this check was needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then I would clearly rename isVocabularyField with something like isCustomVocabularyField

: mapValue(value, null, isVocabularyField, isGenericVocabulary);
record = _set(record, `custom_fields.${key}`, _value);
}
}
}

deserialize(record) {
const _deserialize = (value, i = undefined, isVocabulary = false) => {
const _deserialize = (
value,
i = undefined,
isVocabulary = false,
isGenericVocabulary = false
) => {
if (isVocabulary && !isGenericVocabulary) {
return value;
}
if (isVocabulary && value?.id) {
return value.id;
}
Expand Down
Loading