From 225f57fefd61ec8da83a26164b40b7422912d1c9 Mon Sep 17 00:00:00 2001 From: mabashian Date: Thu, 27 Aug 2020 09:26:23 -0400 Subject: [PATCH] Remove use of i18n.plural in favor of low level i18n._. --- .../JobList/JobListCancelButton.jsx | 58 +++++++++++-------- .../JobList/JobListCancelButton.test.jsx | 17 +----- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/awx/ui_next/src/components/JobList/JobListCancelButton.jsx b/awx/ui_next/src/components/JobList/JobListCancelButton.jsx index a178034479..a4fbc197b4 100644 --- a/awx/ui_next/src/components/JobList/JobListCancelButton.jsx +++ b/awx/ui_next/src/components/JobList/JobListCancelButton.jsx @@ -13,6 +13,8 @@ function cannotCancel(job) { function JobListCancelButton({ i18n, jobsToCancel, onCancel }) { const [isModalOpen, setIsModalOpen] = useState(false); + const numJobsToCancel = jobsToCancel.length; + const zeroOrOneJobSelected = numJobsToCancel < 2; const handleCancel = () => { onCancel(); @@ -22,26 +24,28 @@ function JobListCancelButton({ i18n, jobsToCancel, onCancel }) { const renderTooltip = () => { const jobsUnableToCancel = jobsToCancel .filter(cannotCancel) - .map(job => job.name) - .join(', '); - if (jobsToCancel.some(cannotCancel)) { + .map(job => job.name); + const numJobsUnableToCancel = jobsUnableToCancel.length; + if (numJobsUnableToCancel > 0) { return (
- {i18n.plural({ - value: jobsToCancel.length, - one: 'You do not have permission to cancel the following job: ', - other: 'You do not have permission to cancel the following jobs: ', - })} - {jobsUnableToCancel} + {i18n._( + '{numJobsUnableToCancel, plural, one {You do not have permission to cancel the following job:} other {You do not have permission to cancel the following jobs:}}', + { + numJobsUnableToCancel, + } + )} + {' '.concat(jobsUnableToCancel.join(', '))}
); } - if (jobsToCancel.length) { - return i18n.plural({ - value: jobsToCancel.length, - one: 'Cancel selected job', - other: 'Cancel selected jobs', - }); + if (numJobsToCancel > 0) { + return i18n._( + '{numJobsToCancel, plural, one {Cancel selected job} other {Cancel selected jobs}}', + { + numJobsToCancel, + } + ); } return i18n._(t`Select a job to cancel`); }; @@ -49,11 +53,12 @@ function JobListCancelButton({ i18n, jobsToCancel, onCancel }) { const isDisabled = jobsToCancel.length === 0 || jobsToCancel.some(cannotCancel); - const cancelJobText = i18n.plural({ - value: jobsToCancel.length < 2, - one: 'Cancel job', - other: 'Cancel jobs', - }); + const cancelJobText = i18n._( + '{zeroOrOneJobSelected, plural, one {Cancel job} other {Cancel jobs}}', + { + zeroOrOneJobSelected, + } + ); return ( @@ -90,6 +95,7 @@ function JobListCancelButton({ i18n, jobsToCancel, onCancel }) { onClose={() => setIsModalOpen(false)} actions={[