1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 15:37:51 +02:00

feat: Admin debug mode warning (#3590)

* feat: Admin debug mode warning

* prettier

* Wrap in Alert component

* feat: add `title` and `icon` attributes to the `Alert` component

Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>

* Update framework/core/js/src/admin/components/DebugWarningWidget.js

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>

* Update framework/core/locale/core.yml

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>

* prettier

* chore: convert to TS

Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>

* Update framework/core/js/src/common/components/Alert.tsx

Co-authored-by: David Wheatley <hi@davwheat.dev>

* chore: add docs link

Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>
Co-authored-by: Sami Mazouz <ilyasmazouz@gmail.com>
Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
Co-authored-by: David Wheatley <hi@davwheat.dev>
This commit is contained in:
Ian Morland
2022-08-11 22:41:54 +02:00
committed by GitHub
parent 25122fd355
commit 4eb2112282
8 changed files with 73 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import ExtensionsWidget from './ExtensionsWidget';
import ItemList from '../../common/utils/ItemList';
import AdminPage from './AdminPage';
import type { Children } from 'mithril';
import DebugWarningWidget from './DebugWarningWidget';
export default class DashboardPage extends AdminPage {
headerInfo() {
@@ -22,6 +23,10 @@ export default class DashboardPage extends AdminPage {
availableWidgets(): ItemList<Children> {
const items = new ItemList<Children>();
if (app.data.debugEnabled) {
items.add('debug-warning', <DebugWarningWidget />, 100);
}
items.add('status', <StatusWidget />, 30);
items.add('extensions', <ExtensionsWidget />, 10);

View File

@@ -0,0 +1,20 @@
import app from '../../admin/app';
import Alert from '../../common/components/Alert';
import Link from '../../common/components/Link';
import DashboardWidget from './DashboardWidget';
export default class DebugWarningWidget extends DashboardWidget {
className() {
return 'DebugWarningWidget';
}
content() {
return (
<Alert type="warning" dismissible={false} title={app.translator.trans('core.admin.debug-warning.label')} icon="fas fa-exclamation-triangle">
{app.translator.trans('core.admin.debug-warning.detail', {
link: <Link href="https://docs.flarum.org/troubleshoot/#step-0-activate-debug-mode" external={true} target="_blank" />,
})}
</Alert>
);
}
}

View File

@@ -5,10 +5,15 @@ import extract from '../utils/extract';
import type Mithril from 'mithril';
import classList from '../utils/classList';
import app from '../app';
import iconHelper from '../helpers/icon';
export interface AlertAttrs extends ComponentAttrs {
/** The type of alert this is. Will be used to give the alert a class name of `Alert--{type}`. */
type?: string;
/** Title of the alert. Optional. */
title?: Mithril.Children;
/** Icon used next to the title. Optional. */
icon?: string;
/** An array of controls to show in the alert. */
controls?: Mithril.Children;
/** Whether or not the alert can be dismissed. */
@@ -28,6 +33,8 @@ export default class Alert<T extends AlertAttrs = AlertAttrs> extends Component<
const type = extract(attrs, 'type');
attrs.className = classList('Alert', `Alert--${type}`, attrs.className);
const title = extract(attrs, 'title');
const icon = extract(attrs, 'icon');
const content = extract(attrs, 'content') || vnode.children;
const controls = (extract(attrs, 'controls') || []) as Mithril.Vnode[];
@@ -51,6 +58,12 @@ export default class Alert<T extends AlertAttrs = AlertAttrs> extends Component<
return (
<div {...attrs}>
{!!title && (
<div class="Alert-title">
{!!icon && <span class="Alert-title-icon">{iconHelper(icon)}</span>}
<span class="Alert-title-text">{title}</span>
</div>
)}
<span class="Alert-body">{content}</span>
<ul class="Alert-controls">{listItems(controls.concat(dismissControl))}</ul>
</div>