Skip to content

Commit

Permalink
UI: Ember-data upgrade 5.3.2 prep: use custom service instead of exte…
Browse files Browse the repository at this point in the history
…nding ember-data store (#28695)

* rename store to pagination, remove store extension

* initial update of service test

* remove superfluous helper

* replace store with pagination service in main app

* update kmip engine syntax

* add pagination to kmip engine

* update to pagination in config-ui engine

* update sync engine to use pagination service

* use pagination service in kv engine

* use pagination service in ldap engine

* use pagination in pki engine

* update renaming clearDataset functions

* link to jira VAULT-31721

* remove comment
  • Loading branch information
hellobontempo authored Oct 17, 2024
1 parent f2041b0 commit 1fbbf9d
Show file tree
Hide file tree
Showing 58 changed files with 481 additions and 429 deletions.
15 changes: 13 additions & 2 deletions ui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class App extends Application {
'namespace',
{ 'app-router': 'router' },
'store',
'pagination',
'version',
'custom-messages',
],
Expand Down Expand Up @@ -60,6 +61,7 @@ export default class App extends Application {
'path-help',
{ 'app-router': 'router' },
'store',
'pagination',
'version',
'secret-mount-path',
],
Expand All @@ -78,7 +80,14 @@ export default class App extends Application {
},
ldap: {
dependencies: {
services: [{ 'app-router': 'router' }, 'store', 'secret-mount-path', 'flash-messages', 'auth'],
services: [
{ 'app-router': 'router' },
'store',
'pagination',
'secret-mount-path',
'flash-messages',
'auth',
],
externalRoutes: {
secrets: 'vault.cluster.secrets.backends',
},
Expand All @@ -95,6 +104,7 @@ export default class App extends Application {
{ 'app-router': 'router' },
'secret-mount-path',
'store',
'pagination',
'version',
],
externalRoutes: {
Expand All @@ -114,6 +124,7 @@ export default class App extends Application {
{ 'app-router': 'router' },
'secret-mount-path',
'store',
'pagination',
'version',
],
externalRoutes: {
Expand All @@ -125,7 +136,7 @@ export default class App extends Application {
},
sync: {
dependencies: {
services: ['flash-messages', 'flags', { 'app-router': 'router' }, 'store', 'version'],
services: ['flash-messages', 'flags', { 'app-router': 'router' }, 'store', 'pagination', 'version'],
externalRoutes: {
kvSecretOverview: 'vault.cluster.secrets.backend.kv.secret.index',
clientCountOverview: 'vault.cluster.clients',
Expand Down
4 changes: 2 additions & 2 deletions ui/app/components/console/ui-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default Component.extend({
console: service(),
router: service(),
controlGroup: service(),
store: service(),
pagination: service(),
'data-test-component': 'console/ui-panel',
attributeBindings: ['data-test-component'],

Expand Down Expand Up @@ -108,7 +108,7 @@ export default Component.extend({
const currentRoute = owner.lookup(`router:main`).currentRouteName;

try {
this.store.clearDataset();
this.pagination.clearDataset();
yield this.router.transitionTo(currentRoute);
this.logAndOutput(null, { type: 'success', content: 'The current screen has been refreshed!' });
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions ui/app/components/generated-item-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import { tracked } from '@glimmer/tracking';

export default class GeneratedItemList extends Component {
@service router;
@service store;
@service pagination;
@tracked itemToDelete = null;

@action
refreshItemList() {
const route = getOwner(this).lookup(`route:${this.router.currentRouteName}`);
this.store.clearDataset();
this.pagination.clearDataset();
route.refresh();
}
}
3 changes: 2 additions & 1 deletion ui/app/components/keymgmt/distribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const VALID_TYPES_BY_PROVIDER = {
azurekeyvault: ['rsa-2048', 'rsa-3072', 'rsa-4096'],
};
export default class KeymgmtDistribute extends Component {
@service pagination;
@service store;
@service flashMessages;
@service router;
Expand Down Expand Up @@ -191,7 +192,7 @@ export default class KeymgmtDistribute extends Component {
.then(() => {
this.flashMessages.success(`Successfully distributed key ${key} to ${provider}`);
// update keys on provider model
this.store.clearDataset('keymgmt/key');
this.pagination.clearDataset('keymgmt/key');
const providerModel = this.store.peekRecord('keymgmt/provider', provider);
providerModel.fetchKeys(providerModel.keys?.meta?.currentPage || 1);
this.args.onClose();
Expand Down
2 changes: 2 additions & 0 deletions ui/app/mixins/unload-model-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import Mixin from '@ember/object/mixin';
import removeRecord from 'vault/utils/remove-record';
import { service } from '@ember/service';

// removes Ember Data records from the cache when the model
// changes or you move away from the current route
export default Mixin.create({
store: service(),
modelPath: 'model',
unloadModel() {
const { modelPath } = this;
Expand Down
4 changes: 2 additions & 2 deletions ui/app/models/keymgmt/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const validations = {

@withModelValidations(validations)
export default class KeymgmtProviderModel extends Model {
@service store;
@service pagination;
@attr('string') backend;
@attr('string', {
label: 'Provider name',
Expand Down Expand Up @@ -128,7 +128,7 @@ export default class KeymgmtProviderModel extends Model {
} else {
// try unless capabilities returns false
try {
this.keys = await this.store.lazyPaginatedQuery('keymgmt/key', {
this.keys = await this.pagination.lazyPaginatedQuery('keymgmt/key', {
backend: this.backend,
provider: this.name,
responsePath: 'data.keys',
Expand Down
8 changes: 4 additions & 4 deletions ui/app/routes/vault/cluster/access/identity/aliases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import ListRoute from 'core/mixins/list-route';
import { service } from '@ember/service';

export default Route.extend(ListRoute, {
store: service(),
pagination: service(),

model(params) {
const itemType = this.modelFor('vault.cluster.access.identity');
const modelType = `identity/${itemType}-alias`;
return this.store
return this.pagination
.lazyPaginatedQuery(modelType, {
responsePath: 'data.keys',
page: params.page,
Expand All @@ -38,12 +38,12 @@ export default Route.extend(ListRoute, {
willTransition(transition) {
window.scrollTo(0, 0);
if (!transition || transition.targetName !== this.routeName) {
this.store.clearDataset();
this.pagination.clearDataset();
}
return true;
},
reload() {
this.store.clearDataset();
this.pagination.clearDataset();
this.refresh();
},
},
Expand Down
8 changes: 4 additions & 4 deletions ui/app/routes/vault/cluster/access/identity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import ListRoute from 'core/mixins/list-route';
import { service } from '@ember/service';

export default Route.extend(ListRoute, {
store: service(),
pagination: service(),

model(params) {
const itemType = this.modelFor('vault.cluster.access.identity');
const modelType = `identity/${itemType}`;
return this.store
return this.pagination
.lazyPaginatedQuery(modelType, {
responsePath: 'data.keys',
page: params.page,
Expand All @@ -38,12 +38,12 @@ export default Route.extend(ListRoute, {
willTransition(transition) {
window.scrollTo(0, 0);
if (transition.targetName !== this.routeName) {
this.store.clearDataset();
this.pagination.clearDataset();
}
return true;
},
reload() {
this.store.clearDataset();
this.pagination.clearDataset();
this.refresh();
},
},
Expand Down
5 changes: 3 additions & 2 deletions ui/app/routes/vault/cluster/access/leases/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Route from '@ember/routing/route';
import { service } from '@ember/service';

export default Route.extend({
pagination: service(),
store: service(),

queryParams: {
Expand All @@ -26,7 +27,7 @@ export default Route.extend({
const prefix = params.prefix || '';
if (this.modelFor('vault.cluster.access.leases').canList) {
return hash({
leases: this.store
leases: this.pagination
.lazyPaginatedQuery('lease', {
prefix,
responsePath: 'data.keys',
Expand Down Expand Up @@ -104,7 +105,7 @@ export default Route.extend({
willTransition(transition) {
window.scrollTo(0, 0);
if (transition.targetName !== this.routeName) {
this.store.clearDataset();
this.pagination.clearDataset();
}
return true;
},
Expand Down
8 changes: 4 additions & 4 deletions ui/app/routes/vault/cluster/access/method/item/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { singularize } from 'ember-inflector';
import ListRoute from 'vault/mixins/list-route';

export default Route.extend(ListRoute, {
store: service(),
pagination: service(),
pathHelp: service('path-help'),

getMethodAndModelInfo() {
Expand All @@ -25,7 +25,7 @@ export default Route.extend(ListRoute, {
const { page, pageFilter } = this.paramsFor(this.routeName);
const modelType = `generated-${singularize(itemType)}-${type}`;

return this.store
return this.pagination
.lazyPaginatedQuery(modelType, {
responsePath: 'data.keys',
page: page,
Expand All @@ -46,12 +46,12 @@ export default Route.extend(ListRoute, {
willTransition(transition) {
window.scrollTo(0, 0);
if (transition.targetName !== this.routeName) {
this.store.clearDataset();
this.pagination.clearDataset();
}
return true;
},
reload() {
this.store.clearDataset();
this.pagination.clearDataset();
this.refresh();
},
},
Expand Down
7 changes: 4 additions & 3 deletions ui/app/routes/vault/cluster/access/namespaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Route from '@ember/routing/route';
import UnloadModel from 'vault/mixins/unload-model-route';

export default Route.extend(UnloadModel, {
pagination: service(),
store: service(),

queryParams: {
Expand All @@ -27,7 +28,7 @@ export default Route.extend(UnloadModel, {

model(params) {
if (this.version.hasNamespaces) {
return this.store
return this.pagination
.lazyPaginatedQuery('namespace', {
responsePath: 'data.keys',
page: Number(params?.page) || 1,
Expand Down Expand Up @@ -74,12 +75,12 @@ export default Route.extend(UnloadModel, {
willTransition(transition) {
window.scrollTo(0, 0);
if (!transition || transition.targetName !== this.routeName) {
this.store.clearDataset();
this.pagination.clearDataset();
}
return true;
},
reload() {
this.store.clearDataset();
this.pagination.clearDataset();
this.refresh();
},
},
Expand Down
8 changes: 4 additions & 4 deletions ui/app/routes/vault/cluster/policies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ClusterRoute from 'vault/mixins/cluster-route';
import ListRoute from 'core/mixins/list-route';

export default Route.extend(ClusterRoute, ListRoute, {
store: service(),
pagination: service(),
version: service(),

shouldReturnEmptyModel(policyType, version) {
Expand All @@ -21,7 +21,7 @@ export default Route.extend(ClusterRoute, ListRoute, {
if (this.shouldReturnEmptyModel(policyType, this.version)) {
return;
}
return this.store
return this.pagination
.lazyPaginatedQuery(`policy/${policyType}`, {
page: params.page,
pageFilter: params.pageFilter,
Expand Down Expand Up @@ -65,12 +65,12 @@ export default Route.extend(ClusterRoute, ListRoute, {
willTransition(transition) {
window.scrollTo(0, 0);
if (!transition || transition.targetName !== this.routeName) {
this.store.clearDataset();
this.pagination.clearDataset();
}
return true;
},
reload() {
this.store.clearDataset();
this.pagination.clearDataset();
this.refresh();
},
},
Expand Down
9 changes: 5 additions & 4 deletions ui/app/routes/vault/cluster/secrets/backend/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function getValidPage(pageParam) {
}

export default Route.extend({
pagination: service(),
store: service(),
templateName: 'vault/cluster/secrets/backend/list',
pathHelp: service('path-help'),
Expand Down Expand Up @@ -131,7 +132,7 @@ export default Route.extend({

return hash({
secret,
secrets: this.store
secrets: this.pagination
.lazyPaginatedQuery(modelType, {
id: secret,
backend,
Expand Down Expand Up @@ -163,7 +164,7 @@ export default Route.extend({
const has404 = this.has404;
// only clear store cache if this is a new model
if (secret !== controller?.baseKey?.id) {
this.store.clearDataset();
this.pagination.clearDataset();
}
controller.set('hasModel', true);
controller.setProperties({
Expand Down Expand Up @@ -220,12 +221,12 @@ export default Route.extend({
willTransition(transition) {
window.scrollTo(0, 0);
if (transition.targetName !== this.routeName) {
this.store.clearDataset();
this.pagination.clearDataset();
}
return true;
},
reload() {
this.store.clearDataset();
this.pagination.clearDataset();
this.refresh();
},
},
Expand Down
Loading

0 comments on commit 1fbbf9d

Please sign in to comment.