Add Tailwind Elements, modal component
Adds Tailwind UI/Pro Elements (WebComponents), as well as a flexible modal dialog component where we can swap out child components within the dialog
This commit is contained in:
1 parent
f4b07f497a
commit
0a3164cf84
11 files changed
+362
-8
No files matched your search
@@ -5,6 +5,7 @@ import loadInitializers from 'ember-load-initializers';
|
||||
import config from 'dashtab/config/environment';
|
||||
import { importSync, isDevelopingApp, macroCondition } from '@embroider/macros';
|
||||
import setupInspector from '@embroider/legacy-inspector-support/ember-source-4.12';
|
||||
import '@tailwindplus/elements';
|
||||
import './styles/app.css';
|
||||
|
||||
if (macroCondition(isDevelopingApp())) {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { hash } from '@ember/helper';
|
||||
|
||||
export default class ModalDialogComponent extends Component {
|
||||
@tracked currentComponent = this.args.initialComponent;
|
||||
@tracked componentProps = this.args.initialProps || {};
|
||||
|
||||
@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">
|
||||
<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 px-4 pt-5 pb-4 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 sm:max-w-sm sm:p-6 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,33 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { on } from '@ember/modifier';
|
||||
import { fn } from '@ember/helper';
|
||||
import ModalStepTwo from './modal-step-two.gjs';
|
||||
|
||||
export default class ModalStepOneComponent extends Component {
|
||||
<template>
|
||||
<div>
|
||||
<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>
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { on } from '@ember/modifier';
|
||||
import { fn } from '@ember/helper';
|
||||
import ModalStepOne from './modal-step-one.gjs';
|
||||
|
||||
export default class ModalStepTwoComponent extends Component {
|
||||
<template>
|
||||
<div>
|
||||
<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>
|
||||
}
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
@import 'tailwindcss';
|
||||
|
||||
/* Ember supports plain CSS out of the box. More info: https://cli.emberjs.com/release/advanced-use/stylesheets/ */
|
||||
/* @theme { */
|
||||
/* --font-sans: Helvetica, "Liberation Sans", "Nimbus Sans", sans-serif; */
|
||||
/* } */
|
||||
+49
-6
@@ -1,10 +1,53 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { pageTitle } from 'ember-page-title';
|
||||
import { on } from '@ember/modifier';
|
||||
import DefaultClock from '../components/default-clock.gjs';
|
||||
import ModalDialog from '../components/modal-dialog.gjs';
|
||||
import ModalStepOne from '../components/modal-step-one.gjs';
|
||||
|
||||
<template>
|
||||
{{pageTitle "New Tab"}}
|
||||
export default class IndexRoute extends Component {
|
||||
<template>
|
||||
{{pageTitle "New Tab"}}
|
||||
|
||||
<div class="col-start-2 row-start-2 flex items-center justify-center">
|
||||
<DefaultClock />
|
||||
</div>
|
||||
</template>
|
||||
<div class="col-start-2 row-start-2 flex items-center justify-center">
|
||||
<DefaultClock />
|
||||
</div>
|
||||
|
||||
<div class="col-start-2 row-start-3 flex items-center justify-center gap-4">
|
||||
<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">
|
||||
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">
|
||||
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>
|
||||
<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>
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
Discourse contains a system for generating API keys **per user** if a very
|
||||
specific protocol is followed. This feature facilitates "application" access to
|
||||
Discourse instances without needing to involve moderators.
|
||||
|
||||
### High level description
|
||||
|
||||
At a high level:
|
||||
|
||||
1. Client (desktop app, browser plugin, mobile app) generates a private/public
|
||||
key pair and return url
|
||||
|
||||
2. Client redirects to a route on discourse giving discourse its public key
|
||||
|
||||
3. Discourse gets approval from user to use app
|
||||
|
||||
4. Discourse generates a user api key
|
||||
|
||||
5. Discourse redirects back to return url with an encrypted payload using
|
||||
public api key containing the user api key
|
||||
|
||||
### Details
|
||||
|
||||
Use cases:
|
||||
|
||||
1. Desktop applications that poll Discourse sites on behalf of end users to get
|
||||
notification counts across multiple sites.
|
||||
|
||||
2. Mobile applications that poll Discourse sites on behalf of end users and
|
||||
handles push notifications
|
||||
|
||||
3. Web applications that provide a dashboard for end users about various
|
||||
Discourse sites.
|
||||
|
||||
4. Custom integrations with 3rd party apps that consume Discourse as part of
|
||||
a general company app. Eg: integrate Discourse community notifications into
|
||||
hopscotch app.
|
||||
|
||||
The design:
|
||||
|
||||
### Site Settings
|
||||
|
||||
- **allow_user_api_key_scopes**: allowed access scopes for user api keys.
|
||||
- Defined
|
||||
- [here](https://github.com/discourse/discourse/blob/master/app/models/user_api_key.rb)
|
||||
- **min_trust_level_for_user_api_key**: 0 (require this trust level for api key
|
||||
- access)
|
||||
|
||||
- **allowed_user_api_push_urls**: list of sites that can be targets for push
|
||||
- notifications **allowed_user_api_auth_redirects**: allowed redirect
|
||||
- destinations after user api key generation
|
||||
|
||||
### Global Settings
|
||||
|
||||
- **max_user_api_reqs_per_minute**: 20 **max_user_api_reqs_per_day**: 2880
|
||||
|
||||
### UX elements
|
||||
|
||||
If any user api keys have been granted, Discourse displays an **apps** tab in
|
||||
the user page.
|
||||
|
||||
The **apps** tab will list:
|
||||
|
||||
- The name of the application eg: ("Discourse Notifier") Last use date Approved
|
||||
- date List of access scopes granted A **revoke access** button so you can
|
||||
- easily revoke any keys
|
||||
|
||||
#### API Key authorization UI
|
||||
|
||||
Every key will have to be explicitly authorized by end users in a page that
|
||||
clearly explains what is going on, for example:
|
||||
|
||||
> "Discourse Notifier" is requesting the following access to your account:
|
||||
> - Read and clear notifications
|
||||
> - Read user session info
|
||||
> - Create a one-time login token
|
||||
>
|
||||
> [Authorize]
|
||||
|
||||
### API key generation flow
|
||||
|
||||
API only requires a single GET request on the user's end.
|
||||
|
||||
``` https://sitename.com/user-api-key/new ```
|
||||
|
||||
> :exclamation: As of Discourse 2.1 these user api keys now auto-expire if left
|
||||
> unused for long periods of time. The site setting: `revoke user api keys
|
||||
> unused days` is set to 180 out of the box
|
||||
|
||||
Params:
|
||||
|
||||
* **auth_redirect**: url to redirect back to with the generated token
|
||||
* **application_name**: the name of the application making the request (will be
|
||||
* displayed in the user account's Apps tab) **client_id**: a unique identifier
|
||||
* for the client **scopes**: comma-separated list of access scopes allowed for
|
||||
* the key, see `allow user api key scopes` for the full list of available
|
||||
* scopes **push_url**: url to push notifications to (required and valid only if
|
||||
* `push` or `notifications` are included in the scopes) **public_key**: the
|
||||
* public part of the keypair generated by the client
|
||||
|
||||
After `/user-api-key/new` is called with correct params 2 things may happen
|
||||
|
||||
1. If user is not logged on, we will redirect to login (after login we will
|
||||
resume authorization)
|
||||
2. Once a user is logged on they will be presented with the authorization
|
||||
UI
|
||||
|
||||
After authorization is allowed, system will redirect back to the URL
|
||||
defined in `auth_redirect` and include a single encrypted `payload`
|
||||
parameter containing the generated user API key and, if requested, a
|
||||
one-time login token. `client_id` is not echoed back for extra security.
|
||||
|
||||
### Checking API version
|
||||
|
||||
The use key API in Discourse is versioned. Clients can check a Discourse site's
|
||||
API version by making a HEAD request to
|
||||
`https://sitename.com/user-api-key/new`. The response will contain a header
|
||||
named Auth-Api-Version containing the version number of the site's API.
|
||||
|
||||
### Consuming the API
|
||||
|
||||
Consuming the client API will be somewhat different that the current admin API.
|
||||
|
||||
Client can specify 2 headers:
|
||||
|
||||
`User-Api-Key` (required): the key that was generated
|
||||
|
||||
and
|
||||
|
||||
`User-Api-Client-Id` (optional): supply this to update the 'client id' stored
|
||||
for this api_key in the database.
|
||||
|
||||
Once those headers are specified client can perform requests against the API
|
||||
just as they would normally.
|
||||
|
||||
### Generating a one-time-login password
|
||||
|
||||
As of version 4, the API includes a special scope: the `one_time_password`
|
||||
scope, which allows clients to use the user API key to generate a
|
||||
one-time-password. If the client includes this scope when generating the API
|
||||
key following the steps above, a `one_time_password` will be included in the
|
||||
encrypted `payload`.
|
||||
|
||||
Alternately, the client can make a GET request to `/user-api-key/otp` with the
|
||||
following parameters:
|
||||
|
||||
- auth_redirect application_name public_key
|
||||
|
||||
and with the `User-Api-Key` header.
|
||||
|
||||
This request will redirect to a screen in Discourse that will ask the user
|
||||
to allow the application access to the site. If the user approves, the site
|
||||
will redirect back to the URL defined in `auth_redirect` and include an
|
||||
encrypted `payload` with a one-time password which the client can use to
|
||||
login to the site by requesting
|
||||
`https://sitename.com/session/otp/ONE-TIME-PASSWORD`. (The
|
||||
one-time-password is only valid for 10 minutes.)
|
||||
|
||||
### Revoking API keys
|
||||
|
||||
To revoke an API key, make a POST request with the `User-Api-Key` header and no
|
||||
params to `/user-api-key/revoke`.
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
|
||||
{{content-for "head-footer"}}
|
||||
</head>
|
||||
<body>
|
||||
<body class="font-sans">
|
||||
{{content-for "body"}}
|
||||
|
||||
<script src="/@embroider/virtual/vendor.js"></script>
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"@glimmer/component": "^2.0.0",
|
||||
"@rollup/plugin-babel": "^6.0.4",
|
||||
"@tailwindcss/vite": "^4.1.16",
|
||||
"@tailwindplus/elements": "^1.0.18",
|
||||
"@warp-drive/ember": "~5.6.0",
|
||||
"babel-plugin-ember-template-compilation": "^2.4.1",
|
||||
"concurrently": "^9.2.1",
|
||||
|
||||
Generated
+8
@@ -65,6 +65,9 @@ importers:
|
||||
'@tailwindcss/vite':
|
||||
specifier: ^4.1.16
|
||||
version: 4.1.16(vite@7.1.12(@types/node@24.9.2)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.44.0))
|
||||
'@tailwindplus/elements':
|
||||
specifier: ^1.0.18
|
||||
version: 1.0.18
|
||||
'@warp-drive/ember':
|
||||
specifier: ~5.6.0
|
||||
version: 5.6.0(@ember/test-waiters@4.1.1)
|
||||
@@ -1522,6 +1525,9 @@ packages:
|
||||
peerDependencies:
|
||||
vite: ^5.2.0 || ^6 || ^7
|
||||
|
||||
'@tailwindplus/elements@1.0.18':
|
||||
resolution: {integrity: sha512-JvqwL+6LwDIxC5zV9kAcI1wttpkUhgkGr7bcuYGH7fxnmgvVJglBERqlgPGGDXWB+lpuFgjgkvtK3pMm/7MvTA==}
|
||||
|
||||
'@types/babel__code-frame@7.0.6':
|
||||
resolution: {integrity: sha512-Anitqkl3+KrzcW2k77lRlg/GfLZLWXBuNgbEcIOU6M92yw42vsd3xV/Z/yAHEj8m+KUjL6bWOVOFqX8PFPJ4LA==}
|
||||
|
||||
@@ -7887,6 +7893,8 @@ snapshots:
|
||||
tailwindcss: 4.1.16
|
||||
vite: 7.1.12(@types/node@24.9.2)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.44.0)
|
||||
|
||||
'@tailwindplus/elements@1.0.18': {}
|
||||
|
||||
'@types/babel__code-frame@7.0.6': {}
|
||||
|
||||
'@types/body-parser@1.19.6':
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user