Add integration management with editable settings
Rework the integration UI so Add and Manage are separate surfaces, only active integrations appear in Manage, and integrations with settings (e.g. Bitcoin) can be edited via the same form used to add them. Replace the ModalDialog/initialComponent flow with a modal service and a single ModalHost that lazily mounts each dialog body, so forms and custom elements start fresh per open. Move integration components to settings/integrations, add an integrations service that unifies registry capabilities with live instances, and fix the select value refresh and bitcoin config reset.
This commit is contained in:
1 parent
5643de9915
commit
abfbabb416
38 files changed
+1749
-785
No files matched your search
@@ -1,8 +1,12 @@
|
||||
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';
|
||||
|
||||
export default class BitcoinTickerComponent extends Component {
|
||||
@service bitcoin;
|
||||
@service modal;
|
||||
|
||||
get formattedPrice() {
|
||||
if (this.bitcoin.price == null) {
|
||||
@@ -27,9 +31,23 @@ export default class BitcoinTickerComponent extends Component {
|
||||
return this.isUp ? 'text-green-400' : 'text-red-400';
|
||||
}
|
||||
|
||||
@action
|
||||
openSettings() {
|
||||
this.modal.open({
|
||||
component: formFor('bitcoin'),
|
||||
props: { mode: 'edit' },
|
||||
size: 'md',
|
||||
});
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if this.bitcoin.enabled}}
|
||||
<div class="text-center text-white text-shadow-lg">
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.openSettings}}
|
||||
aria-label="Edit Bitcoin ticker settings"
|
||||
class="cursor-pointer rounded-lg text-center text-white text-shadow-lg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white/70"
|
||||
>
|
||||
<div class="flex items-center justify-center gap-1.5">
|
||||
<span class="text-lg font-semibold">{{this.formattedPrice}}</span>
|
||||
{{#if this.hasChange}}
|
||||
@@ -52,7 +70,7 @@ export default class BitcoinTickerComponent extends Component {
|
||||
{{#if this.bitcoin.error}}
|
||||
<div class="text-xs text-red-300">{{this.bitcoin.error}}</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
</button>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { service } from '@ember/service';
|
||||
import { modifier } from 'ember-modifier';
|
||||
import ModalDialog from './modal-dialog.gjs';
|
||||
import IntegrationResult from './settings/add-integration/result.gjs';
|
||||
|
||||
const autoOpenDialog = modifier(() => {
|
||||
setTimeout(() => {
|
||||
const dialog = document.getElementById('integration-result-dialog');
|
||||
if (dialog && !dialog.open) {
|
||||
dialog.showModal();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
|
||||
export default class IntegrationResultModalComponent extends Component {
|
||||
@service integrationResult;
|
||||
|
||||
get result() {
|
||||
return this.integrationResult.result;
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if this.result}}
|
||||
<div {{autoOpenDialog}}>
|
||||
<ModalDialog @id="integration-result-dialog" @maxWidth="sm">
|
||||
<div class="px-4 pt-5 pb-4 sm:p-6">
|
||||
<IntegrationResult @result={{this.result}} />
|
||||
</div>
|
||||
</ModalDialog>
|
||||
</div>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import AddList from './settings/integrations/add-list.gjs';
|
||||
import ManageList from './settings/integrations/manage-list.gjs';
|
||||
|
||||
export default class IntegrationsToolbarComponent extends Component {
|
||||
@service modal;
|
||||
|
||||
@action
|
||||
openAdd() {
|
||||
this.modal.open({ component: AddList, size: 'md' });
|
||||
}
|
||||
|
||||
@action
|
||||
openManage() {
|
||||
this.modal.open({ component: ManageList, size: 'xl' });
|
||||
}
|
||||
|
||||
<template>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.openAdd}}
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10"
|
||||
>
|
||||
Add Integration
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.openManage}}
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10"
|
||||
>
|
||||
Manage Integrations
|
||||
</button>
|
||||
</template>
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { hash } from '@ember/helper';
|
||||
import { modifier } from 'ember-modifier';
|
||||
|
||||
export default class ModalDialogComponent extends Component {
|
||||
@tracked currentComponent = null;
|
||||
@tracked componentProps = null;
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.currentComponent = this.args.initialComponent;
|
||||
this.componentProps = this.args.initialProps ?? {};
|
||||
}
|
||||
|
||||
setupDialog = modifier((element) => {
|
||||
const handleClose = () => {
|
||||
// Reset to initial component when dialog closes
|
||||
this.currentComponent = this.args.initialComponent;
|
||||
this.componentProps = this.args.initialProps || {};
|
||||
};
|
||||
|
||||
element.addEventListener('close', handleClose);
|
||||
|
||||
return () => {
|
||||
element.removeEventListener('close', handleClose);
|
||||
};
|
||||
});
|
||||
|
||||
get maxWidthClass() {
|
||||
const widths = {
|
||||
sm: 'sm:max-w-sm',
|
||||
md: 'sm:max-w-md',
|
||||
lg: 'sm:max-w-lg',
|
||||
xl: 'sm:max-w-xl',
|
||||
'2xl': 'sm:max-w-2xl',
|
||||
'3xl': 'sm:max-w-3xl',
|
||||
'4xl': 'sm:max-w-4xl',
|
||||
'5xl': 'sm:max-w-5xl',
|
||||
'6xl': 'sm:max-w-6xl',
|
||||
'7xl': 'sm:max-w-7xl',
|
||||
};
|
||||
return widths[this.args.maxWidth || 'md'] || widths.md;
|
||||
}
|
||||
|
||||
@action
|
||||
switchComponent(component, props = {}) {
|
||||
this.currentComponent = component;
|
||||
this.componentProps = props;
|
||||
}
|
||||
|
||||
@action
|
||||
closeDialog() {
|
||||
const dialog = document.getElementById(this.args.id);
|
||||
if (dialog) {
|
||||
dialog.close();
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
<el-dialog>
|
||||
<dialog
|
||||
id={{@id}}
|
||||
aria-labelledby="dialog-title"
|
||||
class="fixed inset-0 size-auto max-h-none max-w-none overflow-y-auto bg-transparent backdrop:bg-transparent"
|
||||
{{this.setupDialog}}
|
||||
>
|
||||
<el-dialog-backdrop
|
||||
class="fixed inset-0 bg-neutral-950/75 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in"
|
||||
></el-dialog-backdrop>
|
||||
<div
|
||||
tabindex="0"
|
||||
class="flex min-h-full items-end justify-center p-4 text-center focus:outline-none sm:items-center sm:p-0"
|
||||
>
|
||||
<el-dialog-panel
|
||||
class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full
|
||||
{{this.maxWidthClass}}
|
||||
data-closed:sm:translate-y-0 data-closed:sm:scale-95"
|
||||
>
|
||||
{{#if this.currentComponent}}
|
||||
<this.currentComponent
|
||||
@switchComponent={{this.switchComponent}}
|
||||
@closeDialog={{this.closeDialog}}
|
||||
...attributes
|
||||
/>
|
||||
{{else}}
|
||||
{{yield
|
||||
(hash
|
||||
switchComponent=this.switchComponent
|
||||
closeDialog=this.closeDialog
|
||||
)
|
||||
}}
|
||||
{{/if}}
|
||||
</el-dialog-panel>
|
||||
</div>
|
||||
</dialog>
|
||||
</el-dialog>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { service } from '@ember/service';
|
||||
import { modifier } from 'ember-modifier';
|
||||
|
||||
const WIDTHS = {
|
||||
sm: 'sm:max-w-sm',
|
||||
md: 'sm:max-w-md',
|
||||
lg: 'sm:max-w-lg',
|
||||
xl: 'sm:max-w-xl',
|
||||
'2xl': 'sm:max-w-2xl',
|
||||
'3xl': 'sm:max-w-3xl',
|
||||
};
|
||||
|
||||
export default class ModalHostComponent extends Component {
|
||||
@service modal;
|
||||
|
||||
dialogElement = null;
|
||||
|
||||
get currentComponent() {
|
||||
return this.modal.current?.component;
|
||||
}
|
||||
|
||||
get maxWidthClass() {
|
||||
const size = this.modal.current?.size ?? 'md';
|
||||
return WIDTHS[size] || WIDTHS.md;
|
||||
}
|
||||
|
||||
trackDialog = modifier((element) => {
|
||||
this.dialogElement = element;
|
||||
|
||||
queueMicrotask(() => {
|
||||
if (element.isConnected && !element.open) {
|
||||
element.showModal();
|
||||
}
|
||||
});
|
||||
|
||||
const handleClose = () => {
|
||||
this.dialogElement = null;
|
||||
this.modal.finished();
|
||||
};
|
||||
|
||||
element.addEventListener('close', handleClose);
|
||||
|
||||
return () => {
|
||||
element.removeEventListener('close', handleClose);
|
||||
this.dialogElement = null;
|
||||
};
|
||||
});
|
||||
|
||||
@action
|
||||
close() {
|
||||
this.dialogElement?.close();
|
||||
}
|
||||
|
||||
@action
|
||||
replace(descriptor) {
|
||||
this.modal.replace(descriptor);
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if this.modal.current}}
|
||||
<el-dialog>
|
||||
<dialog
|
||||
id="app-modal"
|
||||
aria-labelledby="modal-title"
|
||||
class="fixed inset-0 size-auto max-h-none max-w-none overflow-y-auto bg-transparent backdrop:bg-transparent"
|
||||
{{this.trackDialog}}
|
||||
>
|
||||
<el-dialog-backdrop
|
||||
class="fixed inset-0 bg-neutral-950/75 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in"
|
||||
></el-dialog-backdrop>
|
||||
<div
|
||||
tabindex="0"
|
||||
class="flex min-h-full items-end justify-center p-4 text-center focus:outline-none sm:items-center sm:p-0"
|
||||
>
|
||||
<el-dialog-panel
|
||||
class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full
|
||||
{{this.maxWidthClass}}
|
||||
data-closed:sm:translate-y-0 data-closed:sm:scale-95"
|
||||
>
|
||||
<this.currentComponent
|
||||
@props={{this.modal.current.props}}
|
||||
@close={{this.close}}
|
||||
@replace={{this.replace}}
|
||||
/>
|
||||
</el-dialog-panel>
|
||||
</div>
|
||||
</dialog>
|
||||
</el-dialog>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { on } from '@ember/modifier';
|
||||
import { fn } from '@ember/helper';
|
||||
import ModalStepTwo from './modal-step-two.gjs';
|
||||
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<h3
|
||||
id="dialog-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Step 1: Welcome</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
This is the first step of the workflow. Click next to continue.
|
||||
</p>
|
||||
</div>
|
||||
<div class="mt-5 sm:mt-6 flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" (fn @switchComponent ModalStepTwo)}}
|
||||
class="inline-flex w-full 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 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>
|
||||
Next
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @closeDialog}}
|
||||
class="inline-flex w-full justify-center 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"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,33 +0,0 @@
|
||||
import { on } from '@ember/modifier';
|
||||
import { fn } from '@ember/helper';
|
||||
import ModalStepOne from './modal-step-one.gjs';
|
||||
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<h3
|
||||
id="dialog-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Step 2: Configuration</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
This is the second step. You can go back or finish.
|
||||
</p>
|
||||
</div>
|
||||
<div class="mt-5 sm:mt-6 flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @closeDialog}}
|
||||
class="inline-flex w-full 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 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>
|
||||
Finish
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" (fn @switchComponent ModalStepOne)}}
|
||||
class="inline-flex w-full justify-center 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"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,196 +0,0 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { fn } from '@ember/helper';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import Discourse from './discourse.gjs';
|
||||
import Bitcoin from './bitcoin.gjs';
|
||||
|
||||
export default class SettingsAddIntegrationList extends Component {
|
||||
@service authorization;
|
||||
@service integrationResult;
|
||||
@service sites;
|
||||
@service notifications;
|
||||
|
||||
get connected() {
|
||||
return this.sites.all.map((site) => ({
|
||||
...site,
|
||||
error: this.notifications.stateFor(site).error,
|
||||
canReconnect: site.type === 'discourse',
|
||||
}));
|
||||
}
|
||||
|
||||
@action
|
||||
async reconnect(source) {
|
||||
try {
|
||||
const { transport, integration } = await this.authorization.start(
|
||||
'discourse',
|
||||
source.url
|
||||
);
|
||||
|
||||
if (transport === 'extension') {
|
||||
await this.sites.reload();
|
||||
this.integrationResult.show({ success: true, integration });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error reconnecting Discourse integration:', err);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
async remove(source) {
|
||||
await this.sites.removeSource(source.id);
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="block max-h-96 p-4 transform-gpu scroll-py-3 overflow-y-auto">
|
||||
{{#if this.connected.length}}
|
||||
<p
|
||||
class="px-3 pb-1 text-xs font-semibold tracking-wide text-gray-500 uppercase"
|
||||
>
|
||||
Connected
|
||||
</p>
|
||||
{{#each this.connected as |source|}}
|
||||
<div
|
||||
class="flex items-center gap-3 rounded-xl p-3"
|
||||
data-connected={{source.id}}
|
||||
>
|
||||
<div class="flex-auto text-left">
|
||||
<p class="text-sm font-medium text-gray-700">{{source.label}}</p>
|
||||
{{#if source.error}}
|
||||
<p class="text-sm text-red-600">{{source.error}}</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#if source.canReconnect}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-reconnect
|
||||
{{on "click" (fn this.reconnect source)}}
|
||||
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-50"
|
||||
>
|
||||
Reconnect
|
||||
</button>
|
||||
{{/if}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-remove
|
||||
{{on "click" (fn this.remove source)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-red-600 ring-1 ring-inset ring-red-200 hover:bg-red-50"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
{{/each}}
|
||||
|
||||
<div class="my-2 border-t border-gray-200"></div>
|
||||
{{/if}}
|
||||
|
||||
<p
|
||||
class="px-3 pb-1 text-xs font-semibold tracking-wide text-gray-500 uppercase"
|
||||
>
|
||||
Add integration
|
||||
</p>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" (fn @switchComponent Discourse)}}
|
||||
class="group flex w-full rounded-xl p-3 cursor-pointer select-none focus:outline-hidden hover:bg-gray-100 aria-selected:bg-gray-100"
|
||||
>
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg bg-indigo-500"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4 flex-auto text-left">
|
||||
<p
|
||||
id="item-discourse-label"
|
||||
class="text-sm font-medium text-gray-700 group-aria-selected:text-gray-900"
|
||||
>
|
||||
Discourse
|
||||
</p>
|
||||
<p class="text-sm text-gray-500 group-aria-selected:text-gray-700">
|
||||
Notifications from your discussion forums
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" (fn @switchComponent Bitcoin)}}
|
||||
class="group flex w-full rounded-xl p-3 cursor-pointer select-none focus:outline-hidden hover:bg-gray-100 aria-selected:bg-gray-100"
|
||||
>
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg bg-orange-500"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d="M23.638 14.904c-1.602 6.43-8.113 10.34-14.542 8.736C2.67 22.05-1.244 15.525.362 9.105 1.962 2.67 8.475-1.243 14.9.358c6.43 1.605 10.342 8.115 8.738 14.546zm-6.35-4.613c.24-1.59-.974-2.45-2.64-3.03l.54-2.153-1.315-.328-.525 2.107c-.345-.087-.705-.167-1.064-.25l.526-2.127-1.32-.33-.54 2.165c-.285-.067-.565-.132-.84-.2l-.006-.02-1.815-.45-.35 1.407s.975.225.955.238c.535.136.63.486.615.766l-.862 3.454c-.04.1-.14.25-.365.195.01.014-.95-.237-.95-.237l-.656 1.51 1.72.43c.32.08.634.16.955.25l-.54 2.2 1.32.33.54-2.18c.36.1.71.19 1.05.28l-.53 2.16 1.31.33.54-2.2c2.28.43 3.99.26 4.71-1.8.58-1.65-.03-2.6-1.22-3.22.87-.2 1.53-.78 1.7-1.96z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4 flex-auto text-left">
|
||||
<p
|
||||
id="item-bitcoin-label"
|
||||
class="text-sm font-medium text-gray-700 group-aria-selected:text-gray-900"
|
||||
>
|
||||
Bitcoin Price Ticker
|
||||
</p>
|
||||
<p class="text-sm text-gray-500 group-aria-selected:text-gray-700">
|
||||
Live BTC price on your dashboard
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
disabled
|
||||
class="group flex w-full cursor-default rounded-xl p-3 select-none focus:outline-hidden"
|
||||
>
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg bg-gray-300"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4 flex-auto text-left">
|
||||
<p id="item-gitea-label" class="text-sm font-medium text-gray-400">
|
||||
Gitea
|
||||
</p>
|
||||
<p class="text-sm text-gray-400">
|
||||
Notifications from your Git hosting servers
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { fn } from '@ember/helper';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import { formFor } from '../../../config/integration-forms';
|
||||
|
||||
export default class SettingsIntegrationsAddList extends Component {
|
||||
@service modal;
|
||||
@service integrations;
|
||||
|
||||
get items() {
|
||||
// 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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
add(integration) {
|
||||
const component = formFor(integration.id);
|
||||
|
||||
if (!integration.available || !component) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.modal.replace({ component, props: { mode: 'add' }, size: 'md' });
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<h3
|
||||
id="modal-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Add Integration</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
Choose an integration to connect to your dashboard.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 -mx-3 max-h-[80vh] overflow-y-auto">
|
||||
{{#each this.items as |integration|}}
|
||||
<button
|
||||
type="button"
|
||||
disabled={{not integration.available}}
|
||||
data-add={{integration.id}}
|
||||
{{on "click" (fn this.add integration)}}
|
||||
class="group flex w-full rounded-xl p-3 select-none focus:outline-hidden
|
||||
{{if
|
||||
integration.available
|
||||
'cursor-pointer hover:bg-gray-100'
|
||||
'cursor-default'
|
||||
}}"
|
||||
>
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg
|
||||
{{integration.colorClass}}"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill={{if integration.iconFill "currentColor" "none"}}
|
||||
stroke={{if integration.iconFill "none" "currentColor"}}
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d={{integration.iconPath}}
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4 flex-auto text-left">
|
||||
<p
|
||||
class="text-sm font-medium
|
||||
{{if integration.available 'text-gray-700' 'text-gray-400'}}"
|
||||
>
|
||||
{{integration.label}}
|
||||
</p>
|
||||
<p
|
||||
class="text-sm
|
||||
{{if integration.available 'text-gray-500' 'text-gray-400'}}"
|
||||
>
|
||||
{{integration.description}}
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
{{/each}}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
+75
-12
@@ -3,6 +3,7 @@ import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { service } from '@ember/service';
|
||||
import { on } from '@ember/modifier';
|
||||
import { modifier } from 'ember-modifier';
|
||||
import SettingsSelect from './select.gjs';
|
||||
import {
|
||||
BITCOIN_DEFAULT_INTERVAL,
|
||||
@@ -11,11 +12,67 @@ import {
|
||||
BITCOIN_PROVIDERS,
|
||||
} from '../../../services/bitcoin';
|
||||
|
||||
export default class SettingsAddIntegrationBitcoin extends Component {
|
||||
export default class SettingsIntegrationsBitcoinForm extends Component {
|
||||
@service bitcoin;
|
||||
|
||||
@tracked interval = BITCOIN_DEFAULT_INTERVAL;
|
||||
@tracked provider = BITCOIN_DEFAULT_PROVIDER;
|
||||
// User edits are kept as drafts so the displayed values can fall back to the
|
||||
// persisted integration or the live service state. This keeps the form safe
|
||||
// to mount anywhere, even before the bitcoin service has finished loading.
|
||||
@tracked intervalDraft = null;
|
||||
@tracked providerDraft = null;
|
||||
|
||||
get integration() {
|
||||
return this.args.props?.integration;
|
||||
}
|
||||
|
||||
get interval() {
|
||||
return (
|
||||
this.intervalDraft ??
|
||||
this.integration?.interval ??
|
||||
this.bitcoin.interval ??
|
||||
BITCOIN_DEFAULT_INTERVAL
|
||||
);
|
||||
}
|
||||
|
||||
get provider() {
|
||||
return (
|
||||
this.providerDraft ??
|
||||
this.integration?.provider ??
|
||||
this.bitcoin.provider ??
|
||||
BITCOIN_DEFAULT_PROVIDER
|
||||
);
|
||||
}
|
||||
|
||||
resetOnClose = modifier((element) => {
|
||||
const dialog = element.closest('dialog');
|
||||
|
||||
if (!dialog) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
this.intervalDraft = null;
|
||||
this.providerDraft = null;
|
||||
};
|
||||
|
||||
dialog.addEventListener('close', handleClose);
|
||||
|
||||
return () => dialog.removeEventListener('close', handleClose);
|
||||
});
|
||||
|
||||
get isEdit() {
|
||||
return this.args.props?.mode === 'edit';
|
||||
}
|
||||
|
||||
get title() {
|
||||
return this.isEdit
|
||||
? 'Edit Bitcoin Price Ticker'
|
||||
: 'Add Bitcoin Price Ticker';
|
||||
}
|
||||
|
||||
get submitLabel() {
|
||||
return this.isEdit ? 'Save' : 'Enable';
|
||||
}
|
||||
|
||||
get intervalOptions() {
|
||||
return BITCOIN_INTERVAL_OPTIONS;
|
||||
@@ -27,27 +84,33 @@ export default class SettingsAddIntegrationBitcoin extends Component {
|
||||
|
||||
@action
|
||||
updateInterval(value) {
|
||||
this.interval = Number(value);
|
||||
this.intervalDraft = Number(value);
|
||||
}
|
||||
|
||||
@action
|
||||
updateProvider(value) {
|
||||
this.provider = value;
|
||||
this.providerDraft = value;
|
||||
}
|
||||
|
||||
@action
|
||||
async handleSubmit(event) {
|
||||
event.preventDefault();
|
||||
await this.bitcoin.enable(this.interval, this.provider);
|
||||
this.args.closeDialog();
|
||||
|
||||
if (this.isEdit) {
|
||||
await this.bitcoin.update(this.interval, this.provider);
|
||||
} else {
|
||||
await this.bitcoin.enable(this.interval, this.provider);
|
||||
}
|
||||
|
||||
this.args.close?.();
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<div class="p-6" {{this.resetOnClose}}>
|
||||
<h3
|
||||
id="dialog-title"
|
||||
id="modal-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Add Bitcoin Price Ticker</h3>
|
||||
>{{this.title}}</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
Show the current Bitcoin price at the top of your dashboard.
|
||||
@@ -80,11 +143,11 @@ export default class SettingsAddIntegrationBitcoin extends Component {
|
||||
type="submit"
|
||||
class="inline-flex w-full 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 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>
|
||||
Enable
|
||||
{{this.submitLabel}}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @closeDialog}}
|
||||
{{on "click" @close}}
|
||||
class="inline-flex w-full justify-center 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"
|
||||
>
|
||||
Cancel
|
||||
+5
-4
@@ -4,7 +4,7 @@ import { action } from '@ember/object';
|
||||
import { service } from '@ember/service';
|
||||
import { on } from '@ember/modifier';
|
||||
|
||||
export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
export default class SettingsIntegrationsDiscourseForm extends Component {
|
||||
@service authorization;
|
||||
@service integrationResult;
|
||||
@service sites;
|
||||
@@ -33,8 +33,9 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
// away to the forum and returns through the callback route instead.
|
||||
if (transport === 'extension') {
|
||||
await this.sites.reload();
|
||||
// The result replaces this form inside the same modal; closing here
|
||||
// would dismiss it immediately.
|
||||
this.integrationResult.show({ success: true, integration });
|
||||
this.args.closeDialog?.();
|
||||
}
|
||||
} catch (err) {
|
||||
if (err?.message === 'Please enter a Discourse URL') {
|
||||
@@ -52,7 +53,7 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<h3
|
||||
id="dialog-title"
|
||||
id="modal-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Add Discourse Integration</h3>
|
||||
<div class="mt-2">
|
||||
@@ -93,7 +94,7 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @closeDialog}}
|
||||
{{on "click" @close}}
|
||||
class="inline-flex w-full justify-center 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"
|
||||
>
|
||||
Cancel
|
||||
@@ -0,0 +1,231 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { fn } from '@ember/helper';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import { formFor } from '../../../config/integration-forms';
|
||||
|
||||
export default class SettingsIntegrationsManageList extends Component {
|
||||
@service authorization;
|
||||
@service integrationResult;
|
||||
@service integrations;
|
||||
@service sites;
|
||||
@service modal;
|
||||
|
||||
get items() {
|
||||
return this.integrations.active.map((integration) => ({
|
||||
...integration,
|
||||
// Single-instance integrations are not grouped: their actions live on
|
||||
// the main row instead of a nested entry.
|
||||
single:
|
||||
!integration.supportsMultiple && integration.instances.length > 0
|
||||
? integration.instances[0]
|
||||
: null,
|
||||
}));
|
||||
}
|
||||
|
||||
@action
|
||||
add(integration) {
|
||||
const component = formFor(integration.id);
|
||||
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.modal.replace({ component, props: { mode: 'add' }, size: 'md' });
|
||||
}
|
||||
|
||||
@action
|
||||
edit(instance) {
|
||||
const component = formFor(instance.type);
|
||||
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.modal.replace({
|
||||
component,
|
||||
props: { mode: 'edit', integration: instance },
|
||||
size: 'md',
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
async reconnect(instance) {
|
||||
try {
|
||||
const { transport, integration } = await this.authorization.start(
|
||||
'discourse',
|
||||
instance.url
|
||||
);
|
||||
|
||||
if (transport === 'extension') {
|
||||
await this.sites.reload();
|
||||
this.integrationResult.show({ success: true, integration });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error reconnecting Discourse integration:', err);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
async remove(instance) {
|
||||
await this.integrations.remove(instance);
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<h3
|
||||
id="modal-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Manage Integrations</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
Review your connected integrations and adjust their settings.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{{#if this.items.length}}
|
||||
<div class="mt-4 min-h-72 max-h-[80vh] overflow-y-auto">
|
||||
{{#each this.items as |integration|}}
|
||||
<section
|
||||
data-integration={{integration.id}}
|
||||
class="border-b border-gray-100 py-3 last:border-b-0"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg
|
||||
{{integration.colorClass}}"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill={{if integration.iconFill "currentColor" "none"}}
|
||||
stroke={{if integration.iconFill "none" "currentColor"}}
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d={{integration.iconPath}}
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="flex-auto text-left">
|
||||
<p class="text-sm font-medium text-gray-700">
|
||||
{{integration.label}}
|
||||
</p>
|
||||
<p class="text-sm text-gray-500">
|
||||
{{integration.description}}
|
||||
</p>
|
||||
{{#if integration.single.error}}
|
||||
<p class="text-sm text-red-600">
|
||||
{{integration.single.error}}
|
||||
</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#if integration.single}}
|
||||
{{#if integration.hasSettings}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-settings
|
||||
{{on "click" (fn this.edit integration.single)}}
|
||||
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"
|
||||
>
|
||||
Settings
|
||||
</button>
|
||||
{{/if}}
|
||||
{{#if integration.single.canReconnect}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-reconnect
|
||||
{{on "click" (fn this.reconnect integration.single)}}
|
||||
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
|
||||
{{on "click" (fn this.remove integration.single)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-red-600 ring-1 ring-inset ring-red-200 hover:bg-red-50"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
{{else}}
|
||||
{{#if integration.supportsMultiple}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-add
|
||||
{{on "click" (fn this.add integration)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-indigo-600 ring-1 ring-inset ring-indigo-200 hover:bg-indigo-50"
|
||||
>
|
||||
Add another
|
||||
</button>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#unless integration.single}}
|
||||
{{#each integration.instances as |instance|}}
|
||||
<div
|
||||
data-instance={{instance.id}}
|
||||
class="mt-2 ml-13 flex items-center gap-2 rounded-xl bg-gray-50 p-3"
|
||||
>
|
||||
<div class="flex-auto text-left">
|
||||
<p class="text-sm font-medium text-gray-700">
|
||||
{{instance.label}}
|
||||
</p>
|
||||
{{#if instance.error}}
|
||||
<p class="text-sm text-red-600">{{instance.error}}</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#if integration.hasSettings}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-settings
|
||||
{{on "click" (fn this.edit instance)}}
|
||||
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"
|
||||
>
|
||||
Settings
|
||||
</button>
|
||||
{{/if}}
|
||||
{{#if instance.canReconnect}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-reconnect
|
||||
{{on "click" (fn this.reconnect instance)}}
|
||||
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
|
||||
{{on "click" (fn this.remove instance)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-red-600 ring-1 ring-inset ring-red-200 hover:bg-red-50"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
{{/each}}
|
||||
{{/unless}}
|
||||
</section>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="mt-6 rounded-xl bg-gray-50 p-6 text-center">
|
||||
<p class="text-sm text-gray-500">
|
||||
You don't have any integrations connected yet.
|
||||
</p>
|
||||
<p class="mt-1 text-sm text-gray-400">
|
||||
Use "Add Integration" to connect one.
|
||||
</p>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
+13
-23
@@ -1,10 +1,7 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { service } from '@ember/service';
|
||||
|
||||
export default class IntegrationResultDialog extends Component {
|
||||
@service integrationResult;
|
||||
import { on } from '@ember/modifier';
|
||||
|
||||
export default class IntegrationResult extends Component {
|
||||
get isSuccess() {
|
||||
return this.args.result?.success;
|
||||
}
|
||||
@@ -13,13 +10,8 @@ export default class IntegrationResultDialog extends Component {
|
||||
return this.args.result?.error;
|
||||
}
|
||||
|
||||
@action
|
||||
goBack() {
|
||||
this.integrationResult.dismiss();
|
||||
}
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="px-4 pt-5 pb-4 sm:p-6">
|
||||
<div
|
||||
class="mx-auto flex size-12 items-center justify-center rounded-full
|
||||
{{if this.isSuccess 'bg-green-100' 'bg-red-100'}}"
|
||||
@@ -59,7 +51,7 @@ export default class IntegrationResultDialog extends Component {
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="mt-3 text-center sm:mt-5">
|
||||
<h3 id="dialog-title" class="text-base font-semibold text-gray-900">
|
||||
<h3 id="modal-title" class="text-base font-semibold text-gray-900">
|
||||
{{if this.isSuccess "Integration Successful!" "Integration Failed"}}
|
||||
</h3>
|
||||
<div class="mt-2">
|
||||
@@ -73,17 +65,15 @@ export default class IntegrationResultDialog extends Component {
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5 sm:mt-6">
|
||||
<button
|
||||
type="button"
|
||||
command="close"
|
||||
commandfor="integration-result-dialog"
|
||||
onclick={{this.goBack}}
|
||||
class="inline-flex w-full justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-xs hover:bg-indigo-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>
|
||||
Go back to dashboard
|
||||
</button>
|
||||
<div class="mt-5 sm:mt-6">
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @close}}
|
||||
class="inline-flex w-full justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-xs hover:bg-indigo-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>
|
||||
Go back to dashboard
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { on } from '@ember/modifier';
|
||||
import setAttribute from '../../../modifiers/set-attribute';
|
||||
import setSelectValue from '../../../modifiers/set-select-value';
|
||||
|
||||
export default class SettingsAddIntegrationSelect extends Component {
|
||||
export default class SettingsIntegrationsSelect extends Component {
|
||||
get selectedLabel() {
|
||||
const selected = this.args.options?.find(
|
||||
(option) => String(option.value) === String(this.args.value)
|
||||
@@ -26,7 +26,7 @@ export default class SettingsAddIntegrationSelect extends Component {
|
||||
id={{@id}}
|
||||
name={{@name}}
|
||||
class="mt-2 block"
|
||||
{{setAttribute "value" @value}}
|
||||
{{setSelectValue @value}}
|
||||
{{on "change" this.handleChange}}
|
||||
>
|
||||
<button
|
||||
@@ -0,0 +1,11 @@
|
||||
import DiscourseForm from '../components/settings/integrations/discourse-form.gjs';
|
||||
import BitcoinForm from '../components/settings/integrations/bitcoin-form.gjs';
|
||||
|
||||
const FORMS = {
|
||||
discourse: DiscourseForm,
|
||||
bitcoin: BitcoinForm,
|
||||
};
|
||||
|
||||
export function formFor(type) {
|
||||
return FORMS[type] ?? null;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
const PENCIL_ICON_PATH =
|
||||
'm16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10';
|
||||
|
||||
const BITCOIN_ICON_PATH =
|
||||
'M23.638 14.904c-1.602 6.43-8.113 10.34-14.542 8.736C2.67 22.05-1.244 15.525.362 9.105 1.962 2.67 8.475-1.243 14.9.358c6.43 1.605 10.342 8.115 8.738 14.546zm-6.35-4.613c.24-1.59-.974-2.45-2.64-3.03l.54-2.153-1.315-.328-.525 2.107c-.345-.087-.705-.167-1.064-.25l.526-2.127-1.32-.33-.54 2.165c-.285-.067-.565-.132-.84-.2l-.006-.02-1.815-.45-.35 1.407s.975.225.955.238c.535.136.63.486.615.766l-.862 3.454c-.04.1-.14.25-.365.195.01.014-.95-.237-.95-.237l-.656 1.51 1.72.43c.32.08.634.16.955.25l-.54 2.2 1.32.33.54-2.18c.36.1.71.19 1.05.28l-.53 2.16 1.31.33.54-2.2c2.28.43 3.99.26 4.71-1.8.58-1.65-.03-2.6-1.22-3.22.87-.2 1.53-.78 1.7-1.96z';
|
||||
|
||||
// Metadata for every integration the app knows about. `hasSettings` controls
|
||||
// whether the Manage screen exposes an edit affordance; `reconnectable` marks
|
||||
// integrations with an auth token that can be refreshed; `supportsMultiple`
|
||||
// allows more than one connected instance.
|
||||
export const INTEGRATIONS = [
|
||||
{
|
||||
id: 'discourse',
|
||||
label: 'Discourse',
|
||||
description: 'Notifications from your discussion forums',
|
||||
colorClass: 'bg-indigo-500',
|
||||
iconPath: PENCIL_ICON_PATH,
|
||||
iconFill: false,
|
||||
available: true,
|
||||
supportsMultiple: true,
|
||||
hasSettings: false,
|
||||
reconnectable: true,
|
||||
},
|
||||
{
|
||||
id: 'bitcoin',
|
||||
label: 'Bitcoin Price Ticker',
|
||||
description: 'Live BTC price on your dashboard',
|
||||
colorClass: 'bg-orange-500',
|
||||
iconPath: BITCOIN_ICON_PATH,
|
||||
iconFill: true,
|
||||
available: true,
|
||||
supportsMultiple: false,
|
||||
hasSettings: true,
|
||||
reconnectable: false,
|
||||
},
|
||||
{
|
||||
id: 'gitea',
|
||||
label: 'Gitea',
|
||||
description: 'Notifications from your Git hosting servers',
|
||||
colorClass: 'bg-gray-300',
|
||||
iconPath: PENCIL_ICON_PATH,
|
||||
iconFill: false,
|
||||
available: false,
|
||||
supportsMultiple: false,
|
||||
hasSettings: false,
|
||||
reconnectable: false,
|
||||
},
|
||||
];
|
||||
|
||||
export function integrationFor(type) {
|
||||
return INTEGRATIONS.find((integration) => integration.id === type) ?? null;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { modifier } from 'ember-modifier';
|
||||
|
||||
// Sets an attribute (rather than a same-named DOM property). Needed for custom
|
||||
// elements like `<el-select>` whose `value` property setter runs synchronously
|
||||
// and requires its children to already be present.
|
||||
export default modifier((element, [name, value]) => {
|
||||
if (value === undefined || value === null) {
|
||||
element.removeAttribute(name);
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute(name, String(value));
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { modifier } from 'ember-modifier';
|
||||
|
||||
// `<el-select>` only observes its `required` attribute, so it reads `value`
|
||||
// once during mount. Mirroring the value onto the element's `value` property
|
||||
// after mount is what refreshes `<el-selectedcontent>` for later changes.
|
||||
export default modifier((element, [value]) => {
|
||||
if (value === undefined || value === null) {
|
||||
element.removeAttribute('value');
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute('value', String(value));
|
||||
|
||||
queueMicrotask(() => {
|
||||
if (element.isConnected && 'value' in element) {
|
||||
element.value = value;
|
||||
}
|
||||
});
|
||||
});
|
||||
+36
-3
@@ -97,16 +97,49 @@ export default class BitcoinService extends Service {
|
||||
this.provider = provider;
|
||||
this.enabled = true;
|
||||
|
||||
await this.persist({ interval, provider });
|
||||
|
||||
this.startPolling();
|
||||
}
|
||||
|
||||
async update(interval = this.interval, provider = this.provider) {
|
||||
await this.ready;
|
||||
|
||||
this.interval = interval;
|
||||
this.provider = provider;
|
||||
this.enabled = true;
|
||||
|
||||
await this.persist({ interval, provider });
|
||||
|
||||
this.startPolling();
|
||||
}
|
||||
|
||||
async persist({ interval, provider }) {
|
||||
const existing = await this.storage.get('integrations', 'bitcoin');
|
||||
|
||||
await this.storage.set('integrations', 'bitcoin', {
|
||||
...existing,
|
||||
type: 'bitcoin',
|
||||
status: 'active',
|
||||
interval,
|
||||
provider,
|
||||
currency: 'usd',
|
||||
createdAt: Date.now(),
|
||||
currency: existing?.currency ?? 'usd',
|
||||
createdAt: existing?.createdAt ?? Date.now(),
|
||||
});
|
||||
}
|
||||
|
||||
this.startPolling();
|
||||
async disable() {
|
||||
await this.ready;
|
||||
|
||||
this.stopPolling();
|
||||
this.enabled = false;
|
||||
this.interval = BITCOIN_DEFAULT_INTERVAL;
|
||||
this.provider = BITCOIN_DEFAULT_PROVIDER;
|
||||
this.price = null;
|
||||
this.changePercent = null;
|
||||
this.error = null;
|
||||
|
||||
await this.storage.remove('integrations', 'bitcoin');
|
||||
}
|
||||
|
||||
async fetchPrice() {
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import Service from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import Service, { service } from '@ember/service';
|
||||
import IntegrationResult from '../components/settings/integrations/result.gjs';
|
||||
|
||||
// Holds the outcome of the most recent integration authorization so it can be
|
||||
// shown as a modal on top of the dashboard, both after an in-place extension
|
||||
// flow and after the web redirect round-trip.
|
||||
// Shows the outcome of the most recent integration authorization as a modal,
|
||||
// both after an in-place extension flow and after the web redirect round-trip.
|
||||
export default class IntegrationResultService extends Service {
|
||||
@tracked result = null;
|
||||
@service modal;
|
||||
|
||||
show(result) {
|
||||
this.result = result;
|
||||
this.modal.open({
|
||||
component: IntegrationResult,
|
||||
props: { result },
|
||||
size: 'sm',
|
||||
});
|
||||
}
|
||||
|
||||
dismiss() {
|
||||
this.result = null;
|
||||
this.modal.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import Service, { service } from '@ember/service';
|
||||
import { INTEGRATIONS, integrationFor } from '../config/integrations';
|
||||
|
||||
// Bridges the static integration registry with the live instance state owned by
|
||||
// the `sites` (auth-based) and `bitcoin` services, so the Add/Manage screens can
|
||||
// read one uniform model instead of special-casing each integration type.
|
||||
const ADAPTERS = {
|
||||
discourse: {
|
||||
instances() {
|
||||
return this.sites.all
|
||||
.filter((site) => site.type === 'discourse')
|
||||
.map((site) => {
|
||||
const state = this.notifications.stateFor(site);
|
||||
|
||||
return {
|
||||
id: site.id,
|
||||
type: 'discourse',
|
||||
label: site.label,
|
||||
url: site.url,
|
||||
status: 'active',
|
||||
error: state.error,
|
||||
errorType: state.errorType,
|
||||
canReconnect: state.errorType === 'unauthorized',
|
||||
};
|
||||
});
|
||||
},
|
||||
remove(instance) {
|
||||
return this.sites.removeSource(instance.id);
|
||||
},
|
||||
},
|
||||
bitcoin: {
|
||||
instances() {
|
||||
if (!this.bitcoin.enabled) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
id: 'bitcoin',
|
||||
type: 'bitcoin',
|
||||
label: 'Bitcoin Price Ticker',
|
||||
status: 'active',
|
||||
interval: this.bitcoin.interval,
|
||||
provider: this.bitcoin.provider,
|
||||
},
|
||||
];
|
||||
},
|
||||
remove() {
|
||||
return this.bitcoin.disable();
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default class IntegrationsService extends Service {
|
||||
@service sites;
|
||||
@service bitcoin;
|
||||
@service notifications;
|
||||
|
||||
get all() {
|
||||
return INTEGRATIONS.map((integration) => ({
|
||||
...integration,
|
||||
instances: this.instancesFor(integration.id),
|
||||
}));
|
||||
}
|
||||
|
||||
get active() {
|
||||
return this.all.filter((integration) => integration.instances.length > 0);
|
||||
}
|
||||
|
||||
integrationFor(type) {
|
||||
return integrationFor(type);
|
||||
}
|
||||
|
||||
instancesFor(type) {
|
||||
const adapter = ADAPTERS[type];
|
||||
return adapter ? adapter.instances.call(this) : [];
|
||||
}
|
||||
|
||||
async remove(instance) {
|
||||
const adapter = ADAPTERS[instance.type];
|
||||
|
||||
if (adapter) {
|
||||
await adapter.remove.call(this, instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import Service from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
|
||||
export default class ModalService extends Service {
|
||||
@tracked current = null;
|
||||
|
||||
open(descriptor) {
|
||||
this.current = descriptor;
|
||||
}
|
||||
|
||||
replace(descriptor) {
|
||||
this.current = descriptor;
|
||||
}
|
||||
|
||||
close() {
|
||||
this.current = null;
|
||||
}
|
||||
|
||||
finished() {
|
||||
this.current = null;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { pageTitle } from 'ember-page-title';
|
||||
import IntegrationResultModal from '../components/integration-result-modal.gjs';
|
||||
import ModalHost from '../components/modal-host.gjs';
|
||||
|
||||
<template>
|
||||
{{pageTitle "Dashtab"}}
|
||||
@@ -11,5 +11,5 @@ import IntegrationResultModal from '../components/integration-result-modal.gjs';
|
||||
{{outlet}}
|
||||
</div>
|
||||
|
||||
<IntegrationResultModal />
|
||||
<ModalHost />
|
||||
</template>
|
||||
+2
-66
@@ -1,11 +1,8 @@
|
||||
import { pageTitle } from 'ember-page-title';
|
||||
import { on } from '@ember/modifier';
|
||||
import DefaultClock from '../components/default-clock.gjs';
|
||||
import BitcoinTicker from '../components/bitcoin-ticker.gjs';
|
||||
import SiteLinks from '../components/site-links.gjs';
|
||||
import ModalDialog from '../components/modal-dialog.gjs';
|
||||
import ModalStepOne from '../components/modal-step-one.gjs';
|
||||
import { default as SettingsAddIntegrationList } from '../components/settings/add-integration/list.gjs';
|
||||
import IntegrationsToolbar from '../components/integrations-toolbar.gjs';
|
||||
|
||||
<template>
|
||||
{{pageTitle "New Tab"}}
|
||||
@@ -13,19 +10,7 @@ import { default as SettingsAddIntegrationList } from '../components/settings/ad
|
||||
<div
|
||||
class="col-start-2 row-start-3 flex items-end justify-center gap-4 pb-12"
|
||||
>
|
||||
<button
|
||||
command="show-modal"
|
||||
commandfor="modal-settings-add-integration"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10"
|
||||
type="button"
|
||||
>
|
||||
Add Integration
|
||||
</button>
|
||||
|
||||
<ModalDialog
|
||||
@initialComponent={{SettingsAddIntegrationList}}
|
||||
@id="modal-settings-add-integration"
|
||||
/>
|
||||
<IntegrationsToolbar />
|
||||
</div>
|
||||
|
||||
<div class="col-start-3 row-start-1 flex items-start justify-end pt-12 pr-12">
|
||||
@@ -39,53 +24,4 @@ import { default as SettingsAddIntegrationList } from '../components/settings/ad
|
||||
<div class="col-start-2 row-start-2 flex items-center justify-center">
|
||||
<DefaultClock />
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="col-start-3 row-start-3 flex items-end justify-end gap-4 pb-12 pr-12"
|
||||
>
|
||||
<button
|
||||
command="show-modal"
|
||||
commandfor="modal-dialog-workflow"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10"
|
||||
type="button"
|
||||
>
|
||||
Open workflow dialog
|
||||
</button>
|
||||
|
||||
<button
|
||||
command="show-modal"
|
||||
commandfor="modal-dialog-yield"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10"
|
||||
type="button"
|
||||
>
|
||||
Open yielded dialog
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{{! Workflow dialog with initial component }}
|
||||
<ModalDialog @initialComponent={{ModalStepOne}} @id="modal-dialog-workflow" />
|
||||
|
||||
{{! Yielded content dialog }}
|
||||
<ModalDialog @id="modal-dialog-yield" as |modal|>
|
||||
<div class="p-6">
|
||||
<h3
|
||||
id="dialog-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Simple Dialog</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
This dialog uses yielded content. You can put any content here.
|
||||
</p>
|
||||
</div>
|
||||
<div class="mt-5 sm:mt-6">
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" modal.closeDialog}}
|
||||
class="inline-flex w-full 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 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</ModalDialog>
|
||||
</template>
|
||||
@@ -1,6 +1,6 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import { render, click } from '@ember/test-helpers';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import BitcoinTicker from 'dashtab/components/bitcoin-ticker';
|
||||
|
||||
@@ -11,6 +11,14 @@ class FakeBitcoinService {
|
||||
@tracked error = null;
|
||||
}
|
||||
|
||||
class FakeModalService {
|
||||
opened = null;
|
||||
|
||||
open(descriptor) {
|
||||
this.opened = descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
module('Integration | Component | bitcoin-ticker', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
@@ -21,6 +29,26 @@ module('Integration | Component | bitcoin-ticker', function (hooks) {
|
||||
await render(<template><BitcoinTicker /></template>);
|
||||
|
||||
assert.dom().doesNotContainText('Bitcoin');
|
||||
assert.dom('button').doesNotExist();
|
||||
});
|
||||
|
||||
test('it opens the bitcoin settings when enabled', async function (assert) {
|
||||
const bitcoin = new FakeBitcoinService();
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
const modal = new FakeModalService();
|
||||
this.owner.register('service:modal', modal, { instantiate: false });
|
||||
|
||||
bitcoin.enabled = true;
|
||||
|
||||
await render(<template><BitcoinTicker /></template>);
|
||||
|
||||
assert.dom('button').exists();
|
||||
|
||||
await click('button');
|
||||
|
||||
assert.ok(modal.opened.component);
|
||||
assert.strictEqual(modal.opened.props.mode, 'edit');
|
||||
assert.strictEqual(modal.opened.size, 'md');
|
||||
});
|
||||
|
||||
test('it renders the price and an up triangle when enabled', async function (assert) {
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import ModalDialog from 'dashtab/components/modal-dialog';
|
||||
|
||||
module('Integration | Component | modal-dialog', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
// Updating values is achieved using autotracking, just like in app code. For example:
|
||||
// class State { @tracked myProperty = 0; }; const state = new State();
|
||||
// and update using state.myProperty = 1; await rerender();
|
||||
// Handle any actions with function myAction(val) { ... };
|
||||
|
||||
await render(<template><ModalDialog /></template>);
|
||||
|
||||
assert.dom().hasText('');
|
||||
|
||||
// Template block usage:
|
||||
await render(
|
||||
<template>
|
||||
<ModalDialog>
|
||||
template block text
|
||||
</ModalDialog>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert.dom().hasText('template block text');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render, click, settled } from '@ember/test-helpers';
|
||||
import { fn, hash } from '@ember/helper';
|
||||
import { on } from '@ember/modifier';
|
||||
import ModalHost from 'dashtab/components/modal-host';
|
||||
|
||||
const BodyB = <template>
|
||||
<div data-body="b">
|
||||
<h3 id="modal-title">B</h3>
|
||||
</div>
|
||||
</template>;
|
||||
|
||||
const BodyA = <template>
|
||||
<div data-body="a">
|
||||
<h3 id="modal-title">A</h3>
|
||||
<button
|
||||
type="button"
|
||||
data-replace
|
||||
{{on "click" (fn @replace (hash component=BodyB props=(hash) size="md"))}}
|
||||
>Replace</button>
|
||||
</div>
|
||||
</template>;
|
||||
|
||||
module('Integration | Component | modal-host', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders nothing without an open modal', async function (assert) {
|
||||
await render(<template><ModalHost /></template>);
|
||||
|
||||
assert.dom('[data-body]').doesNotExist();
|
||||
assert.dom('dialog').doesNotExist();
|
||||
});
|
||||
|
||||
test('it renders the current modal at the requested size', async function (assert) {
|
||||
const modal = this.owner.lookup('service:modal');
|
||||
|
||||
await render(<template><ModalHost /></template>);
|
||||
|
||||
modal.open({ component: BodyA, props: {}, size: 'sm' });
|
||||
await settled();
|
||||
|
||||
assert.dom('[data-body="a"]').exists();
|
||||
assert.dom('el-dialog-panel').hasClass('sm:max-w-sm');
|
||||
assert.true(document.getElementById('app-modal').open);
|
||||
});
|
||||
|
||||
test('replace swaps the body while the dialog stays open', async function (assert) {
|
||||
const modal = this.owner.lookup('service:modal');
|
||||
|
||||
await render(<template><ModalHost /></template>);
|
||||
|
||||
modal.open({ component: BodyA, props: {}, size: 'md' });
|
||||
await settled();
|
||||
|
||||
await click('[data-replace]');
|
||||
|
||||
assert.dom('[data-body="a"]').doesNotExist();
|
||||
assert.dom('[data-body="b"]').exists();
|
||||
assert.true(document.getElementById('app-modal').open);
|
||||
});
|
||||
|
||||
test('finishing the modal unmounts it', async function (assert) {
|
||||
const modal = this.owner.lookup('service:modal');
|
||||
|
||||
await render(<template><ModalHost /></template>);
|
||||
|
||||
modal.open({ component: BodyA, props: {}, size: 'md' });
|
||||
await settled();
|
||||
|
||||
modal.finished();
|
||||
await settled();
|
||||
|
||||
assert.dom('[data-body]').doesNotExist();
|
||||
assert.dom('dialog').doesNotExist();
|
||||
});
|
||||
});
|
||||
@@ -1,93 +0,0 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render, triggerEvent } from '@ember/test-helpers';
|
||||
import Bitcoin from 'dashtab/components/settings/add-integration/bitcoin';
|
||||
|
||||
function changeSelect(selector, value) {
|
||||
const select = document.querySelector(selector);
|
||||
const event = new Event('change', { bubbles: true });
|
||||
Object.defineProperty(event, 'target', { value: { value } });
|
||||
select.dispatchEvent(event);
|
||||
}
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/add-integration/bitcoin',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><Bitcoin @closeDialog={{noop}} /></template>);
|
||||
|
||||
assert.dom().containsText('Add Bitcoin Price Ticker');
|
||||
assert.dom().containsText('Price source');
|
||||
assert.dom().containsText('Update interval');
|
||||
assert.dom('form').exists();
|
||||
assert.dom('el-select').exists({ count: 2 });
|
||||
assert.dom('el-option').exists({ count: 6 });
|
||||
assert.dom().containsText('CoinGecko');
|
||||
assert.dom().containsText('Binance');
|
||||
assert.dom().containsText('Bitstamp');
|
||||
assert.dom().containsText('Every 30 seconds');
|
||||
assert.dom().containsText('Every 60 seconds');
|
||||
assert.dom().containsText('Every 5 minutes');
|
||||
});
|
||||
|
||||
test('submitting enables the integration with the default interval and provider', async function (assert) {
|
||||
const calls = [];
|
||||
const bitcoin = {
|
||||
enable: async (interval, provider) =>
|
||||
calls.push({ interval, provider }),
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
let closed = false;
|
||||
const closeDialog = () => {
|
||||
closed = true;
|
||||
};
|
||||
|
||||
await render(
|
||||
<template><Bitcoin @closeDialog={{closeDialog}} /></template>
|
||||
);
|
||||
await triggerEvent('form', 'submit');
|
||||
|
||||
assert.deepEqual(calls, [{ interval: 30000, provider: 'coingecko' }]);
|
||||
assert.true(closed);
|
||||
});
|
||||
|
||||
test('submitting uses the selected interval', async function (assert) {
|
||||
const calls = [];
|
||||
const bitcoin = {
|
||||
enable: async (interval, provider) =>
|
||||
calls.push({ interval, provider }),
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
const noop = () => {};
|
||||
await render(<template><Bitcoin @closeDialog={{noop}} /></template>);
|
||||
|
||||
changeSelect('#bitcoin-interval', '60000');
|
||||
await triggerEvent('form', 'submit');
|
||||
|
||||
assert.deepEqual(calls, [{ interval: 60000, provider: 'coingecko' }]);
|
||||
});
|
||||
|
||||
test('submitting uses the selected provider', async function (assert) {
|
||||
const calls = [];
|
||||
const bitcoin = {
|
||||
enable: async (interval, provider) =>
|
||||
calls.push({ interval, provider }),
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
const noop = () => {};
|
||||
await render(<template><Bitcoin @closeDialog={{noop}} /></template>);
|
||||
|
||||
changeSelect('#bitcoin-provider', 'binance');
|
||||
await triggerEvent('form', 'submit');
|
||||
|
||||
assert.deepEqual(calls, [{ interval: 30000, provider: 'binance' }]);
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,27 +0,0 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import Discourse from 'dashtab/components/settings/add-integration/discourse';
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/add-integration/discourse',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
// Updating values is achieved using autotracking, just like in app code. For example:
|
||||
// class State { @tracked myProperty = 0; }; const state = new State();
|
||||
// and update using state.myProperty = 1; await rerender();
|
||||
// Handle any actions with function myAction(val) { ... };
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><Discourse @closeDialog={{noop}} /></template>);
|
||||
|
||||
assert.dom().containsText('Add Discourse Integration');
|
||||
assert.dom().containsText('Enter your Discourse forum URL');
|
||||
assert.dom('form').exists();
|
||||
assert.dom('#discourse-url').hasNoValue();
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,99 +0,0 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render, click } from '@ember/test-helpers';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import List from 'dashtab/components/settings/add-integration/list';
|
||||
|
||||
class FakeSitesService {
|
||||
@tracked all = [];
|
||||
removed = [];
|
||||
|
||||
async removeSource(id) {
|
||||
this.removed.push(id);
|
||||
this.all = this.all.filter((site) => site.id !== id);
|
||||
}
|
||||
}
|
||||
|
||||
class FakeNotificationsService {
|
||||
stateFor(site) {
|
||||
return { error: site.error ?? null };
|
||||
}
|
||||
}
|
||||
|
||||
function registerServices(owner, sites) {
|
||||
owner.register('service:sites', sites, { instantiate: false });
|
||||
owner.register('service:notifications', new FakeNotificationsService(), {
|
||||
instantiate: false,
|
||||
});
|
||||
}
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/add-integration/list',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders the add options', async function (assert) {
|
||||
registerServices(this.owner, new FakeSitesService());
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><List @switchComponent={{noop}} /></template>);
|
||||
|
||||
assert.dom().containsText('Discourse');
|
||||
assert.dom().containsText('Notifications from your discussion forums');
|
||||
assert.dom().containsText('Bitcoin Price Ticker');
|
||||
assert.dom().containsText('Live BTC price on your dashboard');
|
||||
assert.dom().containsText('Gitea');
|
||||
assert.dom().containsText('Notifications from your Git hosting servers');
|
||||
});
|
||||
|
||||
test('it lists connected sites with reconnect and remove', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-abc',
|
||||
type: 'discourse',
|
||||
label: 'forum.example.com',
|
||||
url: 'https://forum.example.com',
|
||||
error: null,
|
||||
},
|
||||
];
|
||||
registerServices(this.owner, sites);
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><List @switchComponent={{noop}} /></template>);
|
||||
|
||||
const row = '[data-connected="discourse-abc"]';
|
||||
assert.dom(row).exists();
|
||||
assert.dom(row).containsText('forum.example.com');
|
||||
assert.dom(`${row} [data-test-reconnect]`).exists();
|
||||
|
||||
await click(`${row} [data-test-remove]`);
|
||||
|
||||
assert.deepEqual(sites.removed, ['discourse-abc']);
|
||||
});
|
||||
|
||||
test('it shows the error for a failing site', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-bad',
|
||||
type: 'discourse',
|
||||
label: 'bad.example.com',
|
||||
url: 'https://bad.example.com',
|
||||
error: 'Access was rejected — reconnect this forum',
|
||||
},
|
||||
];
|
||||
registerServices(this.owner, sites);
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><List @switchComponent={{noop}} /></template>);
|
||||
|
||||
assert
|
||||
.dom('[data-connected="discourse-bad"]')
|
||||
.containsText('Access was rejected — reconnect this forum');
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,100 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render, click } from '@ember/test-helpers';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import List from 'dashtab/components/settings/integrations/add-list';
|
||||
|
||||
class FakeSitesService {
|
||||
@tracked all = [];
|
||||
}
|
||||
|
||||
class FakeNotificationsService {
|
||||
stateFor() {
|
||||
return { error: null, errorType: null };
|
||||
}
|
||||
}
|
||||
|
||||
class FakeBitcoinService {
|
||||
@tracked enabled = false;
|
||||
@tracked interval = 30000;
|
||||
@tracked provider = 'coingecko';
|
||||
}
|
||||
|
||||
class FakeModalService {
|
||||
replaced = null;
|
||||
|
||||
open(descriptor) {
|
||||
this.replaced = descriptor;
|
||||
}
|
||||
|
||||
replace(descriptor) {
|
||||
this.replaced = descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
function register(owner, overrides = {}) {
|
||||
owner.register('service:sites', overrides.sites ?? new FakeSitesService(), {
|
||||
instantiate: false,
|
||||
});
|
||||
owner.register(
|
||||
'service:notifications',
|
||||
overrides.notifications ?? new FakeNotificationsService(),
|
||||
{ instantiate: false }
|
||||
);
|
||||
owner.register(
|
||||
'service:bitcoin',
|
||||
overrides.bitcoin ?? new FakeBitcoinService(),
|
||||
{ instantiate: false }
|
||||
);
|
||||
|
||||
const modal = overrides.modal ?? new FakeModalService();
|
||||
owner.register('service:modal', modal, { instantiate: false });
|
||||
|
||||
return { modal };
|
||||
}
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/integrations/add-list',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders every available integration', async function (assert) {
|
||||
register(this.owner);
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom().containsText('Discourse');
|
||||
assert.dom().containsText('Notifications from your discussion forums');
|
||||
assert.dom().containsText('Bitcoin Price Ticker');
|
||||
assert.dom().containsText('Live BTC price on your dashboard');
|
||||
assert.dom().containsText('Gitea');
|
||||
assert.dom().containsText('Notifications from your Git hosting servers');
|
||||
|
||||
assert.dom('[data-add="gitea"]').isDisabled();
|
||||
});
|
||||
|
||||
test('clicking an integration opens its add form', async function (assert) {
|
||||
const { modal } = register(this.owner);
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
await click('[data-add="discourse"]');
|
||||
|
||||
assert.ok(modal.replaced.component);
|
||||
assert.strictEqual(modal.replaced.props.mode, 'add');
|
||||
assert.strictEqual(modal.replaced.size, 'md');
|
||||
});
|
||||
|
||||
test('hides an already connected single-instance integration', async function (assert) {
|
||||
const bitcoin = new FakeBitcoinService();
|
||||
bitcoin.enabled = true;
|
||||
|
||||
register(this.owner, { bitcoin });
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-add="bitcoin"]').doesNotExist();
|
||||
assert.dom('[data-add="discourse"]').exists();
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,174 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render, triggerEvent } from '@ember/test-helpers';
|
||||
import Bitcoin from 'dashtab/components/settings/integrations/bitcoin-form';
|
||||
|
||||
function changeSelect(selector, value) {
|
||||
const select = document.querySelector(selector);
|
||||
const event = new Event('change', { bubbles: true });
|
||||
Object.defineProperty(event, 'target', { value: { value } });
|
||||
select.dispatchEvent(event);
|
||||
}
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/integrations/bitcoin-form',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><Bitcoin @close={{noop}} /></template>);
|
||||
|
||||
assert.dom().containsText('Add Bitcoin Price Ticker');
|
||||
assert.dom().containsText('Price source');
|
||||
assert.dom().containsText('Update interval');
|
||||
assert.dom('form').exists();
|
||||
assert.dom('el-select').exists({ count: 2 });
|
||||
assert.dom('el-option').exists({ count: 6 });
|
||||
assert.dom().containsText('CoinGecko');
|
||||
assert.dom().containsText('Binance');
|
||||
assert.dom().containsText('Bitstamp');
|
||||
assert.dom().containsText('Every 30 seconds');
|
||||
assert.dom().containsText('Every 60 seconds');
|
||||
assert.dom().containsText('Every 5 minutes');
|
||||
});
|
||||
|
||||
test('submitting enables the integration with the default interval and provider', async function (assert) {
|
||||
const calls = [];
|
||||
const bitcoin = {
|
||||
enable: async (interval, provider) =>
|
||||
calls.push({ interval, provider }),
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
let closed = false;
|
||||
const closeDialog = () => {
|
||||
closed = true;
|
||||
};
|
||||
|
||||
await render(<template><Bitcoin @close={{closeDialog}} /></template>);
|
||||
await triggerEvent('form', 'submit');
|
||||
|
||||
assert.deepEqual(calls, [{ interval: 30000, provider: 'coingecko' }]);
|
||||
assert.true(closed);
|
||||
});
|
||||
|
||||
test('submitting uses the selected interval', async function (assert) {
|
||||
const calls = [];
|
||||
const bitcoin = {
|
||||
enable: async (interval, provider) =>
|
||||
calls.push({ interval, provider }),
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
const noop = () => {};
|
||||
await render(<template><Bitcoin @close={{noop}} /></template>);
|
||||
|
||||
changeSelect('#bitcoin-interval', '60000');
|
||||
await triggerEvent('form', 'submit');
|
||||
|
||||
assert.deepEqual(calls, [{ interval: 60000, provider: 'coingecko' }]);
|
||||
});
|
||||
|
||||
test('submitting uses the selected provider', async function (assert) {
|
||||
const calls = [];
|
||||
const bitcoin = {
|
||||
enable: async (interval, provider) =>
|
||||
calls.push({ interval, provider }),
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
const noop = () => {};
|
||||
await render(<template><Bitcoin @close={{noop}} /></template>);
|
||||
|
||||
changeSelect('#bitcoin-provider', 'binance');
|
||||
await triggerEvent('form', 'submit');
|
||||
|
||||
assert.deepEqual(calls, [{ interval: 30000, provider: 'binance' }]);
|
||||
});
|
||||
|
||||
test('edit mode prefills the stored settings and saves with update', async function (assert) {
|
||||
const calls = [];
|
||||
const bitcoin = {
|
||||
interval: 30000,
|
||||
provider: 'coingecko',
|
||||
enable: async () => assert.ok(false, 'enable should not be called'),
|
||||
update: async (interval, provider) =>
|
||||
calls.push({ interval, provider }),
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
this.props = {
|
||||
mode: 'edit',
|
||||
integration: { interval: 60000, provider: 'binance' },
|
||||
};
|
||||
|
||||
let closed = false;
|
||||
const closeDialog = () => {
|
||||
closed = true;
|
||||
};
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<Bitcoin @props={{this.props}} @close={{closeDialog}} />
|
||||
</template>
|
||||
);
|
||||
|
||||
assert.dom().containsText('Edit Bitcoin Price Ticker');
|
||||
assert.dom().containsText('Save');
|
||||
assert.dom('#bitcoin-provider').containsText('Binance');
|
||||
assert.dom('#bitcoin-interval').containsText('Every 60 seconds');
|
||||
|
||||
changeSelect('#bitcoin-interval', '300000');
|
||||
await triggerEvent('form', 'submit');
|
||||
|
||||
assert.deepEqual(calls, [{ interval: 300000, provider: 'binance' }]);
|
||||
assert.true(closed);
|
||||
});
|
||||
|
||||
test('it reflects the live service settings when no integration is provided', async function (assert) {
|
||||
const bitcoin = {
|
||||
interval: 60000,
|
||||
provider: 'binance',
|
||||
enable: async () => {},
|
||||
update: async () => {},
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><Bitcoin @close={{noop}} /></template>);
|
||||
|
||||
assert.dom('#bitcoin-provider').containsText('Binance');
|
||||
assert.dom('#bitcoin-interval').containsText('Every 60 seconds');
|
||||
});
|
||||
|
||||
test('it clears unsaved edits when the enclosing dialog closes', async function (assert) {
|
||||
const bitcoin = {
|
||||
interval: 30000,
|
||||
provider: 'coingecko',
|
||||
enable: async () => {},
|
||||
update: async () => {},
|
||||
};
|
||||
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<dialog>
|
||||
<Bitcoin @close={{noop}} />
|
||||
</dialog>
|
||||
</template>
|
||||
);
|
||||
|
||||
changeSelect('#bitcoin-provider', 'binance');
|
||||
assert.dom('#bitcoin-provider').containsText('Binance');
|
||||
|
||||
await triggerEvent('dialog', 'close');
|
||||
|
||||
assert.dom('#bitcoin-provider').containsText('CoinGecko');
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,22 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import Discourse from 'dashtab/components/settings/integrations/discourse-form';
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/integrations/discourse-form',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><Discourse @close={{noop}} /></template>);
|
||||
|
||||
assert.dom().containsText('Add Discourse Integration');
|
||||
assert.dom().containsText('Enter your Discourse forum URL');
|
||||
assert.dom('form').exists();
|
||||
assert.dom('#discourse-url').hasNoValue();
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,289 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render, click } from '@ember/test-helpers';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import List from 'dashtab/components/settings/integrations/manage-list';
|
||||
|
||||
class FakeSitesService {
|
||||
@tracked all = [];
|
||||
removed = [];
|
||||
reloaded = 0;
|
||||
|
||||
async removeSource(id) {
|
||||
this.removed.push(id);
|
||||
this.all = this.all.filter((site) => site.id !== id);
|
||||
}
|
||||
|
||||
async reload() {
|
||||
this.reloaded++;
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
disabled = false;
|
||||
|
||||
async disable() {
|
||||
this.disabled = true;
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
replaced = null;
|
||||
|
||||
open(descriptor) {
|
||||
this.replaced = descriptor;
|
||||
}
|
||||
|
||||
replace(descriptor) {
|
||||
this.replaced = descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
function register(owner, overrides = {}) {
|
||||
const sites = overrides.sites ?? new FakeSitesService();
|
||||
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 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:authorization', authorization, {
|
||||
instantiate: false,
|
||||
});
|
||||
owner.register('service:integrationResult', integrationResult, {
|
||||
instantiate: false,
|
||||
});
|
||||
owner.register('service:modal', modal, { instantiate: false });
|
||||
|
||||
return {
|
||||
sites,
|
||||
notifications,
|
||||
bitcoin,
|
||||
authorization,
|
||||
integrationResult,
|
||||
modal,
|
||||
};
|
||||
}
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/integrations/manage-list',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it shows an empty state when nothing is active', async function (assert) {
|
||||
register(this.owner);
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-integration]').doesNotExist();
|
||||
assert
|
||||
.dom()
|
||||
.containsText("You don't have any integrations connected yet");
|
||||
});
|
||||
|
||||
test('it only lists active integrations', 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-integration="discourse"]').exists();
|
||||
assert.dom('[data-integration="bitcoin"]').exists();
|
||||
assert.dom('[data-integration="gitea"]').doesNotExist();
|
||||
});
|
||||
|
||||
test('it only offers reconnect when auth is broken', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-ok',
|
||||
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',
|
||||
},
|
||||
];
|
||||
|
||||
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 = [
|
||||
{
|
||||
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, integrationResult } = register(this.owner, {
|
||||
sites,
|
||||
notifications,
|
||||
});
|
||||
|
||||
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.strictEqual(integrationResult.shown.length, 1);
|
||||
});
|
||||
|
||||
test('removing a discourse instance 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><List /></template>);
|
||||
await click('[data-instance="discourse-abc"] [data-test-remove]');
|
||||
|
||||
assert.deepEqual(sites.removed, ['discourse-abc']);
|
||||
});
|
||||
|
||||
test('a multi-instance integration keeps its grouping', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-abc',
|
||||
type: 'discourse',
|
||||
label: 'forum.example.com',
|
||||
url: 'https://forum.example.com',
|
||||
},
|
||||
];
|
||||
|
||||
const { modal } = register(this.owner, { sites });
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-instance="discourse-abc"]').exists();
|
||||
assert
|
||||
.dom('[data-integration="discourse"] [data-test-add]')
|
||||
.containsText('Add another');
|
||||
|
||||
await click('[data-integration="discourse"] [data-test-add]');
|
||||
|
||||
assert.strictEqual(modal.replaced.props.mode, 'add');
|
||||
});
|
||||
|
||||
test('a single-instance integration is not grouped', 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"]').doesNotExist();
|
||||
assert.dom('[data-integration="bitcoin"] [data-test-settings]').exists();
|
||||
assert
|
||||
.dom('[data-integration="bitcoin"] [data-test-reconnect]')
|
||||
.doesNotExist();
|
||||
assert.dom('[data-integration="bitcoin"] [data-test-add]').doesNotExist();
|
||||
|
||||
await click('[data-integration="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');
|
||||
|
||||
await click('[data-integration="bitcoin"] [data-test-remove]');
|
||||
|
||||
assert.true(bitcoin.disabled);
|
||||
});
|
||||
}
|
||||
);
|
||||
+31
-3
@@ -1,10 +1,10 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import Select from 'dashtab/components/settings/add-integration/select';
|
||||
import { render, settled } from '@ember/test-helpers';
|
||||
import Select from 'dashtab/components/settings/integrations/select';
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/add-integration/select',
|
||||
'Integration | Component | settings/integrations/select',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
@@ -33,6 +33,34 @@ module(
|
||||
assert.dom('el-selectedcontent').hasText('Option B');
|
||||
});
|
||||
|
||||
test('it updates the selected label when the bound value changes', async function (assert) {
|
||||
this.set('options', [
|
||||
{ value: 'a', label: 'Option A' },
|
||||
{ value: 'b', label: 'Option B' },
|
||||
]);
|
||||
this.set('noop', () => {});
|
||||
this.set('value', 'a');
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<Select
|
||||
@id="test-select"
|
||||
@label="Pick one"
|
||||
@options={{this.options}}
|
||||
@value={{this.value}}
|
||||
@onChange={{this.noop}}
|
||||
/>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert.dom('el-selectedcontent').hasText('Option A');
|
||||
|
||||
this.set('value', 'b');
|
||||
await settled();
|
||||
|
||||
assert.dom('el-selectedcontent').hasText('Option B');
|
||||
});
|
||||
|
||||
test('it calls onChange with the chosen value', async function (assert) {
|
||||
this.set('options', [
|
||||
{ value: 'a', label: 'Option A' },
|
||||
@@ -259,4 +259,61 @@ module('Unit | Service | bitcoin', function (hooks) {
|
||||
service.stopPolling();
|
||||
assert.strictEqual(service.intervalId, null);
|
||||
});
|
||||
|
||||
test('update changes the stored settings and restarts polling', async function (assert) {
|
||||
const service = this.owner.lookup('service:bitcoin');
|
||||
service.fetchPrice = async () => {};
|
||||
await service.enable(30000, 'coingecko');
|
||||
|
||||
const storage = this.owner.lookup('service:storage');
|
||||
const before = await storage.get('integrations', 'bitcoin');
|
||||
|
||||
await service.update(60000, 'binance');
|
||||
|
||||
const after = await storage.get('integrations', 'bitcoin');
|
||||
|
||||
assert.strictEqual(after.status, 'active');
|
||||
assert.strictEqual(after.interval, 60000);
|
||||
assert.strictEqual(after.provider, 'binance');
|
||||
assert.strictEqual(after.createdAt, before.createdAt);
|
||||
assert.strictEqual(service.interval, 60000);
|
||||
assert.strictEqual(service.provider, 'binance');
|
||||
assert.ok(service.intervalId);
|
||||
|
||||
service.stopPolling();
|
||||
});
|
||||
|
||||
test('update defaults to the current settings', async function (assert) {
|
||||
const service = this.owner.lookup('service:bitcoin');
|
||||
service.fetchPrice = async () => {};
|
||||
await service.enable(60000, 'binance');
|
||||
|
||||
await service.update();
|
||||
|
||||
assert.strictEqual(service.interval, 60000);
|
||||
assert.strictEqual(service.provider, 'binance');
|
||||
|
||||
service.stopPolling();
|
||||
});
|
||||
|
||||
test('disable clears storage and resets state', async function (assert) {
|
||||
const service = this.owner.lookup('service:bitcoin');
|
||||
service.fetchPrice = async () => {};
|
||||
await service.enable(60000, 'binance');
|
||||
service.price = 123;
|
||||
service.error = 'nope';
|
||||
|
||||
await service.disable();
|
||||
|
||||
const storage = this.owner.lookup('service:storage');
|
||||
const integration = await storage.get('integrations', 'bitcoin');
|
||||
|
||||
assert.strictEqual(integration, null);
|
||||
assert.false(service.enabled);
|
||||
assert.strictEqual(service.intervalId, null);
|
||||
assert.strictEqual(service.interval, 30000);
|
||||
assert.strictEqual(service.provider, 'coingecko');
|
||||
assert.strictEqual(service.price, null);
|
||||
assert.strictEqual(service.error, null);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'dashtab/tests/helpers';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
|
||||
class FakeSitesService {
|
||||
@tracked all = [];
|
||||
removed = [];
|
||||
|
||||
async removeSource(id) {
|
||||
this.removed.push(id);
|
||||
this.all = this.all.filter((site) => site.id !== id);
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
disabled = false;
|
||||
|
||||
async disable() {
|
||||
this.disabled = true;
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function register(owner, overrides = {}) {
|
||||
const sites = overrides.sites ?? new FakeSitesService();
|
||||
const notifications =
|
||||
overrides.notifications ?? new FakeNotificationsService();
|
||||
const bitcoin = overrides.bitcoin ?? new FakeBitcoinService();
|
||||
|
||||
owner.register('service:sites', sites, { instantiate: false });
|
||||
owner.register('service:notifications', notifications, {
|
||||
instantiate: false,
|
||||
});
|
||||
owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
||||
|
||||
return { sites, notifications, bitcoin };
|
||||
}
|
||||
|
||||
module('Unit | Service | integrations', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it merges registry capabilities with live instances', 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;
|
||||
bitcoin.interval = 60000;
|
||||
bitcoin.provider = 'binance';
|
||||
|
||||
register(this.owner, { sites, bitcoin });
|
||||
|
||||
const service = this.owner.lookup('service:integrations');
|
||||
const discourse = service.all.find((entry) => entry.id === 'discourse');
|
||||
const bitcoinEntry = service.all.find((entry) => entry.id === 'bitcoin');
|
||||
const gitea = service.all.find((entry) => entry.id === 'gitea');
|
||||
|
||||
assert.true(discourse.supportsMultiple);
|
||||
assert.false(discourse.hasSettings);
|
||||
assert.true(discourse.reconnectable);
|
||||
assert.strictEqual(discourse.instances.length, 1);
|
||||
assert.strictEqual(discourse.instances[0].id, 'discourse-abc');
|
||||
|
||||
assert.true(bitcoinEntry.hasSettings);
|
||||
assert.strictEqual(bitcoinEntry.instances.length, 1);
|
||||
assert.strictEqual(bitcoinEntry.instances[0].interval, 60000);
|
||||
assert.strictEqual(bitcoinEntry.instances[0].provider, 'binance');
|
||||
|
||||
assert.false(gitea.available);
|
||||
assert.strictEqual(gitea.instances.length, 0);
|
||||
});
|
||||
|
||||
test('active only includes integrations with instances', function (assert) {
|
||||
register(this.owner);
|
||||
|
||||
const service = this.owner.lookup('service:integrations');
|
||||
|
||||
assert.deepEqual(service.active, []);
|
||||
});
|
||||
|
||||
test('remove delegates to each integration adapter', 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;
|
||||
|
||||
const { sites: registeredSites } = register(this.owner, {
|
||||
sites,
|
||||
bitcoin,
|
||||
});
|
||||
|
||||
const service = this.owner.lookup('service:integrations');
|
||||
|
||||
await service.remove({ type: 'discourse', id: 'discourse-abc' });
|
||||
assert.deepEqual(registeredSites.removed, ['discourse-abc']);
|
||||
|
||||
await service.remove({ type: 'bitcoin', id: 'bitcoin' });
|
||||
assert.true(bitcoin.disabled);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'dashtab/tests/helpers';
|
||||
|
||||
module('Unit | Service | modal', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it tracks the open modal through open, replace and close', function (assert) {
|
||||
const service = this.owner.lookup('service:modal');
|
||||
|
||||
assert.strictEqual(service.current, null);
|
||||
|
||||
const first = { component: 'first' };
|
||||
service.open(first);
|
||||
assert.strictEqual(service.current, first);
|
||||
|
||||
const second = { component: 'second' };
|
||||
service.replace(second);
|
||||
assert.strictEqual(service.current, second);
|
||||
|
||||
service.finished();
|
||||
assert.strictEqual(service.current, null);
|
||||
|
||||
service.open(first);
|
||||
service.close();
|
||||
assert.strictEqual(service.current, null);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user