-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-835: Select all for pricelist added
- Loading branch information
Showing
3 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters