-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Secrets Sync] split activation modal into separate component (#26822)
* add new SyncActivationModal component * secrets overview: use SyncActivationModal * tests: add SyncActivationModal tests * int/sync/secrets/overview-test: remove redundant tests now handled by modal tests * cleanup: reorganize sync selectors * chore: will i ever remember copyright headers? nah
- Loading branch information
Noelle Daley
committed
May 22, 2024
1 parent
1884267
commit c5a0040
Showing
8 changed files
with
295 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
ui/lib/sync/addon/components/secrets/sync-activation-modal.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{{! | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: BUSL-1.1 | ||
~}} | ||
|
||
<Hds::Modal @onClose={{@onClose}} data-test-secrets-sync-opt-in-modal as |M|> | ||
<M.Header @icon="alert-triangle"> | ||
Enable Secrets Sync feature | ||
</M.Header> | ||
<M.Body> | ||
<p class="has-bottom-margin-m"> | ||
By enabling the Secrets Sync feature you may incur additional costs. Please review our | ||
<Hds::Link::Inline | ||
@isHrefExternal={{true}} | ||
@href={{doc-link "/hcp/docs/vault/what-is-hcp-vault/client#secrets-sync"}} | ||
>documentation</Hds::Link::Inline> | ||
to learn more. | ||
</p> | ||
<Hds::Form::Checkbox::Field | ||
{{on "change" (fn (mut this.hasConfirmedDocs) (not this.hasConfirmedDocs))}} | ||
data-test-opt-in-check | ||
as |F| | ||
> | ||
<F.Label>I've read the above linked document</F.Label> | ||
</Hds::Form::Checkbox::Field> | ||
</M.Body> | ||
<M.Footer> | ||
<Hds::ButtonSet> | ||
<Hds::Button | ||
data-test-opt-in-confirm | ||
@text="Confirm" | ||
disabled={{not this.hasConfirmedDocs}} | ||
{{on "click" (perform this.onFeatureConfirm)}} | ||
/> | ||
<Hds::Button data-test-opt-in-cancel @text="Cancel" @color="secondary" {{on "click" @onClose}} /> | ||
</Hds::ButtonSet> | ||
</M.Footer> | ||
</Hds::Modal> |
50 changes: 50 additions & 0 deletions
50
ui/lib/sync/addon/components/secrets/sync-activation-modal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { service } from '@ember/service'; | ||
import { task } from 'ember-concurrency'; | ||
import { waitFor } from '@ember/test-waiters'; | ||
import errorMessage from 'vault/utils/error-message'; | ||
|
||
import type FlashMessageService from 'vault/services/flash-messages'; | ||
import type StoreService from 'vault/services/store'; | ||
import type RouterService from '@ember/routing/router-service'; | ||
|
||
interface Args { | ||
onClose: () => void; | ||
onError: (errorMessage: string) => void; | ||
isHvdManaged: boolean; | ||
} | ||
|
||
export default class SyncActivationModal extends Component<Args> { | ||
@service declare readonly flashMessages: FlashMessageService; | ||
@service declare readonly store: StoreService; | ||
@service declare readonly router: RouterService; | ||
|
||
@tracked hasConfirmedDocs = false; | ||
|
||
@task | ||
@waitFor | ||
*onFeatureConfirm() { | ||
// must return null instead of root for non managed cluster. | ||
// child namespaces are not sent. | ||
const namespace = this.args.isHvdManaged ? 'admin' : null; | ||
|
||
try { | ||
yield this.store | ||
.adapterFor('application') | ||
.ajax('/v1/sys/activation-flags/secrets-sync/activate', 'POST', { namespace }); | ||
// must refresh and not transition because transition does not refresh the model from within a namespace | ||
yield this.router.refresh(); | ||
} catch (error) { | ||
this.args.onError(errorMessage(error)); | ||
this.flashMessages.danger(`Error enabling feature \n ${errorMessage(error)}`); | ||
} finally { | ||
this.args.onClose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.