-
-
Notifications
You must be signed in to change notification settings - Fork 213
Introducing abstract for DataModel #1213
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: master
Are you sure you want to change the base?
Conversation
WalkthroughAdds an AbstractDataModel base class with event callback arrays and abstract filter methods; DataModel now extends it and no longer exposes those properties. Introduces RestDataModel implementation. Datagrid and aggregation checks updated to depend on AbstractDataModel. IDataSource::getData() return type changed from iterable to array. phpstan.neon ignore rules updated. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Datagrid
participant DataModel as AbstractDataModel
participant IDataSource
Client->>Datagrid: setDataSource(source)
Datagrid->>Datagrid: create DataModel / RestDataModel
Datagrid->>Datagrid: setDataModel(AbstractDataModel)
Datagrid->>DataModel: wire onBeforeFilter/onAfterFilter/onAfterPaginated
Client->>Datagrid: render()
Datagrid->>DataModel: filterData(paginator?, sorting, filters)
DataModel->>DataModel: emit onBeforeFilter[]
DataModel->>IDataSource: getData() / apply filters & sorting
DataModel->>DataModel: emit onAfterFilter[]
alt paginator provided
DataModel->>IDataSource: apply pagination (limit/offset)
DataModel->>DataModel: emit onAfterPaginated[]
end
DataModel-->>Datagrid: return filtered data (array/iterable)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code graph analysis (6)src/RestDataModel.php (5)
src/DataSource/IDataSource.php (8)
src/Datagrid.php (2)
src/DataModel.php (2)
src/AggregationFunction/TDatagridAggregationFunction.php (2)
src/AbstractDataModel.php (4)
🔇 Additional comments (11)
Comment |
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
phpstan.neon(1 hunks)src/AbstractDataModel.php(1 hunks)src/AggregationFunction/TDatagridAggregationFunction.php(2 hunks)src/DataModel.php(2 hunks)src/DataSource/IDataSource.php(1 hunks)src/Datagrid.php(4 hunks)src/RestDataModel.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
src/AbstractDataModel.php (5)
src/Datagrid.php (2)
Datagrid(79-2969)getDataSource(504-509)src/Components/DatagridPaginator/DatagridPaginator.php (1)
DatagridPaginator(22-119)src/Utils/Sorting.php (1)
Sorting(5-32)src/DataModel.php (3)
getDataSource(85-88)filterData(90-120)filterRow(122-128)src/RestDataModel.php (3)
getDataSource(19-22)filterData(24-52)filterRow(54-60)
src/DataSource/IDataSource.php (8)
src/DataSource/DoctrineDataSource.php (1)
getData(89-102)src/DataSource/DibiFluentDataSource.php (1)
getData(37-40)src/DataSource/ArrayDataSource.php (1)
getData(41-44)src/DataSource/NetteDatabaseTableDataSource.php (1)
getData(59-64)src/DataSource/NextrasDataSource.php (1)
getData(39-47)src/DataSource/ElasticsearchDataSource.php (1)
getData(54-64)src/DataSource/DoctrineCollectionDataSource.php (1)
getData(48-51)src/DataSource/ApiDataSource.php (1)
getData(37-47)
src/Datagrid.php (2)
src/AbstractDataModel.php (1)
AbstractDataModel(14-32)src/DataModel.php (1)
DataModel(32-130)
src/AggregationFunction/TDatagridAggregationFunction.php (1)
src/AbstractDataModel.php (1)
AbstractDataModel(14-32)
src/DataModel.php (2)
src/AbstractDataModel.php (2)
AbstractDataModel(14-32)filterRow(30-30)src/RestDataModel.php (1)
filterRow(54-60)
src/RestDataModel.php (5)
src/Components/DatagridPaginator/DatagridPaginator.php (1)
DatagridPaginator(22-119)src/Utils/Sorting.php (1)
Sorting(5-32)src/AbstractDataModel.php (4)
AbstractDataModel(14-32)getDataSource(26-26)filterData(28-28)filterRow(30-30)src/DataModel.php (4)
__construct(39-83)getDataSource(85-88)filterData(90-120)filterRow(122-128)src/DataSource/IDataSource.php (6)
filter(26-26)sort(49-49)limit(42-42)getData(19-19)getCount(14-14)filterOne(33-33)
🔇 Additional comments (11)
src/DataModel.php (2)
32-32: LGTM: DataModel now properly extends AbstractDataModel.The inheritance hierarchy is well-structured, moving event callbacks and abstract method contracts to the base class.
122-128: LGTM: Return type correctly updated to array.The return type change from
mixedtoarrayaligns with the AbstractDataModel contract and the updated IDataSource.getData() signature.phpstan.neon (1)
33-39: LGTM: PHPStan ignoreErrors correctly updated to AbstractDataModel.The error suppressions now reference the new abstract base class, aligning with the type changes in Datagrid.
src/AggregationFunction/TDatagridAggregationFunction.php (1)
5-5: LGTM: Type constraint correctly updated to AbstractDataModel.The instanceof check now accepts any AbstractDataModel implementation (DataModel or RestDataModel), properly supporting the new abstraction.
Also applies to: 30-32
src/RestDataModel.php (2)
14-22: LGTM: Clean constructor accepting IDataSource directly.RestDataModel provides a simpler alternative to DataModel by accepting an IDataSource directly, whereas DataModel wraps various data source types. This is a good separation of concerns.
54-60: LGTM: filterRow implementation is correct.The single-row filtering logic properly fires lifecycle hooks and returns the filtered data as an array.
src/AbstractDataModel.php (1)
17-24: LGTM: Event callback arrays follow Nette patterns.The public event callback arrays with PHPDoc magic method annotations follow standard Nette framework conventions for event handling.
src/Datagrid.php (3)
186-186: LGTM: Property type correctly updated to AbstractDataModel.The type change enables Datagrid to work with both DataModel and RestDataModel implementations, properly supporting the new abstraction.
347-349: LGTM: Validation correctly checks for AbstractDataModel.The instanceof check appropriately validates that a data model (of any implementation) has been set before rendering.
486-502: LGTM: Well-structured refactoring with proper event wiring.The refactoring properly separates concerns:
setDataSource()wraps various source types in DataModel and delegates tosetDataModel()setDataModel()accepts any AbstractDataModel and wires lifecycle event callbacksThe event wiring connects the data model's hooks to the aggregation function handlers from TDatagridAggregationFunction trait.
src/DataSource/IDataSource.php (1)
19-19: All IDataSource implementations already return array type — interface change is compatible.Verification confirms that all 9 implementations (DoctrineDataSource, ArrayDataSource, NetteDatabaseTableDataSource, NetteDatabaseTableMssqlDataSource, ApiDataSource, NextrasDataSource, ElasticsearchDataSource, DibiFluentDataSource, and DoctrineCollectionDataSource) already return
arrayfromgetData(). The change fromiterabletoarrayin the interface is a safe narrowing of the contract and compatible with all existing implementations.
dac043d to
a7ae51f
Compare
Summary by CodeRabbit