fix(collection table): support conditional fields in columns schema#1545
Open
Punith1117 wants to merge 1 commit into
Open
fix(collection table): support conditional fields in columns schema#1545Punith1117 wants to merge 1 commit into
Punith1117 wants to merge 1 commit into
Conversation
- Convert conditional field values to their discriminant string when rendering table columns to avoid [object Object] output. - Update column schema typing to include ConditionalField so it can be used in collection column definitions.
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR fixes two issues when using
fields.conditional()in collectioncolumns:columnsarray.[object Object]in the collection list view.Changes
TypeScript support
Updated the
collection()column type definition to allowConditionalFieldentries in addition to the previously supported field types.Runtime rendering
When rendering collection table values, conditional field values are now detected and their
discriminantvalue is displayed instead of coercing the entire object to a string.Before:
[object Object]After:
trueorfalse(or the selected discriminant value for select-based conditional fields).
Testing
Tested with conditional fields using:
true/false)Verified that:
columnswithout TypeScript errors.[object Object].Implementation Notes
While investigating this issue, it became apparent that collection column rendering currently assumes that all column values have a scalar preview representation.
Conditional fields are one of the first structured field types where this assumption breaks. Their stored value is an object, which results in
[object Object]being rendered when the value is coerced to a string.For this fix, the conditional field's discriminant value is used as the column preview because it provides a meaningful scalar representation of the selected condition.
More generally, it may be safer for collection columns to explicitly support only scalar-like field types (and other field types that provide a well-defined preview value) rather than attempting to stringify arbitrary complex structures such as
object,image,file,markdoc, ormdxfields.A more comprehensive long-term solution could be a field-level preview resolver that allows each field type to define how it should be represented in collection columns. However, that appears to be a broader design change and is outside the scope of this PR.
Related
Fixes #1396