Skip to content

Commit

Permalink
Merge pull request #52 from openimis/develop
Browse files Browse the repository at this point in the history
MERGING RELEASE branches
  • Loading branch information
delcroip authored May 16, 2023
2 parents 7427526 + 1013f1f commit 273d933
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
16 changes: 9 additions & 7 deletions src/components/ProductForm/DataGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const CellActions = (props) => {
};

const DataGrid = (props) => {
const { className, onChange, error, isLoading, density, rows = [], bindLimitTypesWithDefaultValues } = props;
const { className, onChange, error, isLoading, density, readOnly, rows = [], bindLimitTypesWithDefaultValues } = props;
const [editRowsModel, setEditRowsModel] = useState({});
const modulesManager = useModulesManager();
const { formatMessage } = useTranslations("product.DataGrid", modulesManager);
Expand All @@ -110,8 +110,10 @@ const DataGrid = (props) => {

const renderCellActions = (props) => <CellActions {...props} onRowDelete={onRowDelete} />;

const columns = useMemo(
() => [
const columns = useMemo(() => {
const baseColumns = props.columns;
if (readOnly) return baseColumns;
return [
{
field: "actions",
headerName: formatMessage("actions"),
Expand All @@ -120,10 +122,10 @@ const DataGrid = (props) => {
disableColumnMenu: true,
width: 100,
},
...props.columns,
],
[props.columns, rows],
);
...baseColumns,
];
}, [props.columns, readOnly]);


const handleEditRowsModel = (itemsOrServices) => {
bindLimitTypesWithDefaultValues(itemsOrServices, prevItemsOrServicesRef.current)
Expand Down
16 changes: 10 additions & 6 deletions src/components/ProductForm/GenericItemsTabForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {usePageDisplayRulesQuery} from "../../hooks";
import {GridRenderCellParams} from "@mui/x-data-grid";

const ItemsTabForm = (props) => {
const { classes, className, isLoading, onChange, onAdd, rows = [], itemColumns, Picker, getLimitValueSwitch} = props;
const { classes, className, isLoading, onChange, onAdd, readOnly, rows = [],
itemColumns, Picker, getLimitValueSwitch} = props;
const modulesManager = useModulesManager();
const { formatMessage } = useTranslations("product", modulesManager);
const [isDialogOpen, setDialogOpen] = useState(false);
Expand Down Expand Up @@ -151,11 +152,13 @@ const ItemsTabForm = (props) => {
Picker={Picker}
/>
<Grid container className={className}>
<Grid item container xs={4} className={classes.item}>
<Button startIcon={<AddIcon />} variant="contained" onClick={() => setDialogOpen(true)}>
{formatMessage("ItemsOrServicesGrid.addItemsButton")}
</Button>
</Grid>
{!readOnly && (
<Grid item container xs={4} className={classes.item}>
<Button startIcon={<AddIcon />} variant="contained" onClick={() => setDialogOpen(true)}>
{formatMessage("ItemsOrServicesGrid.addItemsButton")}
</Button>
</Grid>
)}
<Grid item xs={12} className={classes.dataGridWrapper}>
<ErrorBoundary>
{ isLoadedRules && (
Expand All @@ -166,6 +169,7 @@ const ItemsTabForm = (props) => {
columns={columns}
density="compact"
rows={rows}
readOnly={readOnly}
bindLimitTypesWithDefaultValues={bindLimitTypesWithDefaultValues}
/>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ProductForm/ItemsTabForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import _ from "lodash";
import GenericItemsTabForm from "./GenericItemsTabForm";

const ItemsTabForm = (props) => {
const { edited, edited_id, onEditedChanged, limitType, priceOrigin, getLimitValueSwitch } = props;
const { edited, edited_id, onEditedChanged, limitType, priceOrigin, getLimitValueSwitch, readOnly } = props;
const modulesManager = useModulesManager();
const intl = useIntl();
const dispatch = useDispatch();
Expand Down Expand Up @@ -105,6 +105,7 @@ const ItemsTabForm = (props) => {
isLoading={isLoading}
rows={edited.items ?? []}
onChange={onChange}
readOnly={readOnly}
onAdd={onAdd}
getLimitValueSwitch={getLimitValueSwitch}
Picker={(props) => (
Expand Down
7 changes: 4 additions & 3 deletions src/components/ProductForm/ProductForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ import ReplayIcon from "@material-ui/icons/Replay";

const ProductForm = (props) => {
const { readOnly, onBack, onSave, product, canSave, onReset, onChange, autoFocus, isDuplicate } = props;
const returnMethodOrReadOnly = (method) => readOnly? !readOnly: method;

return (
<Form
module="product"
title={product?.uuid ? "product.ProductForm.title" : "product.ProductForm.emptyTitle"}
titleParams={{ label: product.name ?? "" }}
readOnly={readOnly}
canSave={canSave}
canSave={returnMethodOrReadOnly(canSave)}
onEditedChanged={onChange}
edited={product}
isDuplicate={isDuplicate}
edited_id={product.uuid}
HeadPanel={MainPanelForm}
Panels={[TabsForm]}
save={onSave}
save={returnMethodOrReadOnly(onSave)}
autoFocus={autoFocus}
back={onBack}
openDirty={onSave}
openDirty={returnMethodOrReadOnly(onSave)}
actions={[
{
doIt: onReset,
Expand Down
3 changes: 2 additions & 1 deletion src/components/ProductForm/ServicesTabForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import _ from "lodash";
import GenericItemsTabForm from "./GenericItemsTabForm";

const ServicesTabForm = (props) => {
const { edited, edited_id, onEditedChanged, limitType, priceOrigin, getLimitValueSwitch } = props;
const { edited, edited_id, onEditedChanged, limitType, priceOrigin, getLimitValueSwitch, readOnly } = props;
const modulesManager = useModulesManager();
const intl = useIntl();
const dispatch = useDispatch();
Expand Down Expand Up @@ -105,6 +105,7 @@ const ServicesTabForm = (props) => {
rows={edited.services ?? []}
onChange={onChange}
onAdd={onAdd}
readOnly={readOnly}
getLimitValueSwitch={getLimitValueSwitch}
Picker={(props) => (
<PublishedComponent
Expand Down
6 changes: 4 additions & 2 deletions src/pickers/ProductPicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useState } from "react";

import { TextField } from "@material-ui/core";

import { Autocomplete, useModulesManager, useTranslations } from "@openimis/fe-core";
import { useProductsQuery } from "../hooks";

Expand Down Expand Up @@ -47,8 +49,8 @@ const ProductPicker = (props) => {
<TextField
{...inputProps}
required={required}
label={withLabel && (label || nullLabel)}
placeholder={withPlaceholder && (placeholder || formatMessage("Search..."))}
label={(withLabel && (label || nullLabel)) || formatMessage("Product")}
placeholder={(withPlaceholder && placeholder) || formatMessage("ProductPicker.placeholder")}
/>
)}
/>
Expand Down

0 comments on commit 273d933

Please sign in to comment.