Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | /** |
| 6 | * @fileoverview A file containing common constants used in the Approvals |
| 7 | * feature. |
| 8 | */ |
| 9 | |
| 10 | // Only approvers are allowed to set an approval state to one of these states. |
| 11 | export const APPROVER_RESTRICTED_STATUSES = new Set( |
| 12 | ['NA', 'Approved', 'NotApproved']); |
| 13 | |
| 14 | // Map the internal enum names used in Monorail's backend from approval |
| 15 | // statuses to user friendly names. |
| 16 | export const STATUS_ENUM_TO_TEXT = { |
| 17 | '': 'NotSet', |
| 18 | 'NEEDS_REVIEW': 'NeedsReview', |
| 19 | 'NA': 'NA', |
| 20 | 'REVIEW_REQUESTED': 'ReviewRequested', |
| 21 | 'REVIEW_STARTED': 'ReviewStarted', |
| 22 | 'NEED_INFO': 'NeedInfo', |
| 23 | 'APPROVED': 'Approved', |
| 24 | 'NOT_APPROVED': 'NotApproved', |
| 25 | }; |
| 26 | |
| 27 | // Reverse mapping of user friendly names to internal enum names. |
| 28 | // Note that NotSet -> NOT_SET maps differently in reverse because |
| 29 | // the backend sends an empty message to communicate NOT_SET. |
| 30 | export const TEXT_TO_STATUS_ENUM = { |
| 31 | 'NotSet': 'NOT_SET', |
| 32 | 'NeedsReview': 'NEEDS_REVIEW', |
| 33 | 'NA': 'NA', |
| 34 | 'ReviewRequested': 'REVIEW_REQUESTED', |
| 35 | 'ReviewStarted': 'REVIEW_STARTED', |
| 36 | 'NeedInfo': 'NEED_INFO', |
| 37 | 'Approved': 'APPROVED', |
| 38 | 'NotApproved': 'NOT_APPROVED', |
| 39 | }; |
| 40 | |
| 41 | // Statuses mapped to CSS classes used to apply custom styles per |
| 42 | // status like background colors. |
| 43 | export const STATUS_CLASS_MAP = { |
| 44 | 'NotSet': 'status-notset', |
| 45 | 'NeedsReview': 'status-notset', |
| 46 | 'NA': 'status-na', |
| 47 | 'ReviewRequested': 'status-pending', |
| 48 | 'ReviewStarted': 'status-pending', |
| 49 | 'NeedInfo': 'status-pending', |
| 50 | 'Approved': 'status-approved', |
| 51 | 'NotApproved': 'status-rejected', |
| 52 | }; |
| 53 | |
| 54 | // Hardcoded frontent documentation for each approval status. |
| 55 | export const STATUS_DOCSTRING_MAP = { |
| 56 | 'NotSet': '', |
| 57 | 'NeedsReview': 'Review/survey not started', |
| 58 | 'NA': 'Approval gate not required', |
| 59 | 'ReviewRequested': 'Approval requested', |
| 60 | 'ReviewStarted': 'Approval in progress', |
| 61 | 'NeedInfo': 'Approval review needs more information', |
| 62 | 'Approved': 'Approved for Launch', |
| 63 | 'NotApproved': 'Not Approved for Launch', |
| 64 | }; |
| 65 | |
| 66 | // The Material Design icon names that are attached to each |
| 67 | // CSS class. |
| 68 | export const CLASS_ICON_MAP = { |
| 69 | 'status-na': 'remove', |
| 70 | 'status-notset': 'warning', |
| 71 | 'status-pending': 'autorenew', |
| 72 | 'status-approved': 'done', |
| 73 | 'status-rejected': 'close', |
| 74 | }; |
| 75 | |
| 76 | // Statuses formated as an Array rather than an Object for ease of use |
| 77 | // by components. |
| 78 | export const APPROVAL_STATUSES = Object.keys(STATUS_CLASS_MAP).map( |
| 79 | (status) => ({status, docstring: STATUS_DOCSTRING_MAP[status], rank: 1})); |