-
Notifications
You must be signed in to change notification settings - Fork 725
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
[RFR] Preload references in refrenced_list entries #688
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function maReferenceColumn() { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
field: '&', | ||
value: '&', | ||
datastore: '&' | ||
}, | ||
link: { | ||
pre: function(scope) { | ||
const value = scope.value(); | ||
scope.field = scope.field(); | ||
scope.targetEntity = scope.field.targetEntity(); | ||
scope.targetField = scope.field.targetField(); | ||
const identifierName = scope.targetEntity.identifier().name() | ||
scope.referencedEntry = scope.datastore() | ||
.getEntries(scope.targetEntity.uniqueId + '_values') | ||
.filter(entry => entry.values[identifierName] == value) | ||
.pop(); | ||
} | ||
}, | ||
template: '<ma-column field="::targetField" entry="::referencedEntry" entity="::targetEntity" datastore="::datastore()"></ma-column>' | ||
}; | ||
} | ||
|
||
maReferenceColumn.$inject = []; | ||
|
||
export default maReferenceColumn; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,9 @@ function maReferencedListColumn(NgAdminConfiguration) { | |
<ma-datagrid name="{{ field.datagridName() }}" | ||
entries="::entries" | ||
fields="::field.targetFields()" | ||
list-actions="::field.listActions()" | ||
entity="::entity"> | ||
list-actions="::field.listActions()" | ||
entity="::entity" | ||
datastore="::datastore()"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we retrieve There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got my response IRL: we can't remove entries, as this is the only way to keep entry ids. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, but we'd need to pass an array of ids and a type to let the datagrid retrieve the entries from the datastore... not ideal. |
||
</ma-datagrid>` | ||
}; | ||
} | ||
|
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.
===
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.
Assuming that the APIs we fetch are consistent (i.e. that the type of
comment.post_id
is the same as the type ofpost.id
) is pretty brave, but I think we'd rather be tolerant to ease compatibility. So e.g. whencomment.post_id
is'1'
andpost.id
is1
, the current code works.