WIP: Add site links from the Site Links settings section

Add an 'Add site link' button at the bottom of the Site Links pane that opens the Add Integration menu scoped to the still-available site integrations.

The menu accepts an optional type filter and now lists its items alphabetically by integration name.
This commit is contained in:
raucao committed 2026-11-06 17:01:33 +04:00
1 parent b2ae4f090f
commit f485093ab0
4 files changed
+85 -8

No files matched your search

@@ -1,8 +1,10 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { formFor } from '../../../../config/integration-forms';
import { SITE_LINK_TYPES } from '../../../../config/sites';
import AddList from '../../integrations/add-list.gjs';
import IntegrationGrid from './integration-grid.gjs';
// The integrations shown as dashboard quick links, moved out of Manage
@@ -60,10 +62,20 @@ export default class SettingsSiteLinksSection extends Component {
await this.integrations.remove(row);
}
@action
add() {
this.modal.open({
component: AddList,
props: { types: SITE_LINK_TYPES },
size: 'md',
});
}
<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 with notification badges on your dashboard.
The sites shown as quick links with notification badges on your
dashboard.
</p>
<div class="mt-4">
@@ -75,6 +87,17 @@ export default class SettingsSiteLinksSection extends Component {
@emptyLabel="No site links connected yet."
/>
</div>
<div class="mt-6 flex flex-wrap gap-2">
<button
type="button"
data-test-add
{{on "click" this.add}}
class="rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
Add site link
</button>
</div>
</div>
</template>
}
@@ -11,14 +11,21 @@ export default class SettingsIntegrationsAddList extends Component {
@service integrations;
get items() {
const types = this.args.props?.types;
// Single-instance integrations that are already connected are managed from
// the Manage dialog instead of being offered again here.
return this.integrations.all.filter(
(integration) =>
!(
integration.supportsMultiple === false && integration.instances.length
)
);
// the Manage dialog instead of being offered again here. An optional
// `types` filter scopes the menu to a subset (e.g. only site links).
return this.integrations.all
.filter(
(integration) =>
(!types || types.includes(integration.id)) &&
!(
integration.supportsMultiple === false &&
integration.instances.length
)
)
.sort((a, b) => a.label.localeCompare(b.label));
}
@action
@@ -3,6 +3,8 @@ 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';
import AddList from 'dashtab/components/settings/integrations/add-list';
import { SITE_LINK_TYPES } from 'dashtab/config/sites';
class FakeSitesService {
@tracked all = [];
@@ -292,5 +294,15 @@ module(
assert.deepEqual(sites.removed, ['discourse-abc']);
});
test('adding opens the site integration menu', async function (assert) {
const { modal } = register(this.owner);
await render(<template><SiteLinks /></template>);
await click('[data-test-add]');
assert.strictEqual(modal.opened.component, AddList);
assert.deepEqual(modal.opened.props.types, SITE_LINK_TYPES);
});
}
);
@@ -101,6 +101,41 @@ module(
assert.dom('[data-add="homeassistant"]').doesNotHaveAttribute('disabled');
});
test('it can be scoped to a subset of integration types', async function (assert) {
register(this.owner);
const props = { types: ['discourse', 'feedbin'] };
await render(<template><List @props={{props}} /></template>);
assert.dom('[data-add="discourse"]').exists();
assert.dom('[data-add="feedbin"]').exists();
assert.dom('[data-add="github"]').doesNotExist();
assert.dom('[data-add="homeassistant"]').doesNotExist();
assert.dom('[data-add="calendar-caldav"]').doesNotExist();
});
test('it sorts the available integrations by name', async function (assert) {
register(this.owner);
const props = {
types: ['discourse', 'github', 'gitea', 'feedbin', 'homeassistant'],
};
await render(<template><List @props={{props}} /></template>);
const ids = [...this.element.querySelectorAll('[data-add]')].map(
(el) => el.dataset.add
);
assert.deepEqual(ids, [
'discourse',
'feedbin',
'gitea',
'github',
'homeassistant',
]);
});
test('clicking an integration opens its add form', async function (assert) {
const { modal } = register(this.owner);