-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter Secret Engine List view by engineType and/or name #20481
Merged
Monkeychip
merged 22 commits into
main
from
ui/VAULT-16024/filter-secret-engines-type-name
May 15, 2023
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7f39915
initial WIP glimmerize the controller
Monkeychip 152aac3
wip got the filter engine type by supported backends working
Monkeychip 252c396
got filter by engine type working
Monkeychip 4e9682e
wip need to refactor but working ish for name
Monkeychip e54db03
wip working state with both filters, does not work if both fiters are…
Monkeychip c143cf9
fixed when you have two selected filters, but broken for multiples of…
Monkeychip 97b80df
remove repeated engineTypes in filter list
Monkeychip b5c2e93
add disabled to power select
Monkeychip 577886c
fix bug of glimmer for the concurrency task.
Monkeychip 4a1c09f
wording fix
Monkeychip 34f71f9
remove linkableItem and the nested contextual compnents to help with …
Monkeychip 586d8e5
add changelog
Monkeychip 994ccde
fix some tests
Monkeychip f11e204
add test coverage
Monkeychip 7d1c095
Update 20481.txt
Monkeychip a66e319
Merge branch 'main' into ui/VAULT-16024/filter-secret-engines-type-name
Monkeychip eed1407
Merge branch 'ui/VAULT-16024/filter-secret-engines-type-name' of gith…
Monkeychip 3faa498
test fixes 🤞
Monkeychip ed8ec45
test fix?
Monkeychip 92f8aa9
address a pr comment and save
Monkeychip d90698a
Merge branch 'main' into ui/VAULT-16024/filter-secret-engines-type-name
Monkeychip 5ea6e66
address pr comment
Monkeychip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
ui: Add filtering by engine type and engine name to the Secret Engine list view. | ||
``` |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -2,36 +2,76 @@ | |||||
* Copyright (c) HashiCorp, Inc. | ||||||
* SPDX-License-Identifier: MPL-2.0 | ||||||
*/ | ||||||
|
||||||
import { filterBy } from '@ember/object/computed'; | ||||||
import { computed } from '@ember/object'; | ||||||
/* eslint ember/no-computed-properties-in-native-classes: 'warn' */ | ||||||
import Controller from '@ember/controller'; | ||||||
import { task } from 'ember-concurrency'; | ||||||
import { supportedSecretBackends } from 'vault/helpers/supported-secret-backends'; | ||||||
import { inject as service } from '@ember/service'; | ||||||
const LINKED_BACKENDS = supportedSecretBackends(); | ||||||
|
||||||
export default Controller.extend({ | ||||||
flashMessages: service(), | ||||||
displayableBackends: filterBy('model', 'shouldIncludeInList'), | ||||||
|
||||||
supportedBackends: computed('displayableBackends', 'displayableBackends.[]', function () { | ||||||
return (this.displayableBackends || []) | ||||||
.filter((backend) => LINKED_BACKENDS.includes(backend.get('engineType'))) | ||||||
.sortBy('id'); | ||||||
}), | ||||||
|
||||||
unsupportedBackends: computed( | ||||||
'displayableBackends', | ||||||
'displayableBackends.[]', | ||||||
'supportedBackends', | ||||||
'supportedBackends.[]', | ||||||
function () { | ||||||
return (this.displayableBackends || []).slice().removeObjects(this.supportedBackends).sortBy('id'); | ||||||
import { action } from '@ember/object'; | ||||||
import { tracked } from '@glimmer/tracking'; | ||||||
import { filterBy } from '@ember/object/computed'; | ||||||
import { dropTask } from 'ember-concurrency'; | ||||||
|
||||||
export default class VaultClusterSecretsBackendController extends Controller { | ||||||
@service flashMessages; | ||||||
@filterBy('model', 'shouldIncludeInList') displayableBackends; | ||||||
|
||||||
@tracked secretEngineOptions = []; | ||||||
@tracked selectedEngineType = null; | ||||||
@tracked selectedEngineName = null; | ||||||
|
||||||
get sortedDisplayableBackends() { | ||||||
// show supported secret engines first and then organize those by id. | ||||||
const sortedBackends = this.displayableBackends.sort( | ||||||
(a, b) => b.isSupportedBackend - a.isSupportedBackend || a.id - b.id | ||||||
); | ||||||
|
||||||
// return an options list to filter by engine type, ex: 'kv' | ||||||
if (this.selectedEngineType) { | ||||||
// check first if the user has also filtered by name. | ||||||
if (this.selectedEngineName) { | ||||||
return sortedBackends.filter((backend) => this.selectedEngineName === backend.get('id')); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to use
Suggested change
But if that doesn't work for some reason I'd like to understand why! |
||||||
} | ||||||
// otherwise filter by engine type | ||||||
return sortedBackends.filter((backend) => this.selectedEngineType === backend.get('engineType')); | ||||||
} | ||||||
), | ||||||
|
||||||
disableEngine: task(function* (engine) { | ||||||
// return an options list to filter by engine name, ex: 'secret' | ||||||
if (this.selectedEngineName) { | ||||||
return sortedBackends.filter((backend) => this.selectedEngineName === backend.get('id')); | ||||||
} | ||||||
// no filters, return full sorted list. | ||||||
return sortedBackends; | ||||||
} | ||||||
|
||||||
get secretEngineArrayByType() { | ||||||
const arrayOfAllEngineTypes = this.sortedDisplayableBackends.map((modelObject) => modelObject.engineType); | ||||||
// filter out repeated engineTypes (e.g. [kv, kv] => [kv]) | ||||||
const arrayOfUniqueEngineTypes = [...new Set(arrayOfAllEngineTypes)]; | ||||||
|
||||||
return arrayOfUniqueEngineTypes.map((engineType) => ({ | ||||||
name: engineType, | ||||||
id: engineType, | ||||||
})); | ||||||
} | ||||||
|
||||||
get secretEngineArrayByName() { | ||||||
return this.sortedDisplayableBackends.map((modelObject) => ({ | ||||||
name: modelObject.id, | ||||||
id: modelObject.id, | ||||||
})); | ||||||
} | ||||||
|
||||||
@action | ||||||
filterEngineType([type]) { | ||||||
this.selectedEngineType = type; | ||||||
} | ||||||
|
||||||
@action | ||||||
filterEngineName([name]) { | ||||||
this.selectedEngineName = name; | ||||||
} | ||||||
|
||||||
@dropTask | ||||||
*disableEngine(engine) { | ||||||
const { engineType, path } = engine; | ||||||
try { | ||||||
yield engine.destroyRecord(); | ||||||
|
@@ -41,5 +81,5 @@ export default Controller.extend({ | |||||
`There was an error disabling the ${engineType} Secrets Engine at ${path}: ${err.errors.join(' ')}.` | ||||||
); | ||||||
} | ||||||
}).drop(), | ||||||
}); | ||||||
} | ||||||
} |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open to suggestions on ways to make this cleaner, but for context here is the flow:
options
param passed into the SearchSelect components.