Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
fix(oauth): keep opened panels open after saving, show every placeholder
Ronald A. Richardsonb0b536f90668
diff --git a/console/app/components/configure/oauth.hbs b/console/app/components/configure/oauth.hbsindex 14dfddd7..7b4e6bde 100644--- a/console/app/components/configure/oauth.hbs+++ b/console/app/components/configure/oauth.hbs@@ -21,7 +21,7 @@</InputGroup></ContentPanel>-{{#each this.providers as |provider|}}+{{#each this.providers key="id" as |provider|}}<ContentPanel @title={{provider.label}} @open={{get this.panelOpen provider.id}} @wrapperClass="bordered-classic"><InputGroup><Toggle@@ -44,7 +44,7 @@class="form-input w-full font-mono text-xs"rows="6"@value={{this.valueFor provider.id field.key}}- placeholder={{if field.secret (this.secretPlaceholder provider.id field.key) ""}}+ placeholder={{this.placeholderFor provider.id field}}autocomplete="off"spellcheck="false"disabled={{this.load.isRunning}}@@ -55,7 +55,7 @@class="form-input w-full"@type={{if field.secret "password" "text"}}@value={{this.valueFor provider.id field.key}}- placeholder={{if field.secret (this.secretPlaceholder provider.id field.key) ""}}+ placeholder={{this.placeholderFor provider.id field}}autocomplete={{if field.secret "new-password" "off"}}disabled={{this.load.isRunning}}{{on "input" (fn this.updateField provider.id field.key)}}diff --git a/console/app/components/configure/oauth.js b/console/app/components/configure/oauth.jsindex 4b32cf4b..55f6824e 100644--- a/console/app/components/configure/oauth.js+++ b/console/app/components/configure/oauth.js@@ -85,6 +85,7 @@ export default class ConfigureOauthComponent extends Component {return Object.entries(provider?.schema ?? {}).map(([key, definition]) => ({key,label: definition.label ?? key,+ placeholder: definition.placeholder ?? '',help: definition.help ?? null,secret: this.isSecret(definition),required: definition.required === true,@@ -97,10 +98,14 @@ export default class ConfigureOauthComponent extends Component {return this.values[providerId]?.[field] ?? '';}- @action secretPlaceholder(providerId, field) {- const status = this.secretStatus[providerId]?.[field];+ /**+ * A saved secret is never sent back, so its box stays empty; the placeholder says+ * one is saved. Otherwise, like every other field, it shows an example value.+ */+ @action placeholderFor(providerId, field) {+ const status = field.secret ? this.secretStatus[providerId]?.[field.key] : null;- return status?.configured ? `Saved (${status.hint ?? '••••'}) — leave blank to keep` : 'Not set';+ return status?.configured ? `Saved (${status.hint ?? '••••'}) — leave blank to keep` : field.placeholder;}@action isProviderEnabled(providerId) {@@ -145,7 +150,14 @@ export default class ConfigureOauthComponent extends Component {@action applyConfig(payload = {}) {const oauth = payload.oauth ?? {};- this.providers = Array.isArray(payload.providers) ? payload.providers : [];+ const providers = Array.isArray(payload.providers) ? payload.providers : [];++ // A save answers with the same definitions. Keeping the objects the panels were+ // rendered from stops every panel re-reading @open and snapping back to its+ // on-load state, which would close whatever the admin had opened.+ if (JSON.stringify(providers) !== JSON.stringify(this.providers)) {+ this.providers = providers;+ }this.redirectUris = payload.redirect_uris ?? {};this.enabled = oauth.enabled !== false;this.allowRegistration = oauth.allow_registration !== false;diff --git a/console/tests/integration/components/configure/oauth-test.js b/console/tests/integration/components/configure/oauth-test.jsindex a5d54ea6..3d70b89d 100644--- a/console/tests/integration/components/configure/oauth-test.js+++ b/console/tests/integration/components/configure/oauth-test.js@@ -32,9 +32,9 @@ const CONFIG = {label: 'Google',icon: 'google',schema: {- client_id: { label: 'Client ID', required: true },- client_secret: { label: 'Client Secret', secret: true, required: true },- hosted_domain: { label: 'Restrict to Workspace domain' },+ client_id: { label: 'Client ID', placeholder: '123-abc.apps.googleusercontent.com', required: true },+ client_secret: { label: 'Client Secret', placeholder: 'GOCSPX-…', secret: true, required: true },+ hosted_domain: { label: 'Restrict to Workspace domain', placeholder: 'example.com' },},},{@@ -42,10 +42,10 @@ const CONFIG = {label: 'Apple',icon: 'apple',schema: {- client_id: { label: 'Services ID', required: true },- team_id: { label: 'Team ID', required: true },- key_id: { label: 'Key ID', required: true },- private_key: { label: 'Signing key (.p8)', secret: true, required: true },+ client_id: { label: 'Services ID', placeholder: 'com.example.signin', required: true },+ team_id: { label: 'Team ID', placeholder: 'A1B2C3D4E5', required: true },+ key_id: { label: 'Key ID', placeholder: 'ABC123DEFG', required: true },+ private_key: { label: 'Signing key (.p8)', placeholder: '-----BEGIN PRIVATE KEY-----', secret: true, required: true },},},],@@ -217,6 +217,26 @@ module('Integration | Component | configure/oauth', function (hooks) {assert.strictEqual(this.element.querySelectorAll('.next-content-panel-header.next-content-panel-is-closed').length, 0);});+ test('saving keeps opened panels open', async function (assert) {+ await render(hbs`<div id="next-view-section-subheader-actions"></div><Configure::Oauth />`);+ await expandAll(this.element);++ await click('#next-view-section-subheader-actions button');++ assert.dom(this.element).containsText('Signing key (.p8)', 'the disabled provider the admin opened is still open');+ assert.strictEqual(this.element.querySelectorAll('.next-content-panel-header.next-content-panel-is-closed').length, 0);+ });++ test('every field shows a placeholder', async function (assert) {+ await render(hbs`<div id="next-view-section-subheader-actions"></div><Configure::Oauth />`);+ await expandAll(this.element);++ const editable = [...this.element.querySelectorAll('.next-content-panel-body input:not([readonly]), .next-content-panel-body textarea')].filter((input) => input.type !== 'checkbox');++ assert.ok(editable.length >= 7, 'every provider field is rendered');+ editable.forEach((input, index) => assert.notStrictEqual(input.placeholder, '', `field ${index + 1} has a placeholder`));+ });+test('a provider can only be switched on after the provider accepts its credentials', async function (assert) {const captured = captureComponent(this.owner, 'configure/oauth', ConfigureOauthComponent);await render(hbs`<div id="next-view-section-subheader-actions"></div><Configure::Oauth />`);