Skip to content
Open
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
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

44 changes: 27 additions & 17 deletions js/src/admin/components/CategoryEditorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import Form from 'flarum/common/components/Form';
import Button from 'flarum/common/components/Button';
import ColorPreviewInput from 'flarum/common/components/ColorPreviewInput';
import Select from 'flarum/common/components/Select';
import Switch from 'flarum/common/components/Switch';
import ItemList from 'flarum/common/utils/ItemList';
import extractText from 'flarum/common/utils/extractText';
import generateElementId from 'flarum/common/utils/generateElementId';
import { saveCategory, deleteCategory, loadStaffUsers } from '../utils';
import { ticketTypes } from '../../common/ticketTypes';

Expand All @@ -20,6 +22,8 @@ function optionKey(id: string | number | null): string {
* submit/delete row).
*/
export default class CategoryEditorModal extends FormModal<any> {
private readonly allowedGroupsHelpId = generateElementId();

category: any = null;
editId: any = null;
name = '';
Expand Down Expand Up @@ -251,31 +255,37 @@ export default class CategoryEditorModal extends FormModal<any> {
'allowedGroups',
<div className="Form-group">
<label>{app.translator.trans('linkrobins-support.admin.category_editor.field_allowed_groups')}</label>
<div className="helpText">{app.translator.trans('linkrobins-support.admin.category_editor.field_allowed_groups_help')}</div>
<div className="LinkRobinsSupport-groupCheckboxes">
<div className="helpText" id={this.allowedGroupsHelpId}>
{app.translator.trans('linkrobins-support.admin.category_editor.field_allowed_groups_help')}
</div>
<div
className="LinkRobinsSupport-groupSwitches"
role="group"
aria-label={extractText(app.translator.trans('linkrobins-support.admin.category_editor.field_allowed_groups'))}
aria-describedby={this.allowedGroupsHelpId}
>
{((app.store && app.store.all('groups')) || [])
.filter((g: any) => g.id() !== '2') // Exclude Guest group
.map((group: any) => {
const id = String(group.id());
const checked = this.allowedGroupIds.includes(id);
return (
<label className="checkbox" key={id}>
<input
type="checkbox"
checked={checked}
disabled={this.saving}
onchange={(e: any) => {
if (e.target.checked) {
if (!this.allowedGroupIds.includes(id)) {
this.allowedGroupIds.push(id);
}
} else {
this.allowedGroupIds = this.allowedGroupIds.filter((gid) => gid !== id);
<Switch
key={id}
state={checked}
disabled={this.saving}
onchange={(value: boolean) => {
if (value) {
if (!this.allowedGroupIds.includes(id)) {
this.allowedGroupIds.push(id);
}
}}
/>
} else {
this.allowedGroupIds = this.allowedGroupIds.filter((gid) => gid !== id);
}
}}
>
{group.namePlural() || group.nameSingular() || id}
</label>
</Switch>
);
})}
</div>
Expand Down
47 changes: 17 additions & 30 deletions js/src/admin/components/SupportAdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,52 +216,39 @@ export default class SupportAdminPage extends ExtensionPage {
// --- Settings section ---

_renderNavigationSection() {
const switches = [
const settings = [
{
key: 'linkrobins-support.nav_in_sidebar',
setting: 'linkrobins-support.nav_in_sidebar',
labelKey: 'linkrobins-support.admin.navigation.in_sidebar',
helpKey: 'linkrobins-support.admin.navigation.in_sidebar_help',
fallback: true,
default: '1',
},
{
key: 'linkrobins-support.nav_in_account_menu',
setting: 'linkrobins-support.nav_in_account_menu',
labelKey: 'linkrobins-support.admin.navigation.in_account_menu',
helpKey: 'linkrobins-support.admin.navigation.in_account_menu_help',
fallback: true,
default: '1',
},
{
key: 'linkrobins-support.forum_nav_on_support_pages',
setting: 'linkrobins-support.forum_nav_on_support_pages',
labelKey: 'linkrobins-support.admin.navigation.forum_nav',
helpKey: 'linkrobins-support.admin.navigation.forum_nav_help',
fallback: false,
default: '0',
},
];

return (
<Form>
<p className="helpText">{app.translator.trans('linkrobins-support.admin.navigation.intro')}</p>
{switches.map((sw) => {
// Read AND write the page's own setting stream. Reading app.data
// instead leaves the input controlled by the saved value, so a click
// is undone by the very next redraw and the switch looks dead.
const value = this.setting(sw.key, sw.fallback ? '1' : '0');

return (
<div className="Form-group" key={sw.key}>
<label className="checkbox">
<input
type="checkbox"
checked={!(value() === '' || value() === '0')}
onchange={(e: any) => {
value(e.target.checked ? '1' : '0');
}}
/>
{app.translator.trans(sw.labelKey)}
</label>
<div className="helpText">{app.translator.trans(sw.helpKey)}</div>
</div>
);
})}
{settings.map((s) =>
this.buildSettingComponent({
setting: s.setting,
label: app.translator.trans(s.labelKey),
help: app.translator.trans(s.helpKey),
type: 'bool',
default: s.default,
})
)}
<div className="Form-group Form-controls">{this.submitButton()}</div>
</Form>
);
Expand Down Expand Up @@ -316,7 +303,7 @@ export default class SupportAdminPage extends ExtensionPage {
type="number"
className="FormControl"
min={f.min}
// Same rule as the switches above: the stream is the live value.
// Read and write the stream: it holds the live value.
value={this.setting(f.key, f.defaultValue)()}
oninput={(e: any) => {
this.setting(f.key, f.defaultValue)(e.target.value);
Expand Down
25 changes: 7 additions & 18 deletions less/admin.less
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,13 @@
white-space: nowrap;
}

// Group selector checkboxes inside CategoryEditorModal
.LinkRobinsSupport-groupCheckboxes {
// Group selector switches inside CategoryEditorModal, stacked in a column with a
// 14px gap on top of the 5px top/bottom margin each core `.Checkbox--switch`
// already carries.
.LinkRobinsSupport-groupSwitches {
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
margin-top: 6px;

.checkbox {
display: inline-flex;
align-items: center;
gap: 6px;
margin: 0;
cursor: pointer;
font-weight: normal;

input[type="checkbox"] {
margin: 0;
}
}
flex-direction: column;
align-items: flex-start;
gap: 14px;
}

Loading