Skip to content

Commit

Permalink
Finishfeature/OP-835
Browse files Browse the repository at this point in the history
OP-835: Select all for pricelist added
  • Loading branch information
dragos-dobre authored Sep 22, 2022
2 parents cbb323e + a9a55e4 commit b4a53a2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/components/PricelistDetailsPanel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState, useEffect } from "react";
import { withTheme, withStyles } from "@material-ui/core/styles";
import { Table, withModulesManager, combine, useTranslations, ErrorBoundary } from "@openimis/fe-core";
import { Paper, Grid, Typography, Checkbox, Button } from "@material-ui/core";
import { Table, withModulesManager, combine, useTranslations, ErrorBoundary, formatMessage } from "@openimis/fe-core";
import { IconButton } from "@material-ui/core";
import { Paper, Grid, Typography, Checkbox, Button, useStyles, Box } from "@material-ui/core";
import PriceOverruleDialog from "./PriceOverruleDialog";
import SelectAllButton from "./PricelistSelectAllButton"

const styles = (theme) => ({
paper: theme.paper.paper,
Expand Down Expand Up @@ -45,6 +47,13 @@ const PricelistDetailsPanel = (props) => {
const { formatMessage } = useTranslations("medical_pricelist", modulesManager);
const [pagination, setPagination] = useState({ page: 0, afterCursor: null, beforeCursor: null });
const [editedDetail, setEditedDetail] = useState(null);

const ButtonHeader = (_) => {
return SelectAllButton(details, props, edited, onEditedChanged, edited)
}

HEADERS[0] = ButtonHeader

useEffect(() => {
const filters = [];
if (pagination.afterCursor) {
Expand Down
54 changes: 54 additions & 0 deletions src/components/PricelistSelectAllButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useState, useEffect } from "react";
import { withTheme, withStyles } from "@material-ui/core/styles";
import { Table, withModulesManager, combine, useTranslations, ErrorBoundary, formatMessage } from "@openimis/fe-core";
import { IconButton } from "@material-ui/core";
import { Paper, Grid, Typography, Checkbox, Button, useStyles, Box } from "@material-ui/core";
import PriceOverruleDialog from "./PriceOverruleDialog";

export function SelectAllButton (details, props, edited, onEditedChanged) {
const {
modulesManager,
} = props;
const { formatMessage } = useTranslations("medical_pricelist", modulesManager);

const page_details_uuids = details.items ? details.items.map(d => d.uuid) : []
const current_added_details = edited.addedDetails? edited.addedDetails : []
const areNotAllSelected = !current_added_details.includes(...page_details_uuids)
const current_removed_details = edited.removedDetails? edited.removedDetails : []


if (areNotAllSelected) {
page_details_uuids.push(...current_removed_details)
} else {
page_details_uuids.push(...current_added_details)
}

const new_details_uuids = [...new Set(page_details_uuids)]
//details.items.length > (!!edited.addedDetails? edited.addedDetails.length : 0)

const selectAllEdited = () => {
try {
const addedDetails = areNotAllSelected ? new_details_uuids : current_removed_details;
const removedDetails = areNotAllSelected ? current_removed_details : new_details_uuids;
onEditedChanged({
...edited,
addedDetails,
removedDetails
})
} catch (error) {
console.error(error);
}
}

return (
<Box flexGrow={1}>
<Box display="flex" justifyContent="flex-end">
<Button onClick={() => selectAllEdited()} color="primary" disabled={props.readOnly} fullWidth>
{areNotAllSelected ? formatMessage("medical_pricelist.table.selectAll") : formatMessage("medical_pricelist.table.unselectAll")}
</Button>
</Box>
</Box>
);
}

export default SelectAllButton;
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@
"medical_pricelist.updatePricelist.mutationLabel": "Pricelist updated - {name}",
"medical_pricelist.deletePricelist.mutationLabel": "Pricelist deleted - {name}",
"medical_pricelist.deletePricelistDialog.title": "Delete pricelist",
"medical_pricelist.deletePricelistDialog.message": "Are you sure you want to delete the pricelist {name}?"
"medical_pricelist.deletePricelistDialog.message": "Are you sure you want to delete the pricelist {name}?",
"medical_pricelist.table.selectAll": "Select All",
"medical_pricelist.table.unselectAll": "Unselect All"
}

0 comments on commit b4a53a2

Please sign in to comment.