-
Notifications
You must be signed in to change notification settings - Fork 91
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
Changes from all commits
655a7ff
b4a3a07
8cf4d86
4e4e021
2ea16fe
eec8d3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
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 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. 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. 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; | ||
}; | ||
} |
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); | ||
}); | ||
}); |
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.
Do we want to define the stings here? That could become a VERY long list.
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.
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
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.
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?