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

Perform Admin Panel's templates cleanup #15404

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e96d2aa
Setup AdminBundle as a Node.js package
jakubtobiasz Sep 21, 2023
a3dd068
Switch to the dev branch of tabler
jakubtobiasz Sep 22, 2023
c4f700b
Add the $rootDir variable to the SCSS loader
jakubtobiasz Sep 22, 2023
3d98ff1
Set up entrypoint.js
jakubtobiasz Sep 22, 2023
4f29d2c
Add basic template events for CRUD's index
jakubtobiasz Sep 22, 2023
7a84255
Add support for Twig Components in Template Events
jakubtobiasz Sep 17, 2023
e33eb4d
Add navbar notifications button
jakubtobiasz Sep 22, 2023
92fe997
Add navbar user dropdown
jakubtobiasz Sep 22, 2023
8e9afe4
Improve passing event_prefix and resource_event_prefix between blocks
jakubtobiasz Sep 22, 2023
79625f2
Add a mocked searchbar
jakubtobiasz Sep 22, 2023
ec78873
Rename common template events
jakubtobiasz Sep 22, 2023
65b9f87
Add sidebar
jakubtobiasz Sep 22, 2023
1cd5fec
Fix "User profile" item in the user dropdown
jakubtobiasz Sep 22, 2023
15fa984
Add user dropdown on the mobile view
jakubtobiasz Sep 22, 2023
2cecce2
Add Admin Panel login page
jakubtobiasz Sep 22, 2023
63136e4
Add header to the CRUD's index page
jakubtobiasz Sep 23, 2023
852f703
Add filters to the CRUD's index page
jakubtobiasz Sep 23, 2023
eda1e1d
Add grid to the CRUD's index page
jakubtobiasz Sep 23, 2023
430158a
Fix action buttons on the index page
jakubtobiasz Sep 25, 2023
8213542
Fix static analysis
jakubtobiasz Sep 25, 2023
2b4c8f5
Fix icons in the sidebar
jakubtobiasz Sep 25, 2023
05e8cd4
Add pagination and batch actions
jakubtobiasz Sep 25, 2023
0cc1e7e
Add handling flashes
jakubtobiasz Sep 25, 2023
c25bccb
Fix batch checkboxes styling
jakubtobiasz Sep 25, 2023
ec839c5
Fix channel badge color on the index page
jakubtobiasz Sep 25, 2023
04f4a81
Add a default create page
jakubtobiasz Sep 26, 2023
b657b97
Add a default update page
jakubtobiasz Sep 26, 2023
b0240e2
Add a default show page
jakubtobiasz Sep 27, 2023
2f7d8c2
Adjust twig events' names
jakubtobiasz Sep 29, 2023
d932da8
Add a new twig_event Twig Function
jakubtobiasz Sep 29, 2023
a1b7cd5
Add a note about Component in the Data Collector
jakubtobiasz Sep 29, 2023
77af62e
Refactor Template Events to use a standalone ComponentBlock with a bc…
jakubtobiasz Oct 2, 2023
31f6005
Implement the Dashboard view
jakubtobiasz Oct 4, 2023
c78e343
Fix Sylius Template Events
jakubtobiasz Oct 4, 2023
c3e6497
Add pagination
jakubtobiasz Oct 5, 2023
52810fc
Cleanup old templates in the Admin Panel
jakubtobiasz Oct 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -131,6 +131,7 @@
"symfony/translation": "^6.3.3",
"symfony/translation-contracts": "^2.5.2",
"symfony/twig-bundle": "^6.3.0",
"symfony/ux-twig-component": "^2.11.2",
"symfony/validator": "^6.3.4",
"symfony/webpack-encore-bundle": "^1.17.1",
"symfony/yaml": "^6.3.3",
Expand Down Expand Up @@ -232,7 +233,7 @@
"symfony/runtime": "^6.3.2",
"symfony/web-profiler-bundle": "^6.3.2",
"symplify/monorepo-builder": "^11.0",
"vimeo/psalm": "5.15.*",
"vimeo/psalm": "5.14.*",
"weirdan/doctrine-psalm-plugin": "^2.8"
},
"suggest": {
Expand Down
1 change: 1 addition & 0 deletions config/bundles.php
Expand Up @@ -59,4 +59,5 @@
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
];
4 changes: 2 additions & 2 deletions config/packages/_sylius.yaml
@@ -1,12 +1,12 @@
imports:
- { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" }

- { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" }

- { resource: "@SyliusShopBundle/Resources/config/app/config.yml" }

- { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" }

- { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" }

parameters:
sylius_core.public_dir: '%kernel.project_dir%/public'

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"author": "Sylius Sp. z o.o.",
"dependencies": {
"@sylius-ui/admin": "file:src/Sylius/Bundle/AdminBundle",
"chart.js": "^3.7.1",
"jquery": "^3.5.0",
"jquery.dirtyforms": "^2.0.0",
Expand Down
3 changes: 2 additions & 1 deletion psalm.xml
Expand Up @@ -66,6 +66,7 @@
<DeprecatedInterface>
<errorLevel type="info">
<referencedClass name="ApiPlatform\Core\Api\IriConverterInterface" /> <!-- deprecated in ApiPlatform 2.7 -->
<referencedClass name="Sylius\Bundle\ShopBundle\Calculator\OrderItemsSubtotalCalculatorInterface" />
<referencedClass name="Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface" />
<referencedClass name="Sylius\Component\Core\Provider\ProductVariantsPricesProviderInterface" />
<referencedClass name="Sylius\Component\User\Security\UserPasswordEncoderInterface" />
Expand Down Expand Up @@ -135,7 +136,7 @@

<InvalidPropertyAssignmentValue>
<errorLevel type="info">
<file name="src/Sylius/Bundle/UiBundle/DataCollector/TemplateBlockRenderingHistory.php" />
<file name="src/Sylius/Bundle/UiBundle/DataCollector/BlockRenderingHistory.php" />
</errorLevel>
</InvalidPropertyAssignmentValue>

Expand Down
19 changes: 5 additions & 14 deletions rector.php
Expand Up @@ -2,21 +2,12 @@

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void
return static function (RectorConfig $config): void
{
$containerConfigurator->import(LevelSetList::UP_TO_PHP_80);

$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);

$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
$services->set(ClosureToArrowFunctionRector::class);
$config->sets([
LevelSetList::UP_TO_PHP_82
]);
};
Expand Up @@ -38,6 +38,16 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->end()
->arrayNode('templates')
->addDefaultsIfNotSet()
->children()
->arrayNode('item_action')
->useAttributeAsKey('name')
->scalarPrototype()->end()
->end()
->end()
->end()
->end()
->end()
;

Expand Down
Expand Up @@ -28,6 +28,7 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('sylius.admin.notification.enabled', $config['notifications']['enabled']);
$container->setParameter('sylius.admin.notification.frequency', $config['notifications']['frequency']);
$container->setParameter('sylius.admin.shop_enabled', false);
$container->setParameter('sylius.admin.templates.item_action', $config['templates']['item_action']);

$bundles = $container->getParameter('kernel.bundles');
if (array_key_exists('SyliusShopBundle', $bundles)) {
Expand Down
@@ -0,0 +1,23 @@
<?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 Sylius\Bundle\AdminBundle\Grid\Renderer;

use Sylius\Component\Grid\Definition\Action;
use Sylius\Component\Grid\Renderer\GridRendererInterface as BaseGridRendererInterface;
use Sylius\Component\Grid\View\GridViewInterface;

interface GridRendererInterface extends BaseGridRendererInterface
{
public function renderItemAction(GridViewInterface $gridView, Action $action, mixed $data = null): string;
}
@@ -0,0 +1,81 @@
<?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 Sylius\Bundle\AdminBundle\Grid\Renderer;

use Sylius\Bundle\ResourceBundle\Grid\Parser\OptionsParserInterface;
use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView;
use Sylius\Component\Grid\Definition\Action;
use Sylius\Component\Grid\Definition\Field;
use Sylius\Component\Grid\Definition\Filter;
use Sylius\Component\Grid\Renderer\GridRendererInterface as BaseGridRendererInterface;
use Sylius\Component\Grid\View\GridViewInterface;
use Twig\Environment as Twig;
use Webmozart\Assert\Assert;

/** @internal */
final readonly class TwigGridRenderer implements GridRendererInterface
{
/**
* @param array<string, string> $itemActionTemplates
*/
public function __construct (
private BaseGridRendererInterface $decorated,
private Twig $twig,
private OptionsParserInterface $optionsParser,
private array $itemActionTemplates = [],
) {
}

public function render(GridViewInterface $gridView, ?string $template = null): string
{
return $this->decorated->render($gridView, $template);
}

public function renderField(GridViewInterface $gridView, Field $field, $data): string
{
return $this->decorated->renderField($gridView, $field, $data);
}

public function renderAction(GridViewInterface $gridView, Action $action, $data = null): string
{
return $this->decorated->renderAction($gridView, $action, $data);
}

public function renderItemAction(GridViewInterface $gridView, Action $action, mixed $data = null): string
{
Assert::isInstanceOf($gridView, ResourceGridView::class);

$type = $action->getType();
if (!isset($this->itemActionTemplates[$type])) {
throw new \InvalidArgumentException(sprintf('Missing template for action type "%s".', $type));
}

$options = $this->optionsParser->parseOptions(
$action->getOptions(),
$gridView->getRequestConfiguration()->getRequest(),
$data,
);

return $this->twig->render($this->itemActionTemplates[$type], [
'grid' => $gridView,
'action' => $action,
'data' => $data,
'options' => $options,
]); }

public function renderFilter(GridViewInterface $gridView, Filter $filter): string
{
return $this->decorated->renderFilter($gridView, $filter);
}
}
26 changes: 23 additions & 3 deletions src/Sylius/Bundle/AdminBundle/Menu/MainMenuBuilder.php
Expand Up @@ -17,19 +17,24 @@
use Knp\Menu\ItemInterface;
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\RouterInterface;

final class MainMenuBuilder
final readonly class MainMenuBuilder
{
public const EVENT_NAME = 'sylius.menu.admin.main';

public function __construct(private FactoryInterface $factory, private EventDispatcherInterface $eventDispatcher)
{
public function __construct(
private FactoryInterface $factory,
private EventDispatcherInterface $eventDispatcher,
private RouterInterface $router,
) {
}

public function createMenu(array $options): ItemInterface
{
$menu = $this->factory->createItem('root');

$this->addDashboardSubmenu($menu);
$this->addCatalogSubMenu($menu);
$this->addSalesSubMenu($menu);
$this->addCustomersSubMenu($menu);
Expand All @@ -41,11 +46,22 @@ public function createMenu(array $options): ItemInterface
return $menu;
}

private function addDashboardSubmenu(ItemInterface $menu): void
{
$menu
->addChild('dashboard')
->setLabel('sylius.ui.dashboard')
->setLabelAttribute('icon', 'dashboard')
->setUri($this->router->generate('sylius_admin_dashboard'))
;
}

private function addCatalogSubMenu(ItemInterface $menu): void
{
$catalog = $menu
->addChild('catalog')
->setLabel('sylius.menu.admin.main.catalog.header')
->setLabelAttribute('icon', 'list-details')
;

$catalog
Expand Down Expand Up @@ -111,6 +127,7 @@ private function addCustomersSubMenu(ItemInterface $menu): void
$customers = $menu
->addChild('customers')
->setLabel('sylius.menu.admin.main.customers.header')
->setLabelAttribute('icon', 'users')
;

$customers
Expand Down Expand Up @@ -138,6 +155,7 @@ private function addMarketingSubMenu(ItemInterface $menu): void
$marketing = $menu
->addChild('marketing')
->setLabel('sylius.menu.admin.main.marketing.header')
->setLabelAttribute('icon', 'percentage')
;

$marketing
Expand Down Expand Up @@ -177,6 +195,7 @@ private function addSalesSubMenu(ItemInterface $menu): void
$sales = $menu
->addChild('sales')
->setLabel('sylius.menu.admin.main.sales.header')
->setLabelAttribute('icon', 'shopping-bag')
;

$sales
Expand Down Expand Up @@ -209,6 +228,7 @@ private function addConfigurationSubMenu(ItemInterface $menu): void
$configuration = $menu
->addChild('configuration')
->setLabel('sylius.menu.admin.main.configuration.header')
->setLabelAttribute('icon', 'adjustments')
;

$configuration
Expand Down
19 changes: 19 additions & 0 deletions src/Sylius/Bundle/AdminBundle/Resources/assets/entrypoint.js
@@ -0,0 +1,19 @@
/*
* 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.
*/

import './styles/main.scss';

import './scripts/choices';
import './scripts/statistics_chart';

import 'bootstrap';

import './images/no_data.svg';
import './images/sylius-logo.svg';
import './images/sylius-logo-dark-text.png';
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.