Skip to content

Commit

Permalink
Merge pull request #3 from openimis/feature/CM-453
Browse files Browse the repository at this point in the history
CM-453: Create the UI component for field selection for deduplication.
  • Loading branch information
jdolkowski authored Jan 12, 2024
2 parents 954db03 + 5396b7d commit aab332c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/components/dialogs/DeduplicationFieldSelectionDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { withTheme, withStyles } from '@material-ui/core/styles';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import DeduplicationFieldPicker from '../pickers/DeduplicationFieldPicker';

const styles = (theme) => ({
item: theme.paper.item,
Expand All @@ -24,6 +25,7 @@ function DeduplicationFieldSelectionDialog({
}) {
if (!benefitPlan) return null;

const [selectedValues, setSelectedValues] = useState([]);
const [isOpen, setIsOpen] = useState(false);

const handleOpen = () => {
Expand All @@ -34,6 +36,10 @@ function DeduplicationFieldSelectionDialog({
setIsOpen(false);
};

const handlePickerChange = (selectedOptions) => {
setSelectedValues(selectedOptions);
};

return (
<>
<Button
Expand Down Expand Up @@ -65,7 +71,15 @@ function DeduplicationFieldSelectionDialog({
>
{formatMessageWithValues(intl, 'deduplication', 'deduplicate.title', { benefitPlanName: benefitPlan.name })}
</DialogTitle>
<DialogContent />
<DialogContent>
<DeduplicationFieldPicker
required
value={selectedValues}
module="deduplication"
benefitPlan={benefitPlan}
onChange={handlePickerChange}
/>
</DialogContent>
<DialogActions
style={{
display: 'inline',
Expand All @@ -75,7 +89,16 @@ function DeduplicationFieldSelectionDialog({
}}
>
<div>
<div style={{ float: 'left' }} />
<div style={{ float: 'left' }}>
<Button
onClick={() => []}
variant="outlined"
autoFocus
style={{ margin: '0 16px' }}
>
{formatMessage(intl, 'deduplication', 'deduplicate.button.showDuplicateSummary')}
</Button>
</div>
<div style={{
float: 'right',
paddingRight: '16px',
Expand Down
49 changes: 49 additions & 0 deletions src/components/pickers/DeduplicationFieldPicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { useState } from 'react';
import { useTranslations, Autocomplete } from '@openimis/fe-core';
import { BASIC_FIELDS } from '../../constants';

function DeduplicationFieldPicker({
readOnly,
benefitPlan,
value,
onChange,
required,
multiple = true,
placeholder,
withLabel,
withPlaceholder,
label,
filterOptions,
filterSelectedOptions,
}) {
const [searchString, setSearchString] = useState();
const { formatMessage } = useTranslations('deduplication');

const beneficiaryDataSchema = JSON.parse(benefitPlan?.beneficiaryDataSchema);
const schemaFields = Object.keys(beneficiaryDataSchema?.properties ?? {});
const schemaFieldsList = schemaFields.map((key) => ({ id: key, name: key }));
const possibleFields = [...schemaFieldsList, ...BASIC_FIELDS];

return (
<Autocomplete
multiple={multiple}
required={required}
placeholder={placeholder ?? formatMessage('deduplication.deduplicate.fields.placeholder')}
label={label ?? formatMessage('deduplication.deduplicate.fields')}
error={[]}
withLabel={withLabel}
withPlaceholder={withPlaceholder}
readOnly={readOnly}
options={possibleFields}
isLoading={false}
value={value}
getOptionLabel={(o) => o?.name}
onChange={(option) => onChange(option, option?.name)}
filterOptions={filterOptions}
filterSelectedOptions={filterSelectedOptions}
onInputChange={() => setSearchString(searchString)}
/>
);
}

export default DeduplicationFieldPicker;
6 changes: 6 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const BASIC_FIELDS = [
{ id: 'first_name', name: 'first_name' },
{ id: 'last_name', name: 'last_name' },
{ id: 'dob', name: 'dob' },
];
export const MODULE_NAME = 'Deduplication';
5 changes: 4 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"deduplication.deduplicate": "Deduplicate",
"deduplication.deduplicate.title": "Deduplication - {benefitPlanName}",
"deduplication.deduplicate.button.cancel": "Cancel"
"deduplication.deduplicate.button.cancel": "Cancel",
"deduplication.deduplicate.fields": "Duplicate Detection Field Selection",
"deduplication.deduplicate.fields.placeholder": "Duplicate Detection Field Selection",
"deduplicate.button.showDuplicateSummary": "Show Duplicate Summary"
}

0 comments on commit aab332c

Please sign in to comment.