WIP: Add Protocol Gateway settings section and tighten the dialog

Introduce a per-section content registry (contentFor) mirroring the integration form registry, and use it for a new Advanced > Protocol Gateway section that explains Sockethub and edits the server URL, with a live connection status.

The URL field loads the stored value via sockethub.loadUrl() so it never prefills the default over a saved URL, and save failures surface inline.

Also narrow the settings dialog (sm:max-w-4xl) and sidebar (sm:w-52) and shorten it (min(80vh,40rem)).
This commit is contained in:
raucao committed 2026-11-06 14:31:40 +04:00
1 parent 4f8011647d
commit fd0d29760c
9 files changed
+360 -5

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ const WIDTHS = {
xl: 'sm:max-w-xl',
'2xl': 'sm:max-w-2xl',
'3xl': 'sm:max-w-3xl',
settings: 'sm:max-w-6xl',
settings: 'sm:max-w-4xl',
};
export default class ModalHostComponent extends Component {
+9 -2
View File
@@ -7,6 +7,7 @@ import {
SETTINGS_GROUPS,
findSettingsSection,
} from '../../config/settings';
import { contentFor } from '../../config/settings-content';
import Nav from './global-settings/nav.gjs';
import Section from './global-settings/section.gjs';
@@ -28,6 +29,10 @@ export default class SettingsGlobalSettings extends Component {
return this.activeSection?.label ?? 'Settings';
}
get activeContent() {
return contentFor(this.activeId);
}
@action
selectSection(id) {
this.activeId = id;
@@ -35,7 +40,7 @@ export default class SettingsGlobalSettings extends Component {
<template>
<div
class="flex h-[85vh] w-full flex-col text-gray-900 sm:h-[min(85vh,48rem)] sm:flex-row"
class="flex h-[80vh] w-full flex-col text-gray-900 sm:h-[min(80vh,40rem)] sm:flex-row"
>
<Nav
@groups={{this.groups}}
@@ -73,7 +78,9 @@ export default class SettingsGlobalSettings extends Component {
</button>
</header>
{{#if this.activeSection}}
{{#if this.activeContent}}
<this.activeContent @section={{this.activeSection}} />
{{else if this.activeSection}}
<Section @section={{this.activeSection}} />
{{/if}}
</div>
@@ -6,7 +6,7 @@ import NavItem from './nav-item.gjs';
<template>
<nav
aria-label="Settings"
class="flex shrink-0 gap-1 overflow-x-auto overflow-y-hidden border-b border-gray-200 bg-gray-50 p-2 sm:w-64 sm:flex-col sm:gap-0 sm:overflow-x-hidden sm:overflow-y-auto sm:border-r sm:border-b-0 sm:p-3"
class="flex shrink-0 gap-1 overflow-x-auto overflow-y-hidden border-b border-gray-200 bg-gray-50 p-2 sm:w-52 sm:flex-col sm:gap-0 sm:overflow-x-hidden sm:overflow-y-auto sm:border-r sm:border-b-0 sm:p-3"
>
{{#each @groups as |group|}}
<div class="contents sm:block">
@@ -0,0 +1,176 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import {
DEFAULT_SOCKETHUB_URL,
normalizeSockethubUrl,
} from '../../../../config/sockethub';
import {
SOCKETHUB_STATUS_CONNECTING,
SOCKETHUB_STATUS_ERROR,
SOCKETHUB_STATUS_READY,
} from '../../../../services/sockethub';
// Sockethub (the protocol gateway) settings. Dashtab talks to a single
// Sockethub server for every integration that needs one; this section explains
// what that is and lets the user point Dashtab at another instance.
export default class SettingsProtocolGateway extends Component {
@service sockethub;
@tracked urlDraft = null;
@tracked error = null;
@tracked saved = false;
constructor(owner, args) {
super(owner, args);
// `sockethub.url` is only populated when a connection opens, so load the
// stored value eagerly. Otherwise the field would show the default even
// when a custom URL is saved, and saving would overwrite it.
this.sockethub.loadUrl();
}
get url() {
return this.urlDraft ?? this.sockethub.url ?? DEFAULT_SOCKETHUB_URL;
}
get statusLabel() {
switch (this.sockethub.status) {
case SOCKETHUB_STATUS_READY:
return 'Connected';
case SOCKETHUB_STATUS_CONNECTING:
return 'Connecting…';
case SOCKETHUB_STATUS_ERROR:
return this.sockethub.error
? `Last error: ${this.sockethub.error}`
: 'Connection failed';
default:
return 'Not connected';
}
}
get statusDotClass() {
switch (this.sockethub.status) {
case SOCKETHUB_STATUS_READY:
return 'bg-green-500';
case SOCKETHUB_STATUS_ERROR:
return 'bg-red-500';
default:
return 'bg-gray-400';
}
}
@action
updateUrl(event) {
this.urlDraft = event.target.value;
this.error = null;
this.saved = false;
}
@action
async save(event) {
event.preventDefault();
this.error = null;
this.saved = false;
const url = normalizeSockethubUrl(this.url);
if (!url) {
this.error = 'Please enter a valid Sockethub server URL';
return;
}
try {
await this.sockethub.setUrl(url);
this.urlDraft = url;
this.saved = true;
} catch (err) {
this.error = err?.message ?? 'Unable to reach that Sockethub server';
}
}
<template>
<div class="min-h-0 flex-1 overflow-y-auto px-6 py-6">
<div class="max-w-prose space-y-3 text-sm text-gray-500">
<p>
Sockethub is a protocol gateway: it lets Dashtab reach services a
browser cannot talk to directly — currently CalDAV calendars — by
exchanging data via this specialized proxy server.
</p>
<p>
Dashtab talks to a single Sockethub server. Most people can keep the
default; credentials are encrypted on the server and never logged or
saved. Self-hosters can point it at their own instance for maximum
privacy and security.
<a
href="https://sockethub.org"
target="_blank"
rel="noopener noreferrer"
class="text-indigo-600 hover:text-indigo-500"
>Learn more at sockethub.org</a>.
</p>
</div>
<form {{on "submit" this.save}} class="mt-6 max-w-lg">
<label
for="sockethub-url"
class="block text-sm font-medium leading-6 text-gray-900"
>
Sockethub server URL
</label>
<div class="mt-2">
<input
type="text"
inputmode="url"
id="sockethub-url"
name="sockethub-url"
value={{this.url}}
{{on "input" this.updateUrl}}
placeholder={{DEFAULT_SOCKETHUB_URL}}
class="block w-full rounded-md border-0 px-3 py-2 text-sm text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600"
/>
</div>
<p class="mt-2 text-sm text-gray-500">
The Sockethub instance Dashtab talks to. Only the origin is kept; any
path is ignored.
</p>
{{#if this.error}}
<p data-test-error class="mt-3 text-sm text-red-600" role="alert">
{{this.error}}
</p>
{{/if}}
<div class="mt-4 flex items-center gap-3">
<button
type="submit"
class="inline-flex justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
Save
</button>
{{#if this.saved}}
<span data-test-saved class="text-sm text-green-600" role="status">
Saved
</span>
{{/if}}
</div>
</form>
<div class="mt-8 border-t border-gray-200 pt-4 text-sm text-gray-500">
<p class="flex items-center gap-2">
<span
class="size-2 shrink-0 rounded-full {{this.statusDotClass}}"
aria-hidden="true"
></span>
<span data-test-status role="status">{{this.statusLabel}}</span>
</p>
<p class="mt-1 text-xs text-gray-400">
Sockethub connects on demand while an integration that needs it is
active.
</p>
</div>
</div>
</template>
}
+12
View File
@@ -0,0 +1,12 @@
import ProtocolGateway from '../components/settings/global-settings/sections/protocol-gateway.gjs';
// Maps a settings section id to its content component. Sections without an
// entry fall back to the generic placeholder, so this grows one section at a
// time. Mirrors the integration form registry in `integration-forms.js`.
const CONTENT = {
'protocol-gateway': ProtocolGateway,
};
export function contentFor(id) {
return CONTENT[id] ?? null;
}
+15
View File
@@ -75,6 +75,21 @@ export const SETTINGS_GROUPS = [
},
],
},
{
label: 'Advanced',
items: [
{
id: 'protocol-gateway',
label: 'Protocol Gateway',
description:
'Configure the Sockethub server used by protocol integrations.',
// Heroicons globe-alt (no Feather equivalent).
icon: [
'M12 21C16.1926 21 19.7156 18.1332 20.7157 14.2529M12 21C7.80742 21 4.28442 18.1332 3.2843 14.2529M12 21C14.4853 21 16.5 16.9706 16.5 12C16.5 7.02944 14.4853 3 12 3M12 21C9.51472 21 7.5 16.9706 7.5 12C7.5 7.02944 9.51472 3 12 3M12 3C15.3652 3 18.299 4.84694 19.8431 7.58245M12 3C8.63481 3 5.70099 4.84694 4.15692 7.58245M19.8431 7.58245C17.7397 9.40039 14.9983 10.5 12 10.5C9.00172 10.5 6.26027 9.40039 4.15692 7.58245M19.8431 7.58245C20.5797 8.88743 21 10.3946 21 12C21 12.778 20.9013 13.5329 20.7157 14.2529M20.7157 14.2529C18.1334 15.6847 15.1619 16.5 12 16.5C8.8381 16.5 5.86662 15.6847 3.2843 14.2529M3.2843 14.2529C3.09871 13.5329 3 12.778 3 12C3 10.3946 3.42032 8.88743 4.15692 7.58245',
],
},
],
},
{
label: 'About',
items: [
@@ -22,7 +22,7 @@ module('Integration | Component | settings-button', function (hooks) {
await render(<template><SettingsButton /><ModalHost /></template>);
await click('[aria-label="Open settings"]');
assert.dom('el-dialog-panel').hasClass('sm:max-w-6xl');
assert.dom('el-dialog-panel').hasClass('sm:max-w-4xl');
assert.dom('#modal-title').exists({ count: 1 });
});
});
@@ -62,4 +62,27 @@ module('Integration | Component | settings/global-settings', function (hooks) {
assert.true(closed);
});
test('renders a section content component when one is registered', async function (assert) {
const noop = () => {};
this.owner.register(
'service:sockethub',
{
url: null,
status: 'disconnected',
error: null,
loadUrl() {},
setUrl() {},
},
{ instantiate: false }
);
await render(<template><GlobalSettings @close={{noop}} /></template>);
await click(sectionButton(this.element, 'Protocol Gateway'));
assert.dom('#modal-title').hasText('Protocol Gateway');
assert.dom('a[href="https://sockethub.org"]').exists();
assert.dom('input#sockethub-url').exists();
});
});
@@ -0,0 +1,122 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, fillIn, triggerEvent } from '@ember/test-helpers';
import ProtocolGateway from 'dashtab/components/settings/global-settings/sections/protocol-gateway';
import { DEFAULT_SOCKETHUB_URL } from 'dashtab/config/sockethub';
function registerSockethub(owner, overrides = {}) {
const sockethub = {
url: overrides.url ?? null,
status: overrides.status ?? 'disconnected',
error: overrides.error ?? null,
saved: [],
loadUrl() {
this.url = overrides.storedUrl ?? this.url;
return Promise.resolve(this.url);
},
setUrl(url) {
this.saved.push(url);
if (overrides.reject) {
return Promise.reject(
new Error('Unable to reach that Sockethub server')
);
}
this.url = url;
return Promise.resolve();
},
};
owner.register('service:sockethub', sockethub, { instantiate: false });
return sockethub;
}
module(
'Integration | Component | settings/global-settings/sections/protocol-gateway',
function (hooks) {
setupRenderingTest(hooks);
test('explains Sockethub and links to the website', async function (assert) {
registerSockethub(this.owner, { url: DEFAULT_SOCKETHUB_URL });
await render(<template><ProtocolGateway /></template>);
assert.dom('a[href="https://sockethub.org"]').exists();
assert.dom('input#sockethub-url').hasValue(DEFAULT_SOCKETHUB_URL);
});
test('prefills a stored custom URL instead of the default', async function (assert) {
registerSockethub(this.owner, {
storedUrl: 'https://self.example.org',
});
await render(<template><ProtocolGateway /></template>);
assert.dom('input#sockethub-url').hasValue('https://self.example.org');
});
test('rejects an invalid URL without saving', async function (assert) {
const sockethub = registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
});
await render(<template><ProtocolGateway /></template>);
await fillIn('input#sockethub-url', 'not a url');
await triggerEvent('form', 'submit');
assert.dom('[data-test-error]').exists();
assert.deepEqual(sockethub.saved, []);
});
test('saves the normalized origin and confirms', async function (assert) {
const sockethub = registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
});
await render(<template><ProtocolGateway /></template>);
await fillIn('input#sockethub-url', 'https://host.example.org/path?q=1');
await triggerEvent('form', 'submit');
assert.deepEqual(sockethub.saved, ['https://host.example.org']);
assert.dom('[data-test-saved]').exists();
});
test('surfaces a save failure without reporting success', async function (assert) {
registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
reject: true,
});
await render(<template><ProtocolGateway /></template>);
await fillIn('input#sockethub-url', 'https://host.example.org');
await triggerEvent('form', 'submit');
assert.dom('[data-test-error]').exists();
assert.dom('[data-test-saved]').doesNotExist();
});
test('shows a connected status', async function (assert) {
registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
status: 'ready',
});
await render(<template><ProtocolGateway /></template>);
assert.dom('[data-test-status]').hasText('Connected');
});
test('shows the last error when the connection fails', async function (assert) {
registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
status: 'error',
error: 'caldav:authentication-failed',
});
await render(<template><ProtocolGateway /></template>);
assert
.dom('[data-test-status]')
.hasText('Last error: caldav:authentication-failed');
});
}
);