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

[WIP-discussion] Allow show operation to use the panel query #5271

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Aug 9, 2023

WHY

BEFORE - What was wrong? What was happening before this PR?

Heads up: This is working, but it's just a POC to be discussed. We may need to add documentation about it if we decide to do it.

Reported in #5204 and we also had some discussions about it.

In my understanding, and the user reporting the issue, all the operations should be performing their queries over the Panel Query. This would be a huge change in behavior and we may miss use cases that we will break doing such a global change on a non-breaking version.

AFTER - What is happening after this PR?

I've thought about this for a while and decided to "experiment" with the feature in the show operation behind a configuration.

I think this is the way to go now, without risking breaking all people apps. We may eventually turn it true by default in a future version.

HOW

How did you achieve that, in technical terms?

I introduced the usePanelQuery config in show operation, that will tell the operation if it should perform the findOrFail in the model, or in panel query.

Is it a breaking change?

I don't think so no, it need to be enabled.

How can we test the before & after?

Steps described in the linked issue. But to sum up, create a constrain on the crud query and watch it being applied in the List but not in the show operation.

pxpm and others added 2 commits August 9, 2023 15:10
@pxpm pxpm assigned tabacitu and pxpm Aug 9, 2023
@pxpm pxpm added Priority: SHOULD Minor Bug A bug that happens only in a very niche or specific use case. labels Aug 9, 2023
Copy link
Member

@tabacitu tabacitu left a comment

Choose a reason for hiding this comment

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

I like the approach yes. A bit scared to do it, but yeah, we should probably do something like this. Only one question

$this->data['title'] = $this->crud->getTitle() ?? trans('backpack::crud.preview').' '.$this->crud->entity_name;
if ($this->crud->get('show.usePanelQuery')) {
$this->data['entry'] = $this->crud->query->withTrashed()->findOrFail($id);
$this->data['entry'] = $this->crud->setLocaleOnModel($this->data['entry']);
Copy link
Member

Choose a reason for hiding this comment

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

Uuuu what does THIS button do?!

working-cartoon-network-gif

And why is this needed here? And only here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. Writing a descriptive comment for you 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... something here is fishy to me. Why aren't we using getEntryWithLocale() and we are using setLocaleOnModel()? Looks to me like we're using a setter, instead of a getter.

Copy link
Member

Choose a reason for hiding this comment

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

Would this do the same thing or no?

Suggested change
$this->data['entry'] = $this->crud->setLocaleOnModel($this->data['entry']);
$this->data['entry'] = $this->crud->getEntryWithLocale($id);

@tabacitu tabacitu assigned tabacitu and unassigned tabacitu Aug 9, 2023
pxpm and others added 2 commits August 9, 2023 16:35
@tabacitu tabacitu removed their assignment Sep 27, 2023
@tabacitu
Copy link
Member

Back to you @pxpm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Bug A bug that happens only in a very niche or specific use case. Priority: SHOULD
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants