feat: storage policies list view (#2071)

policies list view
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2024-01-08 15:12:49 -08:00
1 parent b3abb658ab
commit b79eebf73a
14 files changed
+538 -6

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ModelAbility from './model';
import { service } from '@ember/service';
/**
* Provides abilities for storage policies.
*/
export default class PolicyAbility extends ModelAbility {
// =services
@service features;
// =permissions
/**
* This ensures that storage policies may be read only if the
* session-recording feature flag is enabled.
*/
get canRead() {
return this.features.isEnabled('ssh-session-recording')
? super.canRead
: false;
}
/**
* This ensures that storage policies may be updated only if the
* session-recording feature flag is enabled.
*/
get canUpdate() {
return this.features.isEnabled('ssh-session-recording')
? super.canUpdate
: false;
}
/**
* This ensures that storage policies may be deleted only if the
* session-recording feature flag is enabled.
*/
get canDelete() {
return this.features.isEnabled('ssh-session-recording')
? super.canDelete
: false;
}
}
+6
View File
@@ -0,0 +1,6 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
export { default } from 'api/abilities/policy';
+2 -2
View File
@@ -22,12 +22,12 @@ export default factory.extend({
attributes() {
return {
retain_for: {
days: faker.number.int({ min: 10, max: 700 }),
days: faker.number.int({ min: 10, max: 100 }),
overridable: faker.datatype.boolean(),
},
delete_after: {
days: faker.number.int({ min: 1, max: 500 }),
days: faker.number.int({ min: 101, max: 500 }),
overridable: faker.datatype.boolean(),
},
};
@@ -0,0 +1,35 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
/**
* Takes a `Day` instance and returns in year format if there are no remainders,
* * @example
* {{format-day-year number}}
*
**/
export default class extends Helper {
// =services
@service intl;
// =compute method
/**
* @param {number} days
* @return string
*/
compute([days]) {
const remainder = days % 365;
if (remainder === 0) {
const numberOfYears = days / 365;
return this.intl.t('titles.year', { numberOfYears });
} else {
return this.intl.t('titles.days', { days });
}
}
}
@@ -0,0 +1,6 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
export { default } from 'core/helpers/format-day-year';
@@ -0,0 +1,38 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupIntl } from 'ember-intl/test-support';
module('Integration | Helper | format-day-year', function (hooks) {
setupRenderingTest(hooks);
setupIntl(hooks);
test('it renders correctly when it is 1 year', async function (assert) {
this.set('inputValue', 365);
await render(hbs`{{format-day-year this.inputValue}}`);
assert.strictEqual(this.element.textContent.trim(), '1 year');
});
test('it renders correctly when it is more than 1 year', async function (assert) {
this.set('inputValue', 730);
await render(hbs`{{format-day-year this.inputValue}}`);
assert.strictEqual(this.element.textContent.trim(), '2 years');
});
test('it renders correctly when it is not a whole year', async function (assert) {
this.set('inputValue', 800);
await render(hbs`{{format-day-year this.inputValue}}`);
assert.strictEqual(this.element.textContent.trim(), '800 days');
});
test('it renders when null', async function (assert) {
this.set('inputValue', null);
await render(hbs`{{format-date-iso this.inputValue}}`);
assert.strictEqual(this.element.textContent.trim(), '');
});
});
+3
View File
@@ -38,6 +38,9 @@ titles:
create-resources: Create Resources
choose-an-option: Choose an option
feature-edition: 'Edition: {edition}'
unit: Unit
year: '{numberOfYears, plural, =1 {# year} other {# years}}'
days: '{days, plural, =1 {# day} other {# days}}'
descriptions:
empty-set: There are no items to display yet. You may be able to add items or try back later.
cluster-url-initialization: To get started, please enter your cluster URL
@@ -920,3 +920,15 @@ policy:
title_plural: Storage Policies
titles:
new: New Storage Policy
policy_name: Policy name
retain_for: Retain for
delete_after: Delete After
do_not_delete: Do not delete
forever: Forever
actions:
delete: Delete Storage Policy
messages:
none:
title: No storage policies yet
description: Storage policies define how long to store recordings before they are automatically deleted. We recommend checking your data retention policies for compliance requirements.
link: Create a new storage policy