From 47189c437cf1308a96e0d7de2a9afb20eb533c42 Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Tue, 21 May 2024 15:50:01 +1200 Subject: [PATCH 1/3] MNT Object for Nested GridField testing --- _config/extensions.yml | 13 ++++++ code/fields/NestedGridField/BranchNode.php | 38 ++++++++++++++++++ code/fields/NestedGridField/LeafNode.php | 24 +++++++++++ .../NestedGridField/NestedGridFieldAdmin.php | 40 +++++++++++++++++++ .../NestedGridField/NonRelationalData.php | 26 ++++++++++++ code/fields/NestedGridField/RootNode.php | 18 +++++++++ .../SecurityAdminExtension.php | 17 ++++++++ 7 files changed, 176 insertions(+) create mode 100644 code/fields/NestedGridField/BranchNode.php create mode 100644 code/fields/NestedGridField/LeafNode.php create mode 100644 code/fields/NestedGridField/NestedGridFieldAdmin.php create mode 100644 code/fields/NestedGridField/NonRelationalData.php create mode 100644 code/fields/NestedGridField/RootNode.php create mode 100644 code/fields/NestedGridField/SecurityAdminExtension.php diff --git a/_config/extensions.yml b/_config/extensions.yml index 6f834a6..f681410 100644 --- a/_config/extensions.yml +++ b/_config/extensions.yml @@ -15,6 +15,19 @@ SilverStripe\FrameworkTest\Model\Employee: extensions: - SilverStripe\FrameworkTest\Extension\TestDataObjectExtension +SilverStripe\FrameworkTest\Fields\NestedGridField\RootNode: + extensions: + - SilverStripe\FrameworkTest\Extension\TestDataObjectExtension +SilverStripe\FrameworkTest\Fields\NestedGridField\BranchNode: + extensions: + - SilverStripe\FrameworkTest\Extension\TestDataObjectExtension +SilverStripe\FrameworkTest\Fields\NestedGridField\LeafNode: + extensions: + - SilverStripe\FrameworkTest\Extension\TestDataObjectExtension +SilverStripe\FrameworkTest\Fields\NestedGridField\NonRelationalData: + extensions: + - SilverStripe\FrameworkTest\Extension\TestDataObjectExtension + SilverStripe\ORM\DatabaseAdmin: extensions: - SilverStripe\FrameworkTest\GridFieldArbitraryData\DatabaseBuildExtension diff --git a/code/fields/NestedGridField/BranchNode.php b/code/fields/NestedGridField/BranchNode.php new file mode 100644 index 0000000..de653f0 --- /dev/null +++ b/code/fields/NestedGridField/BranchNode.php @@ -0,0 +1,38 @@ + 'Varchar(50)', + 'Category' => 'Varchar(50)', + ]; + + private static $has_one = [ + 'RootNode' => RootNode::class, + ]; + + private static $has_many = [ + 'LeafNodes' => LeafNode::class, + ]; + + private static $summary_fields = [ + 'Name', + 'Category', + ]; + + public function getNestedConfig(): GridFieldConfig + { + $config = new GridFieldConfig_RecordEditor(); + $config->addComponent(GridFieldNestedForm::create()->setRelationName('LeafNodes')); + return $config; + } +} diff --git a/code/fields/NestedGridField/LeafNode.php b/code/fields/NestedGridField/LeafNode.php new file mode 100644 index 0000000..e56587d --- /dev/null +++ b/code/fields/NestedGridField/LeafNode.php @@ -0,0 +1,24 @@ + 'Varchar(50)', + 'Category'=>'Varchar(255)', + ]; + + private static $has_one = [ + 'BranchNode' => BranchNode::class, + ]; + + private static $summary_fields = [ + 'Name', + 'Category', + ]; +} diff --git a/code/fields/NestedGridField/NestedGridFieldAdmin.php b/code/fields/NestedGridField/NestedGridFieldAdmin.php new file mode 100644 index 0000000..070be76 --- /dev/null +++ b/code/fields/NestedGridField/NestedGridFieldAdmin.php @@ -0,0 +1,40 @@ + [ + 'title' => 'Root Nodes', + 'dataClass' => RootNode::class, + ], + 'non-relational-data' => [ + 'title' => 'Non-Relational Data', + 'dataClass' => NonRelationalData::class, + ], + ]; + + protected function getGridFieldConfig(): GridFieldConfig + { + $config = parent::getGridFieldConfig(); + if ($this->modelClass === RootNode::class) { + $config->addComponent(GridFieldNestedForm::create()->setRelationName('BranchNodes')); + } else if ($this->modelClass === NonRelationalData::class) { + $config->addComponent(GridFieldNestedForm::create()->setRelationName('getList')); + } else { + throw new RuntimeException("Unexpected Model name: {$this->tab}"); + } + + return $config; + } +} diff --git a/code/fields/NestedGridField/NonRelationalData.php b/code/fields/NestedGridField/NonRelationalData.php new file mode 100644 index 0000000..2b918f8 --- /dev/null +++ b/code/fields/NestedGridField/NonRelationalData.php @@ -0,0 +1,26 @@ + 'Varchar(50)', + ]; + + public function getList() { + $list = ArrayList::create(); + $data = Company::get()->byIDs([1,2,3,4,5]); + foreach ($data as $value) { + $list->push($value); + } + + return $list; + } +} diff --git a/code/fields/NestedGridField/RootNode.php b/code/fields/NestedGridField/RootNode.php new file mode 100644 index 0000000..c265bc4 --- /dev/null +++ b/code/fields/NestedGridField/RootNode.php @@ -0,0 +1,18 @@ + 'Varchar(50)', + ]; + + private static $has_many = [ + 'BranchNodes' => BranchNode::class, + ]; +} diff --git a/code/fields/NestedGridField/SecurityAdminExtension.php b/code/fields/NestedGridField/SecurityAdminExtension.php new file mode 100644 index 0000000..5cd0cd8 --- /dev/null +++ b/code/fields/NestedGridField/SecurityAdminExtension.php @@ -0,0 +1,17 @@ +owner->getModelClass() === Group::class) { + $config->addComponent(GridFieldNestedForm::create()->setRelationName('Members')); + } + } +} From d18f92e411b762de9a86ea1cc23bf7b77633558b Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Tue, 28 May 2024 13:46:12 +1200 Subject: [PATCH 2/3] MNT Change set of ids to limit in NonRelationalData test class --- code/fields/NestedGridField/NonRelationalData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/fields/NestedGridField/NonRelationalData.php b/code/fields/NestedGridField/NonRelationalData.php index 2b918f8..3c77a5a 100644 --- a/code/fields/NestedGridField/NonRelationalData.php +++ b/code/fields/NestedGridField/NonRelationalData.php @@ -16,7 +16,7 @@ class NonRelationalData extends DataObject public function getList() { $list = ArrayList::create(); - $data = Company::get()->byIDs([1,2,3,4,5]); + $data = Company::get()->limit(5); foreach ($data as $value) { $list->push($value); } From 2a6def82c9cfca908d673a34351c9bc131740fa3 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Fri, 31 May 2024 09:48:31 +1200 Subject: [PATCH 3/3] MNT Run module-standardiser (#182) --- .github/workflows/update-js.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-js.yml b/.github/workflows/update-js.yml index 1ca5860..afff16f 100644 --- a/.github/workflows/update-js.yml +++ b/.github/workflows/update-js.yml @@ -2,9 +2,9 @@ name: Update JS on: workflow_dispatch: - # Run on a schedule of once per quarter + # At 4:20 AM UTC, on day 1 of the month, only in March and September schedule: - - cron: '20 4 1 */3 *' + - cron: '20 4 1 3,9 *' permissions: {}