Skip to content

Modular logistics and supply chain operating system (LSOS)

fix(oauth): keep the provider buttons in the console until ember-ui 0.4.3

Ronald A. Richardson5f82811a1c35
diff --git a/console/app/components/account/connected-accounts.hbs b/console/app/components/account/connected-accounts.hbs
index e9d8455a..9d00cfa1 100644
--- a/console/app/components/account/connected-accounts.hbs
+++ b/console/app/components/account/connected-accounts.hbs
@@ -9,7 +9,7 @@
<div class="flex items-center justify-between rounded-md border border-gray-200 dark:border-gray-700 px-3 py-2">
<div class="flex items-center">
<span class="mr-3 inline-flex text-gray-700 dark:text-gray-200">
- <OauthProviderLogo @provider={{identity.provider}} @icon={{identity.icon}} />
+ <Auth::OauthProviderLogo @provider={{identity.provider}} @icon={{identity.icon}} />
</span>
<div>
<div class="text-sm font-semibold text-gray-900 dark:text-white">{{identity.label}}</div>
@@ -42,7 +42,7 @@
<div class="flex items-center justify-between rounded-md border border-dashed border-gray-300 dark:border-gray-700 px-3 py-2">
<div class="flex items-center">
<span class="mr-3 inline-flex text-gray-700 dark:text-gray-200">
- <OauthProviderLogo @provider={{provider.id}} @icon={{provider.icon}} />
+ <Auth::OauthProviderLogo @provider={{provider.id}} @icon={{provider.icon}} />
</span>
<div class="text-sm text-gray-700 dark:text-gray-300">{{provider.label}}</div>
</div>
diff --git a/console/app/components/auth/oauth-provider-button.hbs b/console/app/components/auth/oauth-provider-button.hbs
new file mode 100644
index 00000000..13a4f600
--- /dev/null
+++ b/console/app/components/auth/oauth-provider-button.hbs
@@ -0,0 +1,24 @@
+{{!-- The console's "Continue with <provider>" button, for the login and sign-up pages.
+
+ Same arguments as ember-ui's <OauthProviderButton> (fleetbase/ember-ui#182, v0.4.3),
+ which the Fleetbase Cloud sign-up step uses. Kept here until the console depends on
+ ember-ui 0.4.3; then this file, auth/oauth-provider-logo and the .oauth-provider-*
+ CSS in console.css go, and callers drop the `Auth::` prefix.
+
+ @provider { id, label, icon } as the API's provider list returns it
+ @text the button text; defaults to the provider's label
+ @disabled
+ @onClick called with the provider --}}
+<Button
+ @wrapperClass="btn-block oauth-provider-button oauth-provider-{{@provider.id}}"
+ @disabled={{@disabled}}
+ @onClick={{fn this.onClick @provider}}
+ data-test-oauth-provider={{@provider.id}}
+ ...attributes
+>
+ {{!-- In Fleetbase's icon slot, so the logo sits at the far left like other buttons. --}}
+ <span class="btn-icon-wrapper">
+ <Auth::OauthProviderLogo @provider={{@provider.id}} @icon={{@provider.icon}} />
+ </span>
+ <span>{{or @text @provider.label}}</span>
+</Button>
diff --git a/console/app/components/auth/oauth-provider-button.js b/console/app/components/auth/oauth-provider-button.js
new file mode 100644
index 00000000..22667330
--- /dev/null
+++ b/console/app/components/auth/oauth-provider-button.js
@@ -0,0 +1,10 @@
+import Component from '@glimmer/component';
+import { action } from '@ember/object';
+
+export default class AuthOauthProviderButtonComponent extends Component {
+ @action onClick(provider) {
+ if (typeof this.args.onClick === 'function') {
+ this.args.onClick(provider);
+ }
+ }
+}
diff --git a/console/app/components/auth/oauth-provider-logo.hbs b/console/app/components/auth/oauth-provider-logo.hbs
new file mode 100644
index 00000000..63ff8bfb
--- /dev/null
+++ b/console/app/components/auth/oauth-provider-logo.hbs
@@ -0,0 +1,27 @@
+{{!-- A provider's own logo, as its brand guidelines require it to be shown.
+ Google and Microsoft must be full colour (a single-colour Google "G" is not
+ allowed), so they are inline SVG. Apple and GitHub are single colour by design
+ and follow the button's text colour. Any other provider falls back to its icon. --}}
+{{#if (eq @provider "google")}}
+ <span class="oauth-provider-logo oauth-provider-logo-google" aria-hidden="true">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="18" height="18">
+ <path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z" />
+ <path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z" />
+ <path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z" />
+ <path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z" />
+ </svg>
+ </span>
+{{else if (eq @provider "microsoft")}}
+ <span class="oauth-provider-logo oauth-provider-logo-microsoft" aria-hidden="true">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 21" width="18" height="18">
+ <rect x="1" y="1" width="9" height="9" fill="#F25022" />
+ <rect x="11" y="1" width="9" height="9" fill="#7FBA00" />
+ <rect x="1" y="11" width="9" height="9" fill="#00A4EF" />
+ <rect x="11" y="11" width="9" height="9" fill="#FFB900" />
+ </svg>
+ </span>
+{{else if @icon}}
+ <span class="oauth-provider-logo oauth-provider-logo-{{@provider}}" aria-hidden="true">
+ <FaIcon @icon={{@icon}} @prefix="fab" />
+ </span>
+{{/if}}
diff --git a/console/app/components/onboarding/form.hbs b/console/app/components/onboarding/form.hbs
index 67fbe256..8b799286 100644
--- a/console/app/components/onboarding/form.hbs
+++ b/console/app/components/onboarding/form.hbs
@@ -26,7 +26,7 @@
{{#if (and this.oauth.canSignUp (not this.hasOauthIntent))}}
<div class="space-y-2" data-test-oauth-signup>
{{#each this.oauth.providers as |provider|}}
- <OauthProviderButton
+ <Auth::OauthProviderButton
@provider={{provider}}
@text={{t "auth.login.oauth.continue-with" provider=provider.label}}
@disabled={{this.isStartingProvider}}
diff --git a/console/app/styles/console.css b/console/app/styles/console.css
index 8b6c0672..cd20ceda 100644
--- a/console/app/styles/console.css
+++ b/console/app/styles/console.css
@@ -243,3 +243,93 @@ body[data-theme='dark'] .console-dashboard-title h1 {
padding: 1rem;
}
}
+
+
+/*
+ * Sign-in provider buttons: each provider's logo and light-mode colours on Fleetbase's
+ * own button shape, size, shadow and icon position.
+ *
+ * Light Google and Microsoft: white with Fleetbase's usual button border, the
+ * full-colour logo (Google forbids a single-colour "G"; Microsoft forbids
+ * altering its logo). Apple: black (Apple HIG). GitHub: #24292F — its mark
+ * is only ever shown in black or white.
+ * Dark Every provider on Fleetbase's gray-900, so the page reads as one set of
+ * buttons. Apple and GitHub marks turn white with the text; the Google "G"
+ * keeps a white disc, since Google requires it on white.
+ *
+ * Only these providers are listed, so one added later keeps the default button.
+ * `body` in each selector outranks ember-ui's `body[data-theme='dark'] .btn.btn-default`
+ * rules, hover included.
+ */
+.oauth-provider-google,
+.oauth-provider-microsoft {
+ --oauth-bg: #ffffff;
+ --oauth-bg-hover: #f3f4f6; /* gray-100 */
+ --oauth-border: #d1d5db; /* gray-300, Fleetbase's default button border */
+ --oauth-border-hover: #9ca3af; /* gray-400 */
+ --oauth-text: #1f2937; /* gray-800 */
+}
+.oauth-provider-apple {
+ --oauth-bg: #000000;
+ --oauth-bg-hover: #262626;
+ --oauth-border: #000000;
+ --oauth-border-hover: #262626;
+ --oauth-text: #ffffff;
+}
+.oauth-provider-github {
+ --oauth-bg: #24292f;
+ --oauth-bg-hover: #3a4149;
+ --oauth-border: #24292f;
+ --oauth-border-hover: #3a4149;
+ --oauth-text: #ffffff;
+}
+body[data-theme='dark'] :is(.oauth-provider-google, .oauth-provider-microsoft, .oauth-provider-apple, .oauth-provider-github) {
+ --oauth-bg: #111827; /* gray-900 */
+ --oauth-bg-hover: #1f2937; /* gray-800 */
+ --oauth-border: #374151; /* gray-700 */
+ --oauth-border-hover: #4b5563; /* gray-600 */
+ --oauth-text: #f3f4f6; /* gray-100 */
+}
+
+body :is(.oauth-provider-google, .oauth-provider-microsoft, .oauth-provider-apple, .oauth-provider-github) > button.btn.btn-default {
+ background-color: var(--oauth-bg);
+ border: 1px solid var(--oauth-border);
+ color: var(--oauth-text);
+ transition:
+ background-color 150ms ease,
+ border-color 150ms ease;
+}
+
+body :is(.oauth-provider-google, .oauth-provider-microsoft, .oauth-provider-apple, .oauth-provider-github) > button.btn.btn-default:hover:not(:disabled) {
+ background-color: var(--oauth-bg-hover);
+ border-color: var(--oauth-border-hover);
+ color: var(--oauth-text);
+}
+
+body :is(.oauth-provider-google, .oauth-provider-microsoft, .oauth-provider-apple, .oauth-provider-github) > button.btn.btn-default:focus {
+ border-color: var(--oauth-border-hover);
+ color: var(--oauth-text);
+}
+
+.oauth-provider-logo {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ line-height: 1;
+}
+
+.oauth-provider-logo svg {
+ width: 16px;
+ height: 16px;
+}
+
+body[data-theme='dark'] .oauth-provider-google .oauth-provider-logo-google {
+ background-color: #ffffff;
+ border-radius: 9999px;
+ padding: 2px;
+}
+
+body[data-theme='dark'] .oauth-provider-google .oauth-provider-logo-google svg {
+ width: 14px;
+ height: 14px;
+}
diff --git a/console/app/templates/auth/login.hbs b/console/app/templates/auth/login.hbs
index a924262b..b624f11a 100644
--- a/console/app/templates/auth/login.hbs
+++ b/console/app/templates/auth/login.hbs
@@ -101,10 +101,10 @@
<div class="flex-grow border-t border-gray-300 dark:border-gray-700"></div>
</div>
- {{!-- ember-ui's OauthProviderButton: each provider's logo and colours on the
- shared btn-auth button, the same buttons the sign-up page shows. --}}
+ {{!-- Each provider's logo and colours on Fleetbase's button (see
+ auth/oauth-provider-button); the sign-up page shows the same ones. --}}
{{#each this.oauth.providers as |provider|}}
- <OauthProviderButton
+ <Auth::OauthProviderButton
@provider={{provider}}
@text={{t "auth.login.oauth.continue-with" provider=provider.label}}
@disabled={{this.isLoading}}
diff --git a/console/tests/integration/components/auth/oauth-provider-button-test.js b/console/tests/integration/components/auth/oauth-provider-button-test.js
new file mode 100644
index 00000000..d01e85f7
--- /dev/null
+++ b/console/tests/integration/components/auth/oauth-provider-button-test.js
@@ -0,0 +1,39 @@
+import { module, test } from 'qunit';
+import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
+import { render, click } from '@ember/test-helpers';
+import { hbs } from 'ember-cli-htmlbars';
+
+module('Integration | Component | auth/oauth-provider-button', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.provider = { id: 'google', label: 'Google', icon: 'google' };
+ });
+
+ test('it is a block button carrying the provider, logo at the far left', async function (assert) {
+ await render(hbs`<Auth::OauthProviderButton @provider={{this.provider}} />`);
+
+ assert.dom('.btn-wrapper').hasClass('btn-block').hasClass('oauth-provider-google');
+ assert.dom('button .btn-icon-wrapper .oauth-provider-logo-google').exists();
+ });
+
+ test('it shows the given text, or the provider label', async function (assert) {
+ await render(hbs`<Auth::OauthProviderButton @provider={{this.provider}} @text="Continue with Google" />`);
+ assert.dom('button').hasText('Continue with Google');
+
+ await render(hbs`<Auth::OauthProviderButton @provider={{this.provider}} />`);
+ assert.dom('button').hasText('Google');
+ });
+
+ test('clicking calls onClick with the provider, and is safe without one', async function (assert) {
+ this.clicked = [];
+ this.onClick = (provider) => this.clicked.push(provider);
+ await render(hbs`<Auth::OauthProviderButton @provider={{this.provider}} @onClick={{this.onClick}} />`);
+ await click('button');
+ assert.deepEqual(this.clicked, [this.provider]);
+
+ await render(hbs`<Auth::OauthProviderButton @provider={{this.provider}} />`);
+ await click('button');
+ assert.dom('button').exists();
+ });
+});
diff --git a/console/tests/integration/components/auth/oauth-provider-logo-test.js b/console/tests/integration/components/auth/oauth-provider-logo-test.js
new file mode 100644
index 00000000..6cff6c7e
--- /dev/null
+++ b/console/tests/integration/components/auth/oauth-provider-logo-test.js
@@ -0,0 +1,37 @@
+import { module, test } from 'qunit';
+import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
+import { render } from '@ember/test-helpers';
+import { hbs } from 'ember-cli-htmlbars';
+
+module('Integration | Component | auth/oauth-provider-logo', function (hooks) {
+ setupRenderingTest(hooks);
+
+ test('google gets its full-colour G, never a single-colour icon', async function (assert) {
+ await render(hbs`<Auth::OauthProviderLogo @provider="google" @icon="google" />`);
+
+ const fills = [...this.element.querySelectorAll('path')].map((path) => path.getAttribute('fill'));
+
+ assert.deepEqual(fills, ['#EA4335', '#4285F4', '#FBBC05', '#34A853']);
+ assert.dom('.svg-inline--fa').doesNotExist();
+ });
+
+ test('microsoft gets its four-colour logo', async function (assert) {
+ await render(hbs`<Auth::OauthProviderLogo @provider="microsoft" @icon="microsoft" />`);
+
+ const fills = [...this.element.querySelectorAll('rect')].map((rect) => rect.getAttribute('fill'));
+
+ assert.deepEqual(fills, ['#F25022', '#7FBA00', '#00A4EF', '#FFB900']);
+ });
+
+ test('apple, github and any later provider use their brand icon', async function (assert) {
+ await render(hbs`<Auth::OauthProviderLogo @provider="github" @icon="github" />`);
+
+ assert.dom('.oauth-provider-logo-github .svg-inline--fa').exists();
+ });
+
+ test('it is hidden from screen readers; the button text names the provider', async function (assert) {
+ await render(hbs`<Auth::OauthProviderLogo @provider="google" />`);
+
+ assert.dom('.oauth-provider-logo').hasAttribute('aria-hidden', 'true');
+ });
+});