Files
vault/ui/lib/ldap/addon/routes/roles/subdirectory.ts
Jordan Reimer c1754f5f97 [UI] Types Linting (#29702)
* adds linting for types to scripts and lint staged

* fixes issue with AdapterError type

* moves lint-staged setup out of package.json and into config file

* fixes ember data store service type

* fixes route params types

* fixes model types

* fixes general type errors

* fixes ts declaration errors in js files

* adds missing copyright headers

* fixes issue accessing capabilities model properties

* ignores AdapterError import type error

* more updates to AdapterError type

* adds comment to lint-staged config

* moves ember data store type to @ember-data namespace

* updates store import

* moves AdapterError type to @ember-data namespace

* turns ember-data import eslint rule back on
2025-02-25 16:08:51 -07:00

81 lines
2.3 KiB
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import LdapRolesRoute from '../roles';
import { hash } from 'rsvp';
import { ldapBreadcrumbs, roleRoutes } from 'ldap/utils/ldap-breadcrumbs';
import type { Breadcrumb } from 'vault/vault/app-types';
import type Controller from '@ember/controller';
import type LdapRoleModel from 'vault/models/ldap/role';
import type SecretEngineModel from 'vault/models/secret-engine';
import type Transition from '@ember/routing/transition';
interface RouteModel {
backendModel: SecretEngineModel;
roleAncestry: { path_to_role: string; type: string };
roles: Array<LdapRoleModel>;
}
interface RouteController extends Controller {
breadcrumbs: Array<Breadcrumb>;
model: RouteModel;
}
interface RouteParams {
page?: string;
pageFilter?: string;
path_to_role?: string;
type?: string;
}
export default class LdapRolesSubdirectoryRoute extends LdapRolesRoute {
queryParams = {
pageFilter: {
refreshModel: true,
},
page: {
refreshModel: true,
},
};
model(params: RouteParams) {
const backendModel = this.modelFor('application') as SecretEngineModel;
const { path_to_role, type } = params;
const roleAncestry = { path_to_role, type };
return hash({
backendModel,
roleAncestry,
roles: this.lazyQuery(backendModel.id, params, { roleAncestry }),
});
}
setupController(controller: RouteController, resolvedModel: RouteModel, transition: Transition) {
super.setupController(controller, resolvedModel, transition);
const { backendModel, roleAncestry } = resolvedModel;
const routeParams = (childResource: string) => {
return [backendModel.id, roleAncestry.type, childResource];
};
const crumbs = [
{ label: 'Secrets', route: 'secrets', linkExternal: true },
{ label: backendModel.id, route: 'overview' },
{ label: 'Roles', route: 'roles' },
...ldapBreadcrumbs(roleAncestry.path_to_role, routeParams, roleRoutes, true),
];
// must call 'set' so breadcrumbs update as we navigate through directories
controller.set('breadcrumbs', crumbs);
}
resetController(controller: RouteController, isExiting: boolean) {
if (isExiting) {
controller.set('pageFilter', undefined);
controller.set('page', undefined);
}
}
}