Skip to content

Commit

Permalink
chore: light tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Dec 7, 2023
1 parent b4a82e8 commit e3553e2
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ComponentAttrs } from 'flarum/common/Component';
import Installer from './Installer';
import Updater from './Updater';
import Mithril from 'mithril';
import Form from 'flarum/common/components/Form';

export default class ControlSection extends Component<ComponentAttrs> {
oninit(vnode: Mithril.Vnode<ComponentAttrs, this>) {
Expand All @@ -22,10 +23,10 @@ export default class ControlSection extends Component<ComponentAttrs> {
</div>
<div className="container">
{app.data['flarum-package-manager.writable_dirs'] ? (
<>
<Form>
<Installer />
<Updater />
</>
</Form>
) : (
<div className="Form-group">
<Alert type="warning" dismissible={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import WhyNotModal from './WhyNotModal';
import ExtensionItem from './ExtensionItem';
import { AsyncBackendResponse } from '../shims';
import jumpToQueue from '../utils/jumpToQueue';
import classList from 'flarum/common/utils/classList';

export interface MajorUpdaterAttrs extends ComponentAttrs {
coreUpdate: UpdatedPackage;
Expand All @@ -33,7 +34,12 @@ export default class MajorUpdater<T extends MajorUpdaterAttrs = MajorUpdaterAttr
view(): Mithril.Children {
// @todo move Form-group--danger class to core for reuse
return (
<div className="Form-group Form-group--danger PackageManager-majorUpdate">
<div
className={classList('Form-group Form-group--danger PackageManager-majorUpdate', {
'PackageManager-majorUpdate--failed': this.updateState.status === 'failure',
'PackageManager-majorUpdate--incompatibleExtensions': this.updateState.incompatibleExtensions.length,
})}
>
<img alt="flarum logo" src={app.forum.attribute('baseUrl') + '/assets/extensions/flarum-package-manager/flarum.svg'} />
<label>{app.translator.trans('flarum-package-manager.admin.major_updater.title', { version: this.attrs.coreUpdate['latest-major'] })}</label>
<p className="helpText">{app.translator.trans('flarum-package-manager.admin.major_updater.description')}</p>
Expand Down
14 changes: 7 additions & 7 deletions extensions/package-manager/js/src/admin/components/Updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ export default class Updater extends Component<IUpdaterAttrs> {
);
}

if (!(state.extensionUpdates.length || state.coreUpdate)) {
const hasMinorCoreUpdate = state.coreUpdate && state.coreUpdate.package['latest-minor'];

if (!(state.extensionUpdates.length || hasMinorCoreUpdate)) {
return (
<div className="PackageManager-extensions">
<Alert type="success" dismissible={false}>
{app.translator.trans('flarum-package-manager.admin.updater.up_to_date')}
</Alert>
<span className="helpText">{app.translator.trans('flarum-package-manager.admin.updater.up_to_date')}</span>
</div>
);
}

return (
<div className="PackageManager-extensions">
<div className="PackageManager-extensions-grid">
{state.coreUpdate ? (
{hasMinorCoreUpdate ? (
<ExtensionItem
extension={state.coreUpdate.extension}
updates={state.coreUpdate.package}
extension={state.coreUpdate!.extension}
updates={state.coreUpdate!.package}
isCore={true}
onClickUpdate={() => state.updateCoreMinor()}
whyNotWarning={state.lastUpdateRun.limitedPackages().includes('flarum/core')}
Expand Down
43 changes: 38 additions & 5 deletions extensions/package-manager/less/admin/ControlSection.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
}

.PackageManager-extensions {
width: 100%;

&-grid {
--gap: 12px;
display: grid;
grid-template-columns: repeat(auto-fit, calc(~"100% / 3 - var(--gap)"));
grid-template-columns: repeat(auto-fit, 310px);
gap: var(--gap);
}
}
Expand Down Expand Up @@ -86,12 +88,35 @@
grid-template-areas:
"title logo"
"helpText logo"
"controls logo"
"extensions extensions"
"failure failure";
grid-gap: 0 var(--space);
"controls logo";
column-gap: 0 var(--space);
align-items: center;

&--failed&--incompatibleExtensions {
grid-template-areas:
"title logo"
"helpText logo"
"controls logo"
"extensions extensions"
"failure failure";
}

&--failed {
grid-template-areas:
"title logo"
"helpText logo"
"controls logo"
"failure failure";
}

&--incompatibleExtensions {
grid-template-areas:
"title logo"
"helpText logo"
"controls logo"
"extensions extensions";
}

> img {
grid-area: logo;
}
Expand All @@ -116,6 +141,10 @@
padding-top: var(--space);
border-top: 1px solid var(--control-bg);
}

.PackageManager-updaterControls {
margin: 0;
}
}

.WhyNotModal {
Expand All @@ -131,3 +160,7 @@
width: 300px;
}
}

.PackageManager-controlSection .container {
max-width: 900px;
}
4 changes: 3 additions & 1 deletion extensions/package-manager/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ flarum-package-manager:
The package manager requires read and write permissions on the following files and directories: composer.json, composer.lock, vendor, storage, storage/.composer
major_updater:
description: Major Flarum updates are not backwards compatible, meaning that some of your currently installed extensions, and manually made modifications might not work with this new version.
description: >
Major Flarum updates are not backwards compatible, meaning that some of your currently installed extensions, and manually made modifications might not work with this new version.
Please make sure to make a backup of your database and files before proceeding.
dry_run: Dry Run
dry_run_help: A dry run emulates the update to see if your current setup can safely update, this does not mean that your manual made custom modifications will work in the newer version.
failure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\PackageManager\Api\Serializer\TaskSerializer;
use Flarum\PackageManager\Task\TaskRepository;
use Flarum\PackageManager\Task\Task;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;

Expand All @@ -23,7 +23,6 @@ class ListTasksController extends AbstractListController

public function __construct(
protected UrlGenerator $url,
protected TaskRepository $repository
) {
}

Expand All @@ -36,14 +35,13 @@ protected function data(ServerRequestInterface $request, Document $document): it
$limit = $this->extractLimit($request);
$offset = $this->extractOffset($request);

$results = $this->repository
->query()
$results = Task::query()
->latest()
->offset($offset)
->limit($limit)
->get();

$total = $this->repository->query()->count();
$total = Task::query()->count();

$document->addMeta('total', (string) $total);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Operation;
use Flarum\PackageManager\Task\Task;

abstract class AbstractActionCommand
{
public ?Task $task = null;
public ?string $package = null;

abstract public function getOperationName(): string;
abstract public function getOperationName(): Operation;
}
6 changes: 3 additions & 3 deletions extensions/package-manager/src/Command/CheckForUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Task;
use Flarum\PackageManager\Task\Operation;
use Flarum\User\User;

class CheckForUpdates extends AbstractActionCommand
Expand All @@ -19,8 +19,8 @@ public function __construct(
) {
}

public function getOperationName(): string
public function getOperationName(): Operation
{
return Task::UPDATE_CHECK;
return Operation::UPDATE_CHECK;
}
}
6 changes: 3 additions & 3 deletions extensions/package-manager/src/Command/GlobalUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Task;
use Flarum\PackageManager\Task\Operation;
use Flarum\User\User;

class GlobalUpdate extends AbstractActionCommand
Expand All @@ -19,8 +19,8 @@ public function __construct(
) {
}

public function getOperationName(): string
public function getOperationName(): Operation
{
return Task::UPDATE_GLOBAL;
return Operation::UPDATE_GLOBAL;
}
}
6 changes: 3 additions & 3 deletions extensions/package-manager/src/Command/MajorUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Task;
use Flarum\PackageManager\Task\Operation;
use Flarum\User\User;

class MajorUpdate extends AbstractActionCommand
Expand All @@ -20,8 +20,8 @@ public function __construct(
) {
}

public function getOperationName(): string
public function getOperationName(): Operation
{
return Task::UPDATE_MAJOR;
return Operation::UPDATE_MAJOR;
}
}
6 changes: 3 additions & 3 deletions extensions/package-manager/src/Command/MinorUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Task;
use Flarum\PackageManager\Task\Operation;
use Flarum\User\User;

class MinorUpdate extends AbstractActionCommand
Expand All @@ -19,8 +19,8 @@ public function __construct(
) {
}

public function getOperationName(): string
public function getOperationName(): Operation
{
return Task::UPDATE_MINOR;
return Operation::UPDATE_MINOR;
}
}
6 changes: 3 additions & 3 deletions extensions/package-manager/src/Command/RemoveExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Task;
use Flarum\PackageManager\Task\Operation;
use Flarum\User\User;

class RemoveExtension extends AbstractActionCommand
Expand All @@ -20,8 +20,8 @@ public function __construct(
) {
}

public function getOperationName(): string
public function getOperationName(): Operation
{
return Task::EXTENSION_REMOVE;
return Operation::EXTENSION_REMOVE;
}
}
6 changes: 3 additions & 3 deletions extensions/package-manager/src/Command/RequireExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Task;
use Flarum\PackageManager\Task\Operation;
use Flarum\User\User;

class RequireExtension extends AbstractActionCommand
Expand All @@ -20,8 +20,8 @@ public function __construct(
) {
}

public function getOperationName(): string
public function getOperationName(): Operation
{
return Task::EXTENSION_INSTALL;
return Operation::EXTENSION_INSTALL;
}
}
6 changes: 3 additions & 3 deletions extensions/package-manager/src/Command/UpdateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Task;
use Flarum\PackageManager\Task\Operation;
use Flarum\User\User;

class UpdateExtension extends AbstractActionCommand
Expand All @@ -20,8 +20,8 @@ public function __construct(
) {
}

public function getOperationName(): string
public function getOperationName(): Operation
{
return Task::EXTENSION_UPDATE;
return Operation::EXTENSION_UPDATE;
}
}
6 changes: 3 additions & 3 deletions extensions/package-manager/src/Command/WhyNot.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\PackageManager\Command;

use Flarum\PackageManager\Task\Task;
use Flarum\PackageManager\Task\Operation;
use Flarum\User\User;

class WhyNot extends AbstractActionCommand
Expand All @@ -21,8 +21,8 @@ public function __construct(
) {
}

public function getOperationName(): string
public function getOperationName(): Operation
{
return Task::WHY_NOT;
return Operation::WHY_NOT;
}
}
2 changes: 1 addition & 1 deletion extensions/package-manager/src/Job/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Dispatcher
* Runs synchronously regardless of user setting if set true.
* Asynchronously if set false.
*/
protected ?bool $runSyncOverride;
protected ?bool $runSyncOverride = null;

public function __construct(
protected Bus $bus,
Expand Down
15 changes: 15 additions & 0 deletions extensions/package-manager/src/Task/Operation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Flarum\PackageManager\Task;

enum Operation: string
{
case EXTENSION_INSTALL = 'extension_install';
case EXTENSION_REMOVE = 'extension_remove';
case EXTENSION_UPDATE = 'extension_update';
case UPDATE_GLOBAL = 'update_global';
case UPDATE_MINOR = 'update_minor';
case UPDATE_MAJOR = 'update_major';
case UPDATE_CHECK = 'update_check';
case WHY_NOT = 'why_not';
}
Loading

0 comments on commit e3553e2

Please sign in to comment.