WIP: Move site links into a Site Links settings section

Remove Clock, Connected Apps and Notifications from the settings menu and move Site Links under Integrations.

Extract a shared integration grid (two-column cards with settings/reconnect/remove icon buttons) used by both Calendar and Site Links, and add a Site Links section that lists the dashboard quick-link integrations alphabetically.

Manage Integrations now excludes calendars and site links, which are managed from their settings sections.
This commit is contained in:
raucao committed 2026-11-06 16:21:29 +04:00
1 parent 11f8d3f049
commit 55b5bfeedb
9 files changed
+584 -443

No files matched your search

@@ -7,19 +7,7 @@ import { formFor } from '../../../../config/integration-forms';
import { CALENDAR_TYPES } from '../../../../config/calendar';
import { CALDAV_TYPE } from '../../../../config/caldav';
import { ICS_TYPE } from '../../../../config/ics';
import Avatar from '../../integrations/avatar.gjs';
// Feather icons (https://feathericons.com), one path per element.
const SETTINGS_ICON = [
'M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z',
'M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z',
];
const REMOVE_ICON = [
'M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20z',
'M15 9l-6 6',
'M9 9l6 6',
];
import IntegrationGrid from './integration-grid.gjs';
// The connected calendars, moved out of Manage Integrations. Add/edit open the
// calendar wizards on top of the settings dialog via the modal stack.
@@ -66,88 +54,12 @@ export default class SettingsCalendarList extends Component {
<template>
<div>
{{#if this.rows.length}}
<ul class="grid grid-cols-1 gap-3 sm:grid-cols-2">
{{#each this.rows as |row|}}
<li
data-instance={{row.id}}
data-integration={{row.type}}
class="flex items-center gap-3 rounded-lg border border-gray-200 p-3"
>
<Avatar @integration={{row}} />
<div class="min-w-0 flex-auto">
<p class="truncate text-sm font-medium text-gray-700">
{{row.label}}
</p>
<p class="truncate text-sm text-gray-500">{{row.byline}}</p>
{{#if row.error}}
<p class="truncate text-sm text-red-600">{{row.error}}</p>
{{/if}}
</div>
<div class="flex shrink-0 items-center">
{{#if row.hasSettings}}
<button
type="button"
data-test-settings
aria-label="Settings"
title="Settings"
{{on "click" (fn this.edit row)}}
class="rounded-md p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
aria-hidden="true"
class="size-5"
>
{{#each SETTINGS_ICON as |d|}}
<path
d={{d}}
stroke-linecap="round"
stroke-linejoin="round"
/>
{{/each}}
</svg>
</button>
{{/if}}
<button
type="button"
data-test-remove
aria-label="Remove"
title="Remove"
{{on "click" (fn this.remove row)}}
class="rounded-md p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
aria-hidden="true"
class="size-5"
>
{{#each REMOVE_ICON as |d|}}
<path
d={{d}}
stroke-linecap="round"
stroke-linejoin="round"
/>
{{/each}}
</svg>
</button>
</div>
</li>
{{/each}}
</ul>
{{else}}
<p class="rounded-xl bg-gray-50 p-6 text-center text-sm text-gray-500">
No calendars connected yet.
</p>
{{/if}}
<IntegrationGrid
@rows={{this.rows}}
@onEdit={{this.edit}}
@onRemove={{this.remove}}
@emptyLabel="No calendars connected yet."
/>
<div class="mt-6 flex flex-wrap gap-2">
<button
@@ -0,0 +1,140 @@
import { fn } from '@ember/helper';
import { on } from '@ember/modifier';
import Avatar from '../../integrations/avatar.gjs';
// Feather icons (https://feathericons.com), one path per element.
const SETTINGS_ICON = [
'M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z',
'M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z',
];
const RECONNECT_ICON = [
'M23 4v6h-6',
'M1 20v-6h6',
'M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15',
];
const REMOVE_ICON = [
'M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20z',
'M15 9l-6 6',
'M9 9l6 6',
];
const ACTION_BUTTON_CLASS =
'rounded-md p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600';
// A two-column grid of integration cards with icon actions. Shared by the
// Calendar and Site Links settings sections so they stay consistent.
<template>
{{#if @rows.length}}
<ul class="grid grid-cols-1 gap-3 sm:grid-cols-2">
{{#each @rows as |row|}}
<li
data-instance={{row.id}}
data-integration={{row.type}}
class="flex items-center gap-3 rounded-lg border border-gray-200 p-3"
>
<Avatar @integration={{row}} />
<div class="min-w-0 flex-auto">
<p class="truncate text-sm font-medium text-gray-700">
{{row.label}}
</p>
<p class="truncate text-sm text-gray-500">{{row.byline}}</p>
{{#if row.error}}
<p class="truncate text-sm text-red-600">{{row.error}}</p>
{{/if}}
</div>
<div class="flex shrink-0 items-center">
{{#if row.hasSettings}}
<button
type="button"
data-test-settings
aria-label="Settings"
title="Settings"
{{on "click" (fn @onEdit row)}}
class={{ACTION_BUTTON_CLASS}}
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
aria-hidden="true"
class="size-5"
>
{{#each SETTINGS_ICON as |d|}}
<path
d={{d}}
stroke-linecap="round"
stroke-linejoin="round"
/>
{{/each}}
</svg>
</button>
{{/if}}
{{#if row.canReconnect}}
<button
type="button"
data-test-reconnect
aria-label="Reconnect"
title="Reconnect"
{{on "click" (fn @onReconnect row)}}
class={{ACTION_BUTTON_CLASS}}
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
aria-hidden="true"
class="size-5"
>
{{#each RECONNECT_ICON as |d|}}
<path
d={{d}}
stroke-linecap="round"
stroke-linejoin="round"
/>
{{/each}}
</svg>
</button>
{{/if}}
<button
type="button"
data-test-remove
aria-label="Remove"
title="Remove"
{{on "click" (fn @onRemove row)}}
class="rounded-md p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
aria-hidden="true"
class="size-5"
>
{{#each REMOVE_ICON as |d|}}
<path
d={{d}}
stroke-linecap="round"
stroke-linejoin="round"
/>
{{/each}}
</svg>
</button>
</div>
</li>
{{/each}}
</ul>
{{else}}
<p class="rounded-xl bg-gray-50 p-6 text-center text-sm text-gray-500">
{{@emptyLabel}}
</p>
{{/if}}
</template>
@@ -0,0 +1,80 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { formFor } from '../../../../config/integration-forms';
import { SITE_LINK_TYPES } from '../../../../config/sites';
import IntegrationGrid from './integration-grid.gjs';
// The integrations shown as dashboard quick links, moved out of Manage
// Integrations. Edit opens the integration form on top of the settings dialog.
export default class SettingsSiteLinksSection extends Component {
@service authorization;
@service integrationResult;
@service integrations;
@service sites;
@service modal;
get rows() {
return this.integrations.rows
.filter((row) => SITE_LINK_TYPES.includes(row.type))
.sort(
(a, b) =>
a.label.localeCompare(b.label) || a.byline.localeCompare(b.byline)
);
}
@action
edit(row) {
const component = formFor(row.type);
if (!component) {
return;
}
this.modal.open({
component,
props: { mode: 'edit', integration: row },
size: 'md',
});
}
@action
async reconnect(row) {
try {
const { transport } = await this.authorization.start(row.type, row.url);
if (transport === 'extension') {
await this.sites.reload();
await this.sites.refreshIcon(row.url);
}
} catch (err) {
console.error(`Error reconnecting ${row.type} integration:`, err);
this.integrationResult.show({
error: err?.message ?? 'Unable to reconnect this forum',
});
}
}
@action
async remove(row) {
await this.integrations.remove(row);
}
<template>
<div class="min-h-0 flex-1 overflow-y-auto px-6 py-6">
<p class="max-w-prose text-sm text-gray-500">
The sites shown as quick links on your dashboard.
</p>
<div class="mt-4">
<IntegrationGrid
@rows={{this.rows}}
@onEdit={{this.edit}}
@onReconnect={{this.reconnect}}
@onRemove={{this.remove}}
@emptyLabel="No site links connected yet."
/>
</div>
</div>
</template>
}
@@ -5,25 +5,26 @@ import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { formFor } from '../../../config/integration-forms';
import { CALENDAR_TYPES } from '../../../config/calendar';
import { SITE_LINK_TYPES } from '../../../config/sites';
import Avatar from './avatar.gjs';
export default class SettingsIntegrationsManageList extends Component {
@service authorization;
@service integrationResult;
@service integrations;
@service sites;
@service modal;
get rows() {
// Calendars are managed from the Events settings section, not here.
// Calendars and site links are managed from their own settings sections.
return this.integrations.rows.filter(
(row) => !CALENDAR_TYPES.includes(row.type)
(row) =>
!CALENDAR_TYPES.includes(row.type) &&
!SITE_LINK_TYPES.includes(row.type)
);
}
get hasCalendars() {
return this.integrations.rows.some((row) =>
CALENDAR_TYPES.includes(row.type)
get hasMovedIntegrations() {
return this.integrations.rows.some(
(row) =>
CALENDAR_TYPES.includes(row.type) || SITE_LINK_TYPES.includes(row.type)
);
}
@@ -42,23 +43,6 @@ export default class SettingsIntegrationsManageList extends Component {
});
}
@action
async reconnect(row) {
try {
const { transport } = await this.authorization.start(row.type, row.url);
if (transport === 'extension') {
await this.sites.reload();
await this.sites.refreshIcon(row.url);
}
} catch (err) {
console.error(`Error reconnecting ${row.type} integration:`, err);
this.integrationResult.show({
error: err?.message ?? 'Unable to reconnect this forum',
});
}
}
@action
async remove(row) {
await this.integrations.remove(row);
@@ -104,16 +88,6 @@ export default class SettingsIntegrationsManageList extends Component {
Settings
</button>
{{/if}}
{{#if row.canReconnect}}
<button
type="button"
data-test-reconnect
{{on "click" (fn this.reconnect row)}}
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-100"
>
Reconnect
</button>
{{/if}}
<button
type="button"
data-test-remove
@@ -131,8 +105,8 @@ export default class SettingsIntegrationsManageList extends Component {
You don't have any other integrations connected yet.
</p>
<p class="mt-1 text-sm text-gray-400">
{{#if this.hasCalendars}}
Your calendars are managed in Settings → Calendar.
{{#if this.hasMovedIntegrations}}
Calendars and site links are managed in Settings.
{{else}}
Use "Add Integration" to connect one.
{{/if}}
+2
View File
@@ -1,10 +1,12 @@
import Events from '../components/settings/global-settings/sections/events.gjs';
import ProtocolGateway from '../components/settings/global-settings/sections/protocol-gateway.gjs';
import SiteLinks from '../components/settings/global-settings/sections/site-links.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 = {
'site-links': SiteLinks,
events: Events,
'protocol-gateway': ProtocolGateway,
};
+6 -30
View File
@@ -4,7 +4,7 @@
// `icon` is an array of SVG path `d` strings (24x24 viewBox, stroke based) so
// the nav can stay data driven without a separate icon component. Icons come
// from Feather (https://feathericons.com) where an equivalent exists; the
// paint brush and puzzle piece are Heroicons because Feather has no match.
// paint brush and globe are Heroicons because Feather has no match.
export const SETTINGS_GROUPS = [
{
@@ -19,12 +19,11 @@ export const SETTINGS_GROUPS = [
'M9.53 16.122a3 3 0 0 0-5.78 1.128 2.25 2.25 0 0 1-2.4 2.245 4.5 4.5 0 0 0 8.4-2.245c0-.399-.078-.78-.22-1.128Zm0 0a15.998 15.998 0 0 0 3.388-1.62m-5.043-.025a15.994 15.994 0 0 1 1.622-3.395m3.42 3.42a15.995 15.995 0 0 0 4.764-4.648l3.876-5.814a1.151 1.151 0 0 0-1.597-1.597L14.146 6.32a15.996 15.996 0 0 0-4.649 4.763m3.42 3.42a6.776 6.776 0 0 0-3.42-3.42',
],
},
{
id: 'clock',
label: 'Clock',
description: 'Pick how times are displayed across the dashboard.',
icon: ['M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20z', 'M12 6v6l4 2'],
},
],
},
{
label: 'Integrations',
items: [
{
id: 'site-links',
label: 'Site Links',
@@ -34,20 +33,6 @@ export const SETTINGS_GROUPS = [
'M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71',
],
},
],
},
{
label: 'Integrations',
items: [
{
id: 'connected',
label: 'Connected Apps',
description: 'Review and configure your connected integrations.',
// Heroicons puzzle piece (no Feather equivalent).
icon: [
'M14.25 6.087c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.036-1.007-1.875-2.25-1.875s-2.25.84-2.25 1.875c0 .369.128.713.349 1.003.215.283.401.604.401.959v0a.64.64 0 0 1-.657.643 48.39 48.39 0 0 1-4.163-.3c.186 1.613.293 3.25.315 4.907a.656.656 0 0 1-.658.663v0c-.355 0-.676-.186-.959-.401a1.647 1.647 0 0 0-1.003-.349c-1.036 0-1.875 1.007-1.875 2.25s.84 2.25 1.875 2.25c.369 0 .713-.128 1.003-.349.283-.215.604-.401.959-.401v0c.31 0 .555.26.532.57a48.039 48.039 0 0 1-.642 5.056c1.518.19 3.058.309 4.616.354a.64.64 0 0 0 .657-.643v0c0-.355-.186-.676-.401-.959a1.647 1.647 0 0 1-.349-1.003c0-1.035 1.008-1.875 2.25-1.875 1.243 0 2.25.84 2.25 1.875 0 .369-.128.713-.349 1.003-.215.283-.4.604-.4.959v0c0 .333.277.599.61.58a48.1 48.1 0 0 0 5.427-.63 48.05 48.05 0 0 0 .582-4.717.532.532 0 0 0-.533-.57v0c-.355 0-.676.186-.959.401-.29.221-.634.349-1.003.349-1.035 0-1.875-1.007-1.875-2.25s.84-2.25 1.875-2.25c.37 0 .713.128 1.003.349.283.215.604.401.96.401v0a.656.656 0 0 0 .658-.663 48.422 48.422 0 0 0-.37-5.36c-1.886.342-3.81.574-5.766.689a.578.578 0 0 1-.61-.58v0Z',
],
},
{
id: 'events',
label: 'Calendar',
@@ -59,15 +44,6 @@ export const SETTINGS_GROUPS = [
'M3 10h18',
],
},
{
id: 'notifications',
label: 'Notifications',
description: 'Decide which events should notify you.',
icon: [
'M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9',
'M13.73 21a2 2 0 0 1-3.46 0',
],
},
],
},
{
+5
View File
@@ -20,3 +20,8 @@ export const SITE_GROUPS = [
integrationTypes: ['homeassistant'],
},
];
// The integration types that appear as dashboard quick links.
export const SITE_LINK_TYPES = SITE_GROUPS.flatMap(
(group) => group.integrationTypes
);
@@ -0,0 +1,296 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import SiteLinks from 'dashtab/components/settings/global-settings/sections/site-links';
class FakeSitesService {
@tracked all = [];
removed = [];
reloaded = 0;
refreshed = [];
integrationFor(id) {
return this.records?.[id];
}
async removeSource(id) {
this.removed.push(id);
this.all = this.all.filter((site) => site.id !== id);
}
async reload() {
this.reloaded++;
}
async refreshIcon(url) {
this.refreshed.push(url);
}
}
class FakeNotificationsService {
states = {};
stateFor(site) {
return this.states[site.id] ?? { error: null, errorType: null };
}
}
class FakeBitcoinService {
@tracked enabled = false;
@tracked interval = 30000;
@tracked provider = 'coingecko';
}
class FakeCalendarService {
instancesFor() {
return [];
}
}
class FakeAuthorizationService {
calls = [];
async start(type, url) {
this.calls.push({ type, url });
return { transport: 'extension', integration: { id: 'reconnected' } };
}
}
class FakeIntegrationResultService {
shown = [];
show(result) {
this.shown.push(result);
}
}
class FakeModalService {
opened = null;
open(descriptor) {
this.opened = descriptor;
}
replace(descriptor) {
this.opened = descriptor;
}
}
function register(owner, overrides = {}) {
const sites = overrides.sites ?? new FakeSitesService();
const notifications =
overrides.notifications ?? new FakeNotificationsService();
const bitcoin = overrides.bitcoin ?? new FakeBitcoinService();
const calendar = overrides.calendar ?? new FakeCalendarService();
const authorization =
overrides.authorization ?? new FakeAuthorizationService();
const integrationResult =
overrides.integrationResult ?? new FakeIntegrationResultService();
const modal = overrides.modal ?? new FakeModalService();
owner.register('service:sites', sites, { instantiate: false });
owner.register('service:notifications', notifications, {
instantiate: false,
});
owner.register('service:bitcoin', bitcoin, { instantiate: false });
owner.register('service:calendar', calendar, { instantiate: false });
owner.register('service:authorization', authorization, {
instantiate: false,
});
owner.register('service:integrationResult', integrationResult, {
instantiate: false,
});
owner.register('service:modal', modal, { instantiate: false });
return {
sites,
notifications,
bitcoin,
calendar,
authorization,
integrationResult,
modal,
};
}
module(
'Integration | Component | settings/global-settings/sections/site-links',
function (hooks) {
setupRenderingTest(hooks);
test('it lists the site links and hides other integrations', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-abc',
type: 'discourse',
label: 'forum.example.com',
url: 'https://forum.example.com',
},
{
id: 'github',
type: 'github',
label: 'GitHub',
href: 'https://github.com/notifications',
},
];
sites.records = { github: { url: 'https://github.com', token: 't' } };
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
register(this.owner, { sites, bitcoin });
await render(<template><SiteLinks /></template>);
assert.dom('[data-instance="discourse-abc"]').exists();
assert.dom('[data-instance="github"]').exists();
assert.dom('[data-instance="bitcoin"]').doesNotExist();
});
test('it sorts the site links alphabetically by name', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'github',
type: 'github',
label: 'GitHub',
href: 'https://github.com/notifications',
},
{
id: 'discourse-a',
type: 'discourse',
label: 'a.example.com',
url: 'https://a.example.com',
},
{
id: 'homeassistant-ha',
type: 'homeassistant',
label: 'ha.example.com',
href: 'https://ha.example.com/',
},
];
sites.records = {
github: { url: 'https://github.com', token: 't' },
'homeassistant-ha': {
url: 'https://ha.example.com',
token: 't',
name: 'Home',
},
};
register(this.owner, { sites });
await render(<template><SiteLinks /></template>);
const ids = [...this.element.querySelectorAll('[data-instance]')].map(
(el) => el.dataset.instance
);
assert.deepEqual(ids, ['discourse-a', 'github', 'homeassistant-ha']);
});
test('it offers settings only where the integration has them', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-abc',
type: 'discourse',
label: 'forum.example.com',
url: 'https://forum.example.com',
},
{
id: 'github',
type: 'github',
label: 'GitHub',
href: 'https://github.com/notifications',
},
];
sites.records = { github: { url: 'https://github.com', token: 't' } };
register(this.owner, { sites });
await render(<template><SiteLinks /></template>);
assert
.dom('[data-instance="discourse-abc"] [data-test-settings]')
.doesNotExist();
assert.dom('[data-instance="github"] [data-test-settings]').exists();
});
test('editing a site link opens its form', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'github',
type: 'github',
label: 'GitHub',
href: 'https://github.com/notifications',
},
];
sites.records = { github: { url: 'https://github.com', token: 't' } };
const { modal } = register(this.owner, { sites });
await render(<template><SiteLinks /></template>);
await click('[data-instance="github"] [data-test-settings]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'edit');
assert.strictEqual(modal.opened.props.integration.id, 'github');
});
test('reconnecting a broken site link runs the auth flow', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-bad',
type: 'discourse',
label: 'bad.example.com',
url: 'https://bad.example.com',
},
];
const notifications = new FakeNotificationsService();
notifications.states['discourse-bad'] = {
errorType: 'unauthorized',
error: 'Reconnect this forum',
};
const {
authorization,
sites: registeredSites,
integrationResult,
} = register(this.owner, { sites, notifications });
await render(<template><SiteLinks /></template>);
await click('[data-instance="discourse-bad"] [data-test-reconnect]');
assert.deepEqual(authorization.calls, [
{ type: 'discourse', url: 'https://bad.example.com' },
]);
assert.strictEqual(registeredSites.reloaded, 1);
assert.deepEqual(registeredSites.refreshed, ['https://bad.example.com']);
assert.strictEqual(integrationResult.shown.length, 0);
});
test('removing a site link removes the source', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-abc',
type: 'discourse',
label: 'forum.example.com',
url: 'https://forum.example.com',
},
];
register(this.owner, { sites });
await render(<template><SiteLinks /></template>);
await click('[data-instance="discourse-abc"] [data-test-remove]');
assert.deepEqual(sites.removed, ['discourse-abc']);
});
}
);
@@ -7,8 +7,6 @@ import List from 'dashtab/components/settings/integrations/manage-list';
class FakeSitesService {
@tracked all = [];
removed = [];
refreshed = [];
reloaded = 0;
integrationFor(id) {
return this.records?.[id];
@@ -18,14 +16,6 @@ class FakeSitesService {
this.removed.push(id);
this.all = this.all.filter((site) => site.id !== id);
}
async reload() {
this.reloaded++;
}
async refreshIcon(url) {
this.refreshed.push(url);
}
}
class FakeNotificationsService {
@@ -48,21 +38,14 @@ class FakeBitcoinService {
}
}
class FakeAuthorizationService {
calls = [];
class FakeCalendarService {
instancesByType = { 'calendar-caldav': [], 'calendar-ics': [] };
async start(type, url) {
this.calls.push({ type, url });
return { transport: 'extension', integration: { id: 'reconnected' } };
instancesFor(type) {
return this.instancesByType[type] ?? [];
}
}
class FakeIntegrationResultService {
shown = [];
show(result) {
this.shown.push(result);
}
async remove() {}
}
class FakeModalService {
@@ -82,10 +65,7 @@ function register(owner, overrides = {}) {
const notifications =
overrides.notifications ?? new FakeNotificationsService();
const bitcoin = overrides.bitcoin ?? new FakeBitcoinService();
const authorization =
overrides.authorization ?? new FakeAuthorizationService();
const integrationResult =
overrides.integrationResult ?? new FakeIntegrationResultService();
const calendar = overrides.calendar ?? new FakeCalendarService();
const modal = overrides.modal ?? new FakeModalService();
owner.register('service:sites', sites, { instantiate: false });
@@ -93,22 +73,10 @@ function register(owner, overrides = {}) {
instantiate: false,
});
owner.register('service:bitcoin', bitcoin, { instantiate: false });
owner.register('service:authorization', authorization, {
instantiate: false,
});
owner.register('service:integrationResult', integrationResult, {
instantiate: false,
});
owner.register('service:calendar', calendar, { instantiate: false });
owner.register('service:modal', modal, { instantiate: false });
return {
sites,
notifications,
bitcoin,
authorization,
integrationResult,
modal,
};
return { sites, notifications, bitcoin, calendar, modal };
}
module(
@@ -127,132 +95,7 @@ module(
.containsText("You don't have any other integrations connected yet");
});
test('it hides calendars, which are managed in Settings', async function (assert) {
this.owner.register(
'service:calendar',
{
instancesFor(type) {
return type === 'calendar-caldav'
? [
{
id: 'cal-1',
type: 'calendar-caldav',
label: 'Work',
url: 'https://cal.example.com',
},
]
: [];
},
},
{ instantiate: false }
);
register(this.owner);
await render(<template><List /></template>);
assert.dom('[data-integration="calendar-caldav"]').doesNotExist();
assert.dom().containsText('managed in Settings');
});
test('it lists one row per connected integration', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-abc',
type: 'discourse',
label: 'forum.example.com',
url: 'https://forum.example.com',
},
];
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
register(this.owner, { sites, bitcoin });
await render(<template><List /></template>);
assert.dom('[data-instance="discourse-abc"]').exists();
assert.dom('[data-instance="bitcoin"]').exists();
assert.dom('[data-integration="github"]').doesNotExist();
});
test('it lists integrations with settings above discourse sites', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-abc',
type: 'discourse',
label: 'forum.example.com',
url: 'https://forum.example.com',
},
];
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
register(this.owner, { sites, bitcoin });
await render(<template><List /></template>);
const ids = [...document.querySelectorAll('[data-instance]')].map(
(el) => el.dataset.instance
);
assert.deepEqual(ids, ['bitcoin', 'discourse-abc']);
});
test('it renders each discourse instance as its own row', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-abc',
type: 'discourse',
label: 'a.example.com',
url: 'https://a.example.com',
},
{
id: 'discourse-def',
type: 'discourse',
label: 'b.example.com',
url: 'https://b.example.com',
},
];
register(this.owner, { sites });
await render(<template><List /></template>);
assert.dom('[data-instance]').exists({ count: 2 });
assert.dom('[data-instance="discourse-abc"]').exists();
assert.dom('[data-instance="discourse-def"]').exists();
});
test('discourse rows show the integration name and the host as byline', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-abc',
type: 'discourse',
label: 'forum.example.com',
url: 'https://forum.example.com',
},
];
register(this.owner, { sites });
await render(<template><List /></template>);
assert.dom('[data-instance="discourse-abc"]').containsText('Discourse');
assert
.dom('[data-instance="discourse-abc"]')
.containsText('forum.example.com');
assert
.dom('[data-instance="discourse-abc"] [data-test-settings]')
.doesNotExist();
});
test('feature integrations keep their description as byline', async function (assert) {
test('it lists the remaining integrations', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
@@ -260,132 +103,46 @@ module(
await render(<template><List /></template>);
assert.dom('[data-instance="bitcoin"]').exists();
assert
.dom('[data-instance="bitcoin"]')
.containsText('Bitcoin Price Ticker');
assert
.dom('[data-instance="bitcoin"]')
.containsText('Live BTC price on your dashboard');
});
test('it only offers reconnect when auth is broken', async function (assert) {
test('it hides calendars and site links, which are managed in Settings', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-ok',
id: 'discourse-abc',
type: 'discourse',
label: 'ok.example.com',
url: 'https://ok.example.com',
},
{
id: 'discourse-bad',
type: 'discourse',
label: 'bad.example.com',
url: 'https://bad.example.com',
label: 'forum.example.com',
url: 'https://forum.example.com',
},
];
const notifications = new FakeNotificationsService();
notifications.states['discourse-bad'] = {
error: 'Access was rejected — reconnect this forum',
errorType: 'unauthorized',
};
register(this.owner, { sites, notifications });
await render(<template><List /></template>);
assert
.dom('[data-instance="discourse-ok"] [data-test-reconnect]')
.doesNotExist();
assert
.dom('[data-instance="discourse-bad"] [data-test-reconnect]')
.exists();
assert
.dom('[data-instance="discourse-bad"]')
.containsText('Access was rejected');
assert
.dom('[data-instance="discourse-bad"] [data-test-settings]')
.doesNotExist();
});
test('reconnecting runs the discourse auth flow', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
const calendar = new FakeCalendarService();
calendar.instancesByType['calendar-ics'] = [
{
id: 'discourse-bad',
type: 'discourse',
label: 'bad.example.com',
url: 'https://bad.example.com',
id: 'ics-1',
type: 'calendar-ics',
label: 'Holidays',
url: 'https://example.org/h.ics',
},
];
const notifications = new FakeNotificationsService();
notifications.states['discourse-bad'] = {
errorType: 'unauthorized',
error: 'Reconnect this forum',
};
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
const { authorization, integrationResult } = register(this.owner, {
sites,
notifications,
});
register(this.owner, { sites, calendar, bitcoin });
await render(<template><List /></template>);
await click('[data-instance="discourse-bad"] [data-test-reconnect]');
assert.deepEqual(authorization.calls, [
{ type: 'discourse', url: 'https://bad.example.com' },
]);
assert.strictEqual(sites.reloaded, 1);
assert.deepEqual(sites.refreshed, ['https://bad.example.com']);
assert.strictEqual(integrationResult.shown.length, 0);
assert.dom('[data-instance="bitcoin"]').exists();
assert.dom('[data-instance="discourse-abc"]').doesNotExist();
assert.dom('[data-instance="ics-1"]').doesNotExist();
});
test('a failed reconnect surfaces the error', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-bad',
type: 'discourse',
label: 'bad.example.com',
url: 'https://bad.example.com',
},
];
const notifications = new FakeNotificationsService();
notifications.states['discourse-bad'] = {
errorType: 'unauthorized',
error: 'Reconnect this forum',
};
const authorization = {
calls: [],
async start(type, url) {
this.calls.push({ type, url });
throw new Error('Authorization was cancelled');
},
};
const { integrationResult } = register(this.owner, {
sites,
notifications,
authorization,
});
await render(<template><List /></template>);
await click('[data-instance="discourse-bad"] [data-test-reconnect]');
assert.deepEqual(authorization.calls, [
{ type: 'discourse', url: 'https://bad.example.com' },
]);
assert.strictEqual(sites.reloaded, 0);
assert.deepEqual(integrationResult.shown, [
{ error: 'Authorization was cancelled' },
]);
});
test('removing an instance removes the source', async function (assert) {
test('the empty state points to Settings when calendars or site links exist', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
@@ -399,32 +156,31 @@ module(
register(this.owner, { sites });
await render(<template><List /></template>);
await click('[data-instance="discourse-abc"] [data-test-remove]');
assert.deepEqual(sites.removed, ['discourse-abc']);
assert.dom().containsText('managed in Settings');
});
test('editing a feature integration opens its form', async function (assert) {
test('editing an integration opens its form', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
bitcoin.interval = 60000;
bitcoin.provider = 'binance';
const { modal } = register(this.owner, { bitcoin });
await render(<template><List /></template>);
assert.dom('[data-instance="bitcoin"] [data-test-settings]').exists();
assert
.dom('[data-instance="bitcoin"] [data-test-reconnect]')
.doesNotExist();
await click('[data-instance="bitcoin"] [data-test-settings]');
assert.strictEqual(modal.replaced.props.mode, 'edit');
assert.strictEqual(modal.replaced.props.integration.interval, 60000);
assert.strictEqual(modal.replaced.props.integration.provider, 'binance');
});
test('removing an instance removes the source', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
register(this.owner, { bitcoin });
await render(<template><List /></template>);
await click('[data-instance="bitcoin"] [data-test-remove]');
assert.true(bitcoin.disabled);