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: skip populate hidden reference #1720

Open
wants to merge 1 commit into
base: master
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
3 changes: 1 addition & 2 deletions src/backend/utils/populator/populator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export async function populator(
const resourceDecorator = records[0].resource.decorate()
const allProperties = Object.values(resourceDecorator.getFlattenProperties())

const references = allProperties.filter((p) => !!p.reference())

const references = allProperties.filter((p) => !!p.reference() && (p.isVisible('show') || p.isVisible('list') || p.isVisible('edit') || p.isVisible('filter')))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can take it a step further and check isVisible only for the current action since it's available in context:
https://github.com/SoftwareBrothers/adminjs/blob/master/src/backend/actions/action.interface.ts#L54

I'm unsure if we'd like to add this restriction though. In actions isVisible is different than isAccessible. Similarly, someone may want to use the ApiClient to fetch record details (show) and they'd like all populated properties to be present.

Ideally, there should be isAccessible in the property options which would tell whether the API should fetch that reference. Setting isAccessible: false should also automatically override isVisible to false since it wouldn't be available.

await Promise.all(references.map(async (propertyDecorator) => {
await populateProperty(records, propertyDecorator, context)
}))
Expand Down