Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CM-453: Create the UI component for field selection for deduplication. #3

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
Loading