Skip to content
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

Adds icon-status component #815

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions client/app/services/service-details/service-details-ansible.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ <h3 translate>Results</h3>
<div class="form-group">
<label class="control-label col-sm-3" translate>Status</label>
<div class="col-sm-8">
<input class="form-control text-capitalize" readonly
value="{{item.stack.status || ('Unknown' | translate)}}"/>
<icon-status status="item.stack.status" success="['successful', 'succeeded', 'create_complete']"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to define the stings here? That could become a VERY long list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presently not a long list, hence the deliberate inclusion for this first run. If it gets much longer tho you're spot on, const in the js is gonna be da way to play

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question about these strings being passed into the component, do we have to worry about those strings being translated and having that ruin the functionality they are meant for?

error="['failure', 'failed']"></icon-status>
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -94,7 +94,7 @@ <h3 translate>Details</h3>
</span>
</div>
<pf-list-view ng-if="item.credentials.length > 0" config="vm.credListConfig"
items="item.credentials" custom-scope="vm">
items="item.credentials" custom-scope="vm">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
<div class="list-view-stacked-item">
Expand Down Expand Up @@ -144,7 +144,7 @@ <h3 translate>Details</h3>
</span>
</div>
<pf-list-view ng-if="item.jobs.length > 0" config="vm.playsListConfig"
items="item.jobs" custom-scope="vm">
items="item.jobs" custom-scope="vm">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
<div class="list-view-stacked-item">
Expand All @@ -157,9 +157,9 @@ <h3 translate>Details</h3>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<div class="list-view-stacked-item">
<strong translate>Status</strong>
<div class="text-capitalize">
{{ item.resource_status }}
</div>
<icon-status status="item.stack.status"
success="['successful', 'succeeded', 'create_complete']"
error="['failure', 'failed']"></icon-status>
</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
Expand Down
50 changes: 50 additions & 0 deletions client/app/shared/icon-status.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export const IconStatusComponent = {
controllerAs: 'vm',
controller: ComponentController,
bindings: {
status: '<',
success: '<?',
error: '<?',
queued: '<?',
inprogress: '<?',
},
template: `
<i class="pficon pficon-ok" ng-if="vm.isSuccess"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could make this template a lot more concise. I would make one icon and write a function in the component that returns the CSS class to show and just use ng-class to display the resulting css class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally verbose, favoring readability rather than conciseness, as was demonstrated above, likely these values are going to change

One below, don't have to worry about translations breaking functionality value and check value(s) are passed by the user, most often specified by the backend for both

uib-tooltip="{{vm.status}}"
tooltip-append-to-body="true"
tooltip-popup-delay="1000"
tooltip-placement="bottom" />
<i class="pficon pficon-error-circle-o" ng-if="vm.isError"
uib-tooltip="{{vm.status}}"
tooltip-append-to-body="true"
tooltip-popup-delay="1000"
tooltip-placement="bottom" />
<span ng-if="vm.isInprogress" class="spinner spinner-xs spinner-inline"/>
<i class="fa fa-hourglass-half" ng-if="vm.isQueued"
uib-tooltip="{{vm.status}}"
tooltip-append-to-body="true"
tooltip-popup-delay="1000"
tooltip-placement="bottom" />
<i class="pficon pficon-help" ng-if="vm.isUnknown"
uib-tooltip="{{vm.status}}"
tooltip-append-to-body="true"
tooltip-popup-delay="1000"
tooltip-placement="bottom" />
`,
};

/** @ngInject */
function ComponentController(lodash) {
const vm = this;
vm.$onChanges = function() {
vm.status = lodash.capitalize(vm.status);

angular.extend(vm, {
isSuccess: vm.success ? vm.success.some((status) => status.toLowerCase() === vm.status.toLowerCase()) : false,
isError: vm.error ? vm.error.some((status) => status.toLowerCase() === vm.status.toLowerCase()) : false,
isQueued: vm.queued ? vm.queued.some((status) => status.toLowerCase() === vm.status.toLowerCase()) : false,
isInprogress: vm.inprogress ? vm.inprogress.some((status) => status.toLowerCase() === vm.status.toLowerCase()) : false,
});
vm.isUnknown = !vm.isSuccess && !vm.isError && !vm.isQueued && !vm.isInprogress;
};
}
47 changes: 47 additions & 0 deletions client/app/shared/icon-status.component.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
describe('Component: Icon-status', () => {
let parentScope, $compile;

beforeEach(module('app.services', 'app.shared'));

beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
parentScope = _$rootScope_.$new();
}));

const compileHtml = function(markup, scope) {
let element = angular.element(markup);
$compile(element)(scope);
scope.$digest();
return element;
};

it('should display success when status matches success', () => {
const renderedElement = compileHtml(angular.element(`<icon-status status="'success'" success="['success']"/>`), parentScope);

expect(renderedElement[0].querySelectorAll('.pficon-ok').length).to.eq(1);
});

it('should display error when status matches error', () => {
const renderedElement = compileHtml(angular.element(`<icon-status status="'error'" error="['error']"/>`), parentScope);

expect(renderedElement[0].querySelectorAll('.pficon-error-circle-o').length).to.eq(1);
});

it('should display pending when status matches pending', () => {
const renderedElement = compileHtml(angular.element(`<icon-status status="'pending'" queued="['pending']"/>`), parentScope);

expect(renderedElement[0].querySelectorAll('.fa-hourglass-half').length).to.eq(1);
});

it('should display spinner when status is matches inprogress', () => {
const renderedElement = compileHtml(angular.element(`<icon-status status="'inprogress'" inprogress="['inprogress']"/>`), parentScope);

expect(renderedElement[0].querySelectorAll('.spinner').length).to.eq(1);
});

it('should display unknown when status unknown', () => {
const renderedElement = compileHtml(angular.element(`<icon-status status="'foo'"/>`), parentScope);

expect(renderedElement[0].querySelectorAll('.pficon-help').length).to.eq(1);
});
});
2 changes: 2 additions & 0 deletions client/app/shared/shared.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {CustomDropdownComponent} from "./custom-dropdown/custom-dropdown.compone
import {DialogContentComponent} from "./dialog-content/dialog-content.component.js";
import {ElapsedTime} from "./elapsedTime.filter.js";
import {IconListComponent} from "./icon-list/icon-list.component.js";
import {IconStatusComponent} from './icon-status.component.js';
import {LoadingComponent} from "./loading.component.js";
import {PaginationComponent} from "./pagination/pagination.component.js";
import {SSCardComponent} from "./ss-card/ss-card.component.js";
Expand All @@ -30,6 +31,7 @@ export const SharedModule = angular
.component('dialogContent', DialogContentComponent)
.component('explorerPagination', PaginationComponent)
.component('iconList', IconListComponent)
.component('iconStatus', IconStatusComponent)
.component('loading', LoadingComponent)
.component('ssCard', SSCardComponent)
.component('taggingWidget', TaggingComponent)
Expand Down