Skip to content

Commit

Permalink
Merge pull request #139 from OpenLMIS-Angola/OAM-226-add-missing-tran…
Browse files Browse the repository at this point in the history
…slations

OAM-226: Added missing translaitons to order create component
  • Loading branch information
olewandowski1 authored Jun 24, 2024
2 parents 4a87089 + 8cf2bf2 commit 0f83f43
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 41 deletions.
3 changes: 3 additions & 0 deletions src/react-components/table/messages_en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"react.table.noItems": "Showing no items"
}
7 changes: 5 additions & 2 deletions src/react-components/table/table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
* http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

import React, { useRef, useState, useLayoutEffect } from 'react';
import React, { useRef, useState, useLayoutEffect, useMemo } from 'react';
import { useTable, usePagination } from 'react-table';

import PrevPageButton from '../buttons/prev-page-button';
import NextPageButton from '../buttons/next-page-button';
import PageButton from '../buttons/page-button';

import getService from '../utils/angular-utils';

const Table = ({
columns,
Expand Down Expand Up @@ -71,6 +72,8 @@ const Table = ({
usePagination
);

const { formatMessage } = useMemo(() => getService('messageService'), []);

const ref = useRef(null);
// Get width of the table and pass it to the table-empty-message
const [width, setWidth] = useState(0);
Expand Down Expand Up @@ -157,7 +160,7 @@ const Table = ({
</table>
{!data.length ? (
<div className='table-empty-message' style={{ width: width }}>
<span>{!noItemsMessage ? "Showing no items" : noItemsMessage}</span>
<span>{!noItemsMessage ? formatMessage('react.table.noItems') : noItemsMessage}</span>
</div>
) : null}
</div>
Expand Down
18 changes: 17 additions & 1 deletion src/requisition-order-create/messages_en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"requisition.orderCreate": "Create Orders",
"requisition.orderCreate.loading": "Loading",
"requisition.orderCreate.view": "View",
"requisition.orderCreate.printOrder": "Print Order",
"requisition.orderCreate.edit": "Edit",
"requisition.orderCreate.create": "Create Order",
"requisition.orderCreate.saveDraft": "Save Draft",
"requisition.orderCreate.submitted": "Orders created successfully",
Expand All @@ -18,5 +22,17 @@
"requisition.orderCreate.reqFacility": "Requesting Facility",
"requisition.orderCreate.reqFacility.placeholder": "Select Requesting Facility",
"requisition.orderCreate.supFacility": "Supplying Facility",
"requisition.orderCreate.supFacility.placeholder": "Select Supplying Facility"
"requisition.orderCreate.supFacility.placeholder": "Select Supplying Facility",
"requisition.orderCreate.table.productCode": "Product Code",
"requisition.orderCreate.table.product": "Product",
"requisition.orderCreate.table.soh": "SOH",
"requisition.orderCreate.table.quantity": "Quantity",
"requisition.orderCreate.table.actions": "Actions",
"requisition.orderCreate.table.facility": "Facility",
"requisition.orderCreate.table.addProduct": "Add",
"requisition.orderCreate.table.productAlreadyAdded": "This product was already added to the table",
"requisition.orderCreate.requisistionInfo.status": "Status",
"requisition.orderCreate.requisistionInfo.dateCreated": "Date Created",
"requisition.orderCreate.searchSelect.placeholder": "Select an option",
"requisition.orderCreate.searchSelect.empty.message": ""
}
2 changes: 1 addition & 1 deletion src/requisition-order-create/order-create-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const OrderCreateForm = () => {
const { formatMessage } = useMemo(() => getService('messageService'), []);
const facilityService = useMemo(() => getService('facilityService'), []);
const orderService = useMemo(() => getService('orderCreateService'), []);
const columns = useMemo(() => orderCreateFormTableColumns, []);
const columns = useMemo(() => orderCreateFormTableColumns(formatMessage), []);

const userId = useMemo(
() => {
Expand Down
9 changes: 6 additions & 3 deletions src/requisition-order-create/order-create-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@
* http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

import React from 'react';
import React, { useMemo } from 'react';
import { HashRouter as Router, Route, Switch, useLocation } from 'react-router-dom';
import OrderCreateTable from './order-create-table';
import OrderCreateForm from './order-create-form';
import Breadcrumbs from '../react-components/breadcrumbs/breadcrumbs';
import getService from '../react-components/utils/angular-utils';

const OrderCreateRouting = () => {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const isReadOnly = queryParams.get('isReadOnly') === 'true';
const { formatMessage } = useMemo(() => getService('messageService'), []);

return (
<div className="page-responsive">
<Breadcrumbs
routes={[
{ path: "/requisitions/orderCreate", breadcrumb: 'Create Order' },
{ path: "/requisitions/orderCreate/:orderIds", breadcrumb: isReadOnly ? 'View' : 'Edit' }
{ path: "/requisitions/orderCreate", breadcrumb: formatMessage('requisition.orderCreate') },
{ path: "/requisitions/orderCreate/:orderIds",
breadcrumb: isReadOnly ? formatMessage('requisition.orderCreate.view') : formatMessage('requisition.orderCreate.edit') }
]}
/>
<Switch>
Expand Down
15 changes: 9 additions & 6 deletions src/requisition-order-create/order-create-requisition-info.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import React from 'react';
import React, { useMemo } from 'react';
import { formatDate } from '../react-components/utils/format-utils';
import getService from '../react-components/utils/angular-utils';

const OrderCreateRequisitionInfo = ({ order }) => {
const { formatMessage } = useMemo(() => getService('messageService'), []);

return (
<aside className="requisition-info">
<ul>
<li>
<strong>Status</strong>
<strong>{ formatMessage('requisition.orderCreate.requisistionInfo.status') }</strong>
{order.status}
</li>
<li>
<strong>Date Created</strong>
<strong>{ formatMessage('requisition.orderCreate.requisistionInfo.dateCreated') }</strong>
{formatDate(order.createdDate)}
</li>
<li>
<strong>Program</strong>
<strong>{ formatMessage('requisition.orderCreate.program') }</strong>
{_.get(order, ['program', 'name'])}
</li>
<li>
<strong>Requesting Facility</strong>
<strong>{ formatMessage('requisition.orderCreate.reqFacility') }</strong>
{_.get(order, ['requestingFacility', 'name'])}
</li>
<li>
<strong>Supplying Facility</strong>
<strong>{ formatMessage('requisition.orderCreate.supFacility') }</strong>
{_.get(order, ['supplyingFacility', 'name'])}
</li>
</ul>
Expand Down
5 changes: 3 additions & 2 deletions src/requisition-order-create/order-create-summary-modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import Modal from '../react-components/modals/modal';
import EditableTable from '../react-components/table/editable-table';
import { orderTableColumns } from './order-create.constant';
import TabNavigation from '../react-components/tab-navigation/tab-navigation';

import getService from '../react-components/utils/angular-utils';

const OrderCreateSummaryModal = ({ isOpen, orders, onSaveClick, onModalClose }) => {
const columns = useMemo(() => orderTableColumns(true), []);
const { formatMessage } = useMemo(() => getService('messageService'), []);
const columns = useMemo(() => orderTableColumns(true, formatMessage), []);
const [currentTab, setCurrentTab] = useState(0);

return (
Expand Down
11 changes: 6 additions & 5 deletions src/requisition-order-create/order-create-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const OrderCreateTab = ({ passedOrder,
const [order, setOrder] = useState({ orderLineItems: [], ...passedOrder });
const [selectedOrderable, setSelectedOrderable] = useState('');
const [orderableOptions, setOrderableOptions] = useState(cachedOrderableOptions);
const columns = useMemo(() => orderTableColumns(isTableReadOnly), []);
const { formatMessage } = useMemo(() => getService('messageService'), []);
const columns = useMemo(() => orderTableColumns(isTableReadOnly, formatMessage), []);
const orderCreatePrintService = useMemo(() => getService('orderCreatePrintService'), []);

useMemo(() => {
Expand Down Expand Up @@ -95,11 +96,11 @@ const OrderCreateTab = ({ passedOrder,
onChange={value => setSelectedOrderable(value)}
objectKey={'id'}
disabled={isTableReadOnly}
>Product</SearchSelect>
>{ formatMessage('requisition.orderCreate.table.product') }</SearchSelect>
}
<div className='buttons-container'>
<Tippy
content="This product was already added to the table"
content={formatMessage('')}
disabled={!isProductAdded}
>
{
Expand All @@ -109,7 +110,7 @@ const OrderCreateTab = ({ passedOrder,
className={"add"}
onClick={addOrderable}
disabled={!selectedOrderable || isProductAdded}
>Add</button>
>{ formatMessage('requisition.orderCreate.table.addProduct') }</button>
</div>
}
</Tippy>
Expand All @@ -118,7 +119,7 @@ const OrderCreateTab = ({ passedOrder,
<button
className="order-print"
onClick={printOrder}>
Print Order
{ formatMessage('requisition.orderCreate.printOrder') }
</button>
}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/requisition-order-create/order-create-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const OrderCreateTable = ({ isReadOnly }) => {
});
});
};

const onOrderBatchDelete = () => {
confirmDestroy(
'requisition.orderCreate.delete.prompt.batch',
Expand Down Expand Up @@ -189,7 +189,7 @@ const OrderCreateTable = ({ isReadOnly }) => {
/>
}
<div className="page-header-responsive">
<h2>Create Order</h2>
<h2>{ formatMessage('requisition.orderCreate') }</h2>
</div>
{
orders.length > 0 &&
Expand Down Expand Up @@ -235,7 +235,7 @@ const OrderCreateTable = ({ isReadOnly }) => {
}
} />
) : (
<p>Loading...</p>
<p>{ formatMessage('requisition.orderCreate.loading') }...</p>
)}
</div>
<div className="page-footer">
Expand Down
33 changes: 17 additions & 16 deletions src/requisition-order-create/order-create.constant.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import React from 'react';
import TrashButton from '../react-components/buttons/trash-button';
import InputCell from '../react-components/table/input-cell';

const orderTableDefaultColumns = [
const orderTableDefaultColumns = (formatMessage) => [
{
Header: 'Product Code',
Header: formatMessage('requisition.orderCreate.table.productCode'),
accessor: 'orderable.productCode'
},
{
Header: 'Product',
Header: formatMessage('requisition.orderCreate.table.product'),
accessor: 'orderable.fullProductName'
},
{
Header: 'SOH',
Header: formatMessage('requisition.orderCreate.table.soh'),
accessor: 'soh',
Cell: ({ value }) => (<div className="text-right">{value}</div>)
},
{
Header: 'Quantity',
Header: formatMessage('requisition.orderCreate.table.quantity'),
accessor: 'orderedQuantity',
Cell: (props) => (
<InputCell
Expand All @@ -28,7 +28,7 @@ const orderTableDefaultColumns = [
)
},
{
Header: 'Actions',
Header: formatMessage('requisition.orderCreate.table.actions'),
accessor: 'id',
Cell: ({ row: { index }, deleteRow }) => (
<TrashButton
Expand All @@ -37,37 +37,38 @@ const orderTableDefaultColumns = [
}
];

const orderReadonlyTableColumns = [
const orderReadonlyTableColumns = (formatMessage) => [
{
Header: 'Product Code',
Header: formatMessage('requisition.orderCreate.table.productCode'),
accessor: 'orderable.productCode'
},
{
Header: 'Product',
Header: formatMessage('requisition.orderCreate.table.product'),
accessor: 'orderable.fullProductName'
},
{
Header: 'SOH',
Header: formatMessage('requisition.orderCreate.table.soh'),
accessor: 'soh',
Cell: ({ value }) => (<div className="text-right">{value}</div>)
},
{
Header: 'Quantity',
Header: formatMessage('requisition.orderCreate.table.quantity'),
accessor: 'orderedQuantity',
}
];

export const orderTableColumns = (isTableReadOnly) => {
return isTableReadOnly ? orderReadonlyTableColumns : orderTableDefaultColumns;
export const orderTableColumns = (isTableReadOnly, formatMessage) => {
return isTableReadOnly ? orderReadonlyTableColumns(formatMessage) :
orderTableDefaultColumns(formatMessage);
}

export const orderCreateFormTableColumns = [
export const orderCreateFormTableColumns = (formatMessage) => [
{
Header: 'Facility',
Header: formatMessage('requisition.orderCreate.table.facility'),
accessor: 'name'
},
{
Header: 'Actions',
Header: formatMessage('requisition.orderCreate.table.actions'),
accessor: 'value',
Cell: ({ row: { index }, deleteRow }) => (
<TrashButton onClick={() => deleteRow(index)} />
Expand Down
Loading

0 comments on commit 0f83f43

Please sign in to comment.