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

Init Admin ui package #20

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ jobs:
fail-fast: false
matrix:
php: [ "8.1", "8.2", "8.3" ]
postgres: ["14.6"]
symfony: [ "^6.4", "^7.0" ]
exclude:
- php: "8.1"
symfony: "^7.0"
name: "PHP ${{ matrix.php }} / Symfony ${{ matrix.symfony }}"
env:
APP_ENV: test
DATABASE_URL: "pgsql://postgres:[email protected]/sylius_stack?charset=utf8&serverVersion=${{ matrix.postgres }}"
steps:
- name: "Checkout"
uses: actions/checkout@v3
Expand All @@ -32,6 +34,15 @@ jobs:
tools: symfony
coverage: none

- name: Shutdown default MySQL
run: sudo service mysql stop

- name: Setup PostgreSQL
uses: harmon758/postgresql-action@v1
with:
postgresql version: "${{ matrix.postgres }}"
postgresql password: "postgres"

- name: "Restrict packages' versions"
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
Expand Down Expand Up @@ -70,6 +81,11 @@ jobs:
- name: Run PHPStan
run: vendor/bin/phpstan analyse

- name: Create Testing database
run: |
bin/console doctrine:database:create
bin/console doctrine:schema:create
- name: Run PHPUnit
run: vendor/bin/phpunit

Expand Down
9 changes: 9 additions & 0 deletions app/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\DataFixtures;
Expand Down
38 changes: 37 additions & 1 deletion app/Entity/Book.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Entity;

use App\Grid\BookGrid;
use App\Repository\BookRepository;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Create;
use Sylius\Resource\Metadata\Index;
use Sylius\Resource\Metadata\Update;

#[ORM\Entity(repositoryClass: BookRepository::class)]
#[AsResource]
#[AsResource(
section: 'admin',
templatesDir: '@SyliusAdminUi/crud',
routePrefix: '/admin',
operations: [
new Create(),
new Update(),
new Index(grid: BookGrid::class),
],
)]
#[SyliusCrudRoutes(
alias: 'app.book',
path: '/admin/legacy/books',
section: 'admin_legacy',
redirect: 'update',
templates: '@SyliusAdminUi/crud',
grid: 'app_book',
vars: [
'all' => [
'subheader' => 'app.ui.manage_your_books',
],
],
)]
class Book implements ResourceInterface
{
#[ORM\Id]
Expand Down
9 changes: 9 additions & 0 deletions app/Factory/BookFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Factory;
Expand Down
79 changes: 79 additions & 0 deletions app/Grid/BookGrid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Grid;

use App\Entity\Book;
use Sylius\Bundle\GridBundle\Builder\Action\CreateAction;
use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction;
use Sylius\Bundle\GridBundle\Builder\Action\ShowAction;
use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\BulkActionGroup;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\MainActionGroup;
use Sylius\Bundle\GridBundle\Builder\Field\StringField;
use Sylius\Bundle\GridBundle\Builder\Filter\StringFilter;
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface;

final class BookGrid extends AbstractGrid implements ResourceAwareGridInterface
{
public static function getName(): string
{
return 'app_book';
}

public function buildGrid(GridBuilderInterface $gridBuilder): void
{
$gridBuilder
->orderBy('title')
->addFilter(
StringFilter::create('search', ['title', 'authorName'])
->setLabel('sylius.ui.search'),
)
->addField(
StringField::create('title')
->setLabel('Title')
->setSortable(true),
)
->addField(
StringField::create('authorName')
->setLabel('Author Name')
->setSortable(true),
)
->addActionGroup(
MainActionGroup::create(
CreateAction::create(),
),
)
->addActionGroup(
ItemActionGroup::create(
// ShowAction::create(),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// ShowAction::create(),

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'll have to build a default show template as the internal core team did in the 2.0 branch.

UpdateAction::create(),
DeleteAction::create(),
),
)
->addActionGroup(
BulkActionGroup::create(
DeleteAction::create(),
),
)
;
}

public function getResourceClass(): string
Copy link
Member

Choose a reason for hiding this comment

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

I understand it comes from grid configuration, but conceptually it's strange it's not a static method.

---     public function getResourceClass(): string
+++     public static function getResourceClass(): string

Copy link
Member Author

@loic425 loic425 Sep 15, 2024

Choose a reason for hiding this comment

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

In the first iteration of the grid, it was a static method, but we remove that static in order to use the class model parameter from Sylius.

in this example:
%app.model.book.class%

{
return Book::class;
}
}
11 changes: 11 additions & 0 deletions app/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
Expand Down
9 changes: 9 additions & 0 deletions app/Repository/BookRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Repository;
Expand Down
9 changes: 9 additions & 0 deletions app/Story/DefaultBooksStory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Story;
Expand Down
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/orm": "^2.0",
"knplabs/knp-menu-bundle": "^3.0",
"laminas/laminas-stdlib": "^3.18",
"pagerfanta/doctrine-orm-adapter": "^4.6",
"sylius/grid-bundle": "^1.13@alpha",
"sylius/resource-bundle": "^1.11 || ^1.12@alpha",
"symfony/config": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
Expand All @@ -39,6 +42,7 @@
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^9.6",
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/debug-bundle": "^6.4 || ^7.0",
"symfony/dom-crawler": "^6.4 || ^7.0",
Expand All @@ -54,14 +58,17 @@
},
"autoload": {
"psr-4": {
"Sylius\\AdminUi\\": "src/AdminUi/src/",
"Sylius\\TwigExtra\\": "src/TwigExtra/src/",
"Sylius\\TwigHooks\\": "src/TwigHooks/src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\": "app/",
"MainTests\\Sylius\\": "tests/",
"TestApplication\\Sylius\\TwigHooks\\": "src/TwigHooks/tests/Functional/.application/src/",
"Tests\\Sylius\\AdminUi\\": "src/AdminUi/tests/",
"Tests\\Sylius\\TwigExtra\\": "src/TwigExtra/tests/",
"Tests\\Sylius\\TwigHooks\\": "src/TwigHooks/tests/"
}
Expand Down
3 changes: 3 additions & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
Sylius\TwigHooks\TwigHooksBundle::class => ['all' => true],
Sylius\TwigExtra\Symfony\TwigExtraBundle::class => ['all' => true],
Sylius\AdminUi\Symfony\SyliusAdminUiBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Symfony\UX\LiveComponent\LiveComponentBundle::class => ['all' => true],
Expand All @@ -16,4 +17,6 @@
Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true],
Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true, 'test' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
];
3 changes: 3 additions & 0 deletions config/packages/sylius_admin_ui.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sylius_admin_ui:
routing:
#dashboard_path: '/admin'
1 change: 1 addition & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/app',
__DIR__ . '/src',
]);

Expand Down
8 changes: 8 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
</php>

<testsuites>
<testsuite name="Main Test Suite">
<directory>tests</directory>
</testsuite>

<testsuite name="AdminUi Test Suite">
<directory>src/AdminUi/tests</directory>
</testsuite>

<testsuite name="TwigExtra Test Suite">
<directory>src/TwigExtra/tests</directory>
</testsuite>
Expand Down
20 changes: 20 additions & 0 deletions src/AdminUi/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "sylius/admin-ui",
"type": "library",
"require": {
"php": "^8.1",
"knplabs/knp-menu-bundle": "^3.0",
"sylius/twig-hooks": "^0.2",
"symfony/http-kernel": "^6.4 || ^7.0"
},
"autoload": {
"psr-4": {
"Sylius\\AdminUi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Sylius\\AdminUi\\": "tests/"
}
}
}
36 changes: 36 additions & 0 deletions src/AdminUi/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\AdminUi\Knp\Menu\MenuBuilder;
use Sylius\AdminUi\Knp\Menu\MenuBuilderInterface;
use Sylius\AdminUi\TwigHooks\Hookable\Metadata\RoutingHookableMetadataFactory;

return function (ContainerConfigurator $configurator): void {
$services = $configurator->services();

$services->set('sylius_admin_ui.knp.menu_builder', MenuBuilder::class)
->args([service('knp_menu.factory')])
->tag(name: 'knp_menu.menu_builder', attributes: ['method' => 'createMenu', 'alias' => 'sylius_admin_ui.menu.sidebar'])
;
$services->alias(MenuBuilderInterface::class, 'sylius_admin_ui.knp.menu_builder');

$services->set('sylius_admin_ui.twig_hooks.factory.hookable_metadata', RoutingHookableMetadataFactory::class)
->decorate('twig_hooks.factory.hookable_metadata')
Copy link
Member

Choose a reason for hiding this comment

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

Are there plans to fix namespace for twig_hooks to sylius_twig_hooks since it starts to affect related packages.

Copy link
Member Author

Choose a reason for hiding this comment

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

we have to discuss about it in the core team channel, but I agree, it's a bit risky to have no sylius prefix.

->args([
service('.inner'),
param('sylius_admin_ui.routing'),
])
;
};
Loading
Loading