Skip to content

Commit

Permalink
CM-453: added working selection fields based on programme schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Jan 12, 2024
1 parent 5fb33c9 commit 5396b7d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/components/dialogs/DeduplicationFieldSelectionDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function DeduplicationFieldSelectionDialog({
}) {
if (!benefitPlan) return null;

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

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

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

return (
<>
<Button
Expand Down Expand Up @@ -69,9 +74,10 @@ function DeduplicationFieldSelectionDialog({
<DialogContent>
<DeduplicationFieldPicker
required
value={[]}
value={selectedValues}
module="deduplication"
onChange={() => []}
benefitPlan={benefitPlan}
onChange={handlePickerChange}
/>
</DialogContent>
<DialogActions
Expand Down
24 changes: 11 additions & 13 deletions src/components/pickers/DeduplicationFieldPicker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState } from 'react';
import { useGraphqlQuery, useTranslations, Autocomplete } from '@openimis/fe-core';
import { useTranslations, Autocomplete } from '@openimis/fe-core';
import { BASIC_FIELDS } from '../../constants';

function DeduplicationFieldPicker({
readOnly,
benefitPlan,
value,
onChange,
required,
Expand All @@ -17,28 +19,24 @@ function DeduplicationFieldPicker({
const [searchString, setSearchString] = useState();
const { formatMessage } = useTranslations('deduplication');

const { isLoading, data, error } = useGraphqlQuery(
`
`,
{ str: searchString },
);

const roles = data?.role?.edges.map((edge) => edge.node) ?? [];
const uniqueValues = [...new Map(value?.map((role) => [role.id, role])).values()];
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={error}
error={[]}
withLabel={withLabel}
withPlaceholder={withPlaceholder}
readOnly={readOnly}
options={roles}
isLoading={isLoading}
value={uniqueValues}
options={possibleFields}
isLoading={false}
value={value}
getOptionLabel={(o) => o?.name}
onChange={(option) => onChange(option, option?.name)}
filterOptions={filterOptions}
Expand Down
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';

0 comments on commit 5396b7d

Please sign in to comment.