Reorder the custom link option and its icon controls

Sort the generic "Custom Link" entry last in the add-integration dialog so
it reads as an "add anything" action after the concrete integrations, and
move the icon controls below the URL and name fields in the custom link
form so the form flows from link details to its optional icon.
This commit is contained in:
raucao committed 2026-11-13 21:09:21 +04:00
1 parent b057e3edca
commit 303b26793f
4 files changed
+92 -49

No files matched your search

@@ -6,6 +6,10 @@ import { service } from '@ember/service';
import { formFor } from '../../../config/integration-forms';
import Avatar from './avatar.gjs';
// Generic "add anything" entries sort after the concrete integrations instead
// of among them.
const LAST_TYPES = new Set(['custom']);
export default class SettingsIntegrationsAddList extends Component {
@service modal;
@service integrations;
@@ -25,7 +29,16 @@ export default class SettingsIntegrationsAddList extends Component {
integration.instances.length
)
)
.sort((a, b) => a.label.localeCompare(b.label));
.sort((a, b) => {
const aLast = LAST_TYPES.has(a.id);
const bLast = LAST_TYPES.has(b.id);
if (aLast !== bLast) {
return aLast ? 1 : -1;
}
return a.label.localeCompare(b.label);
});
}
@action
@@ -210,6 +210,54 @@ export default class SettingsIntegrationsCustomLinkForm extends Component {
<form {{on "submit" this.handleSubmit}} class="mt-5">
<div class="space-y-5">
<div>
<label
for="custom-link-url"
class="block text-sm font-medium leading-6 text-gray-900"
>
Website URL
</label>
<div class="mt-2">
<input
type="text"
inputmode="url"
id="custom-link-url"
name="url"
value={{this.url}}
{{on "input" this.updateUrl}}
{{on "blur" this.previewFromUrl}}
placeholder="example.com"
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">
A full address; if you leave out the scheme, https is assumed.
</p>
</div>
<div>
<label
for="custom-link-name"
class="block text-sm font-medium leading-6 text-gray-900"
>
Name
</label>
<div class="mt-2">
<input
type="text"
id="custom-link-name"
name="name"
value={{this.name}}
{{on "input" this.updateName}}
placeholder={{labelForUrl this.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">
Optional. Defaults to the site's hostname.
</p>
</div>
<div class="flex items-center gap-4">
<div class="shrink-0">
{{#if this.hasPreview}}
@@ -265,54 +313,6 @@ export default class SettingsIntegrationsCustomLinkForm extends Component {
</div>
</div>
<div>
<label
for="custom-link-url"
class="block text-sm font-medium leading-6 text-gray-900"
>
Website URL
</label>
<div class="mt-2">
<input
type="text"
inputmode="url"
id="custom-link-url"
name="url"
value={{this.url}}
{{on "input" this.updateUrl}}
{{on "blur" this.previewFromUrl}}
placeholder="example.com"
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">
A full address; if you leave out the scheme, https is assumed.
</p>
</div>
<div>
<label
for="custom-link-name"
class="block text-sm font-medium leading-6 text-gray-900"
>
Name
</label>
<div class="mt-2">
<input
type="text"
id="custom-link-name"
name="name"
value={{this.name}}
{{on "input" this.updateName}}
placeholder={{labelForUrl this.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">
Optional. Defaults to the site's hostname.
</p>
</div>
{{#if this.error}}
<p class="text-sm text-red-600" data-test-error>{{this.error}}</p>
{{/if}}
@@ -172,6 +172,19 @@ module(
]);
});
test('it sorts the generic Custom Link type last', async function (assert) {
register(this.owner);
const props = { types: ['custom', 'discourse', 'github'] };
await render(<template><List @props={{props}} /></template>);
const ids = [...this.element.querySelectorAll('[data-add]')].map(
(el) => el.dataset.add
);
assert.deepEqual(ids, ['discourse', 'github', 'custom']);
});
test('clicking an integration opens its add form', async function (assert) {
const { modal } = register(this.owner);
@@ -49,6 +49,23 @@ module(
assert.dom('[data-test-icon-upload]').exists();
});
test('it places the icon controls after the URL and name fields', async function (assert) {
registerServices(this.owner);
await render(<template><CustomLinkForm @close={{noop}} /></template>);
const name = this.element.querySelector('#custom-link-name');
const upload = this.element.querySelector('[data-test-icon-upload]');
assert.true(
Boolean(
name.compareDocumentPosition(upload) &
Node.DOCUMENT_POSITION_FOLLOWING
),
'the icon controls come after the name field'
);
});
test('it rejects an empty or invalid URL without storing anything', async function (assert) {
const saved = [];
registerServices(this.owner, {