Files
raucao f485093ab0 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.
2026-11-06 17:01:33 +04:00

104 lines
2.7 KiB
Plaintext

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
// 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);
}
@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.
</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 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>
}