-
Notifications
You must be signed in to change notification settings - Fork 34
FOUR-32638: Fix Collection record list fields and values #1927
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
Open
eiresendez
wants to merge
2
commits into
develop
Choose a base branch
from
task/FOUR-32638-FOUR-32640
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| const COLLECTION_DATA_PREFIX = "data."; | ||
|
|
||
| export function normalizeCollectionFieldPath(fieldPath) { | ||
| if (typeof fieldPath !== "string") { | ||
| return fieldPath; | ||
| } | ||
|
|
||
| return fieldPath.startsWith(COLLECTION_DATA_PREFIX) | ||
| ? fieldPath.slice(COLLECTION_DATA_PREFIX.length) | ||
| : fieldPath; | ||
| } | ||
|
|
||
| export function getCollectionFieldOptions(collection = {}) { | ||
| const options = []; | ||
| const values = new Set(); | ||
|
|
||
| const addOption = ({ text, value }) => { | ||
| const normalizedValue = normalizeCollectionFieldPath(value); | ||
|
|
||
| if (!normalizedValue || values.has(normalizedValue)) { | ||
| return; | ||
| } | ||
|
|
||
| values.add(normalizedValue); | ||
| options.push({ | ||
| text: text || normalizedValue, | ||
| value: normalizedValue | ||
| }); | ||
| }; | ||
|
|
||
| if (Array.isArray(collection?.fields) && collection.fields.length > 0) { | ||
| collection.fields.forEach((field) => { | ||
| if (!field) { | ||
| return; | ||
| } | ||
|
|
||
| addOption({ | ||
| text: field.text || field.value, | ||
| value: field.value | ||
| }); | ||
| }); | ||
| } else { | ||
| const [firstRecord] = collection?.dataRecordList || []; | ||
|
|
||
| if (firstRecord?.data) { | ||
| Object.keys(firstRecord.data).forEach((field) => { | ||
| addOption({ text: field, value: field }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| addOption({ text: "id", value: "id" }); | ||
|
|
||
| return options; | ||
| } | ||
|
|
||
| export function mapCollectionRecordData(data = {}, options = []) { | ||
| if (!data || typeof data !== "object" || Array.isArray(data)) { | ||
| return {}; | ||
| } | ||
|
|
||
| if (!Array.isArray(options) || options.length === 0) { | ||
| return { ...data }; | ||
| } | ||
|
|
||
| const mappedData = {}; | ||
|
|
||
| options.forEach((option) => { | ||
| if (!option) { | ||
| return; | ||
| } | ||
|
|
||
| const targetKey = normalizeCollectionFieldPath( | ||
| option.key || option.content | ||
| ); | ||
| const sourceKey = [option.content, option.key] | ||
| .map(normalizeCollectionFieldPath) | ||
| .find( | ||
| (candidate) => | ||
| candidate && Object.prototype.hasOwnProperty.call(data, candidate) | ||
| ); | ||
|
|
||
| if (sourceKey && targetKey) { | ||
| mappedData[targetKey] = data[sourceKey]; | ||
| } | ||
| }); | ||
|
|
||
| return mappedData; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapCollectionRecordDataonly reads keys fromcolumn.data, but Collection API records expose the systemidon the parent object ({ id, data: { ...fields } }), not insidedata. After this PR always offersidas a column, Preview/table cells for that column stay empty for real Collection payloads.The Cypress fixture masks this by putting
idinsidedata({ id: recordData.id, data: recordData }whererecordDataalso containsid).Impact: Users can select the
idcolumn (or All columns includingid), but Preview and runtime Record Lists will show blankidvalues against real/collections/{id}/recordsresponses.Suggested Fix: Before mapping, merge the record-level id into the payload, e.g.
mapCollectionRecordData({ ...(column.data || {}), ...(column.id != null ? { id: column.id } : {}) }, optionsList). Also update the Cypress intercept sodatadoes not includeid, and assert Preview still renders the parent record id.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CarliPinell Thanks for flagging this.
I verified the current Collection API contract:
CollectionsApiCollectionexplicitly copies the parent record ID intodata.idbefore returning records (source). I also confirmed that a real/api/1.0/collections/2/recordsresponse contains matching IDs at bothrecord.idandrecord.data.id, so the Cypress fixture mirrors the production payload and Preview can map id from column.data. Could you share the endpoint or payload where id exists only on the parent? If that shape exists, I can add compatibility coverage; otherwise, no code change should be needed here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! thanks.