-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(status-tag): align approval state classification with design specs (
#44)
- Loading branch information
1 parent
88b3f06
commit 4e9f52d
Showing
4 changed files
with
110 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,69 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import { IconBlock16, IconError16 } from '@dhis2/ui' | ||
import { Approved, Ready, Waiting } from './icons.js' | ||
|
||
/* | ||
* TODO: The current classification logic was discussed with | ||
* Joe Cooper, but needs to be confirmed by either Lars or Jim. | ||
* Specifically these cases are not clear: | ||
* A. Do ACCEPTED_HERE and ACCEPTED_ELSEWHERE fall into "Ready for | ||
* approval and accepted"? This doesn't seem to match the webapi docs. | ||
* B. Should we show a red tag for UNAPPROVABLE and show a negative tag? | ||
* This was not included in the design specs. | ||
*/ | ||
const getTagDisplayData = approvalState => { | ||
const getApprovalStateIcon = approvalState => { | ||
switch (approvalState) { | ||
case 'APPROVED_HERE': | ||
case 'APPROVED_ABOVE': | ||
return { | ||
icon: Approved, | ||
displayName: i18n.t('Approved'), | ||
type: 'positive', | ||
} | ||
|
||
case 'ACCEPTED_HERE': | ||
return { | ||
icon: Ready, | ||
displayName: i18n.t('Ready for approval and accepted'), | ||
type: 'neutral', | ||
} | ||
|
||
case 'UNAPPROVED_READY': | ||
case 'ACCEPTED_HERE': | ||
return { | ||
icon: Ready, | ||
displayName: i18n.t('Ready for approval'), | ||
type: 'neutral', | ||
} | ||
|
||
case 'UNAPPROVED_WAITING': | ||
case 'UNAPPROVED_ABOVE': | ||
return { | ||
icon: Waiting, | ||
displayName: i18n.t('Waiting'), | ||
type: 'default', | ||
} | ||
|
||
case 'APPROVED_HERE': | ||
case 'APPROVED_ABOVE': | ||
return { | ||
icon: Approved, | ||
type: 'positive', | ||
} | ||
case 'UNAPPROVABLE': | ||
return { | ||
icon: Waiting, | ||
displayName: i18n.t('Cannot approve'), | ||
icon: IconBlock16, | ||
type: 'negative', | ||
} | ||
case 'ERROR': | ||
return { | ||
icon: IconError16, | ||
type: 'negative', | ||
} | ||
default: | ||
throw new Error(`Unknown approval state: '${approvalState}'`) | ||
} | ||
} | ||
|
||
const getApprovalStateText = approvalState => { | ||
switch (approvalState) { | ||
case 'UNAPPROVED_READY': | ||
return i18n.t('Ready for approval') | ||
case 'ACCEPTED_HERE': | ||
return i18n.t('Ready for approval — Accepted') | ||
case 'UNAPPROVED_WAITING': | ||
return i18n.t('Waiting for lower level approval') | ||
case 'UNAPPROVED_ABOVE': | ||
return i18n.t('Waiting for higher level approval') | ||
case 'APPROVED_HERE': | ||
case 'APPROVED_ABOVE': | ||
return i18n.t('Approved') | ||
case 'UNAPPROVABLE': | ||
return i18n.t('Cannot be approved') | ||
case 'ERROR': | ||
return i18n.t('Could not retrieve approval status') | ||
default: | ||
throw new Error(`Unknown approval state: '${approvalState}'`) | ||
} | ||
} | ||
|
||
export { getTagDisplayData } | ||
const getTagDisplayData = approvalState => { | ||
const displayName = getApprovalStateText(approvalState) | ||
const { icon, type } = getApprovalStateIcon(approvalState) | ||
|
||
return { displayName, icon, type } | ||
} | ||
|
||
export { getTagDisplayData, getApprovalStateIcon } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { StatusTag } from './status-tag.js' | ||
export { getApprovalStateIcon } from './get-tag-display-data.js' |