-
Notifications
You must be signed in to change notification settings - Fork 916
[POC] datatable as a component for multiple cruds #5688
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
base: next
Are you sure you want to change the base?
Conversation
d84d59a
to
65aa57b
Compare
39a4912
to
d8b8d16
Compare
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.
Let's
- Polish with the comments here.
- Set up a demo
- used a column in ShowOperation
- used as a widget in ShowOperation
- used in a dashboard as an x-component
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.
Let's call this a datatable
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.
$this->crud->addColumn([
'name' => 'crudColumn',
'type' => 'crud_column',
'controller' => IconCrudController::class,
// OPTIONAL:
// 'afterSetup' => function($crud) {
$crud->addClause();
}
]);
<div id="datatable_button_stack" class="float-right float-end text-right hidden-xs"></div> | ||
</div> | ||
@endif | ||
<x-datatable :crud="$crud" /> | ||
|
||
</div> |
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.
Todo: let's write in the upgrade guide that the list.blade.php
and datatables_logic.blade.php
files have been turned into a datatable
component - if they've made any changes to them, they can delete them from their project and re-do the changes in the component view (after publishing).
} | ||
@endif | ||
|
||
window.crud = { |
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.
Need to test two datatables on the same page.
@@ -0,0 +1,520 @@ | |||
@php |
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.
Ok let's do it. Let's clean up this file a bit - let's take it step-by-step. First: let's remove the PHP from this file.
src/BackpackManager.php
Outdated
|
||
$crud = $this->crud($controller); | ||
|
||
$crud->setOperation('list'); |
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.
🚩 why hard-coded for the list operatin? In the future, we should be able to use BackpackManager to load a Form component, right?
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.
Maybe....
getOperationFromController(string $controller, string $operation)
Or maybe we move this line to a separate method?! 🤷♂️
src/BackpackManager.php
Outdated
return isset($this->cruds[$controller]); | ||
} | ||
|
||
public function getControllerCrud(string $controller): CrudPanel |
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.
let's think more about the names 🤷♂️
[ci skip] [skip ci]
[ci skip] [skip ci]
@@ -62,16 +62,19 @@ function updatePageUrl(filterName, filterValue, currentUrl = null) { | |||
} | |||
|
|||
if(typeof updateDatatablesOnFilterChange !== 'function') { |
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.
Todo: after the review, we should probably move this JS logic from the FILTERS blade file... to the DATATABLES blade file. Right? I mean... filters are a general-purpose feature... that is supported by whatever operation wants to support them.
DataTables - as a component and as an operation... chooses to support the filters. So the logic that says "when filter does X datatables does Y" should probably live in the DATATABLE, not in the FILTERS.
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.
But right now it's ok here, just to keep the diff minimal. We can create a different PR that moves code around. Like a cleanup PR.
src/Backpack.php
Outdated
@@ -0,0 +1,16 @@ | |||
<?php |
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.
Help me understand... what will this facade facilitate - what kind of calls? I'm wondering whether we need a Facade at all... or whether we should change its name.
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.
Is it to do stuff like Backpack::getActiveController
and Backpack::getCrud()
? If so... I think we're better of doing CrudManager::getActiveController()
and CrudManager::getCrud()
.
I wouldn't expand this feature so much as to identify it with the Backpack name. It would prevent us from using the Backpack class for anything else in the future.
Backpack::setControllerCrud(get_class($this), $crudPanel); | ||
} | ||
|
||
private function triggerControllerHooks() |
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.
I think this is a bad name for this function. Sure, it triggers the controller hooks... but that's just the SMALL part of what it does. What it does MORE IMPORTANTLY is to... setup the crud controller? O what is it? Cause I see it's calling the general-purpose setup methods like setupDefaults()
and setup()
but it's also calling setupConfigurationForCurrentOperation()
which is an operation-thing.
Perhaps we call this method:
private function triggerControllerHooks() | |
private function setupCrudController() |
If you don't have a better name for it.
LifecycleHook::trigger('crud:before_setup', [$this]); | ||
$this->setup(); | ||
LifecycleHook::trigger('crud:after_setup', [$this]); | ||
$this->initialized = true; |
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.
Something's fishy here. I see that we have a function called initializeCrud()
but we are also doing $this->initialized=true
outside of it. That is fishy. How can we refactor this bit of code so it's cleaner?
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.
I have a feeling we could/should move ALL of the logic in the constructor to the initializeCrud()
method.
And maybe we call it initialize()
- with an optional parameter. Since it sets the initialized
property on the CrudController... it isn't initializing the CRUD... but the CrudController, right?
[ci skip] [skip ci]
[ci skip] [skip ci]
This is a very early POC about something me and @tabacitu are exploring.
What we are trying to achieve here, can be summed up in the following way:
They way Backpack was built from start, although simple, comes with some limitations. Now that we want to introduce more advanced features we'd need to do major refactors of the software, that would take months for us to develop, and a lot of time for our users to upgrade.
We are always exploring the possibility of changing something internal that would allow us to do more advanced things, without the cost for the developers that use our software.
That said, one of the most requested features and needs we had, was to have a "relation table", without having to develop a new table from scratch, given how much effort we already spent on the Datatable/columns, and the huge amount of features we have on both of them.
Without much to add for the moment, we will need to decide on the direction we would like to take, here is a screenshot of somewhat we want to achieve:
All of that, with the simplicity we aim for our software:
At the moment there are 0 breaking changes, but also stuff that does no properly work. This is very very wip, we may find something that would require a major breaking change that we are not willing to do for the next version .. but it's a start. 👍