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

Conversation

saputradharma
Copy link

Supporting to skip loading invisible reference property.

Currently, it loads all of the related resources even though the property has been set as isVisible: false which will result to unnecessary data load and query.

@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants