Skip to content

Commit

Permalink
fix: multi select logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwan Rimorin John Eric authored and Kwan Rimorin John Eric committed Oct 2, 2023
1 parent 80b29f0 commit cf6d26a
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 35 deletions.
8 changes: 2 additions & 6 deletions src/components/form/household.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ const HouseholdField = ({
DEFAULT_MULTPLE_OPTION_DELIMITER
);
if (hasExistingMultipleValues) {
return [
true,
changeValue?.split(DEFAULT_MULTPLE_OPTION_DELIMITER).map((value) => {
return options.find((option) => option.value === value);
})
];
// if there are existing multiple values after switching from multiselect to single select, clear the value in the dropdown
return [isMultiselect, []];
}

return [
Expand Down
1 change: 0 additions & 1 deletion src/components/table/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ const AdminTable = ({
status={detailsElement.status}
nhcount={detailsElement.nhcount}
defaultOption={policy?.defaultType}
optionMultiSelect={policy?.isMultiselect}
/>
</td>
))}
Expand Down
1 change: 0 additions & 1 deletion src/components/table/privatetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const PrivateTerritoryTable = ({
status={element.status}
nhcount={element.nhcount}
defaultOption={hhpolicy?.defaultType}
optionMultiSelect={hhpolicy?.isMultiselect}
/>
</div>
</Card.Body>
Expand Down
1 change: 0 additions & 1 deletion src/components/table/publictable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const PublicTerritoryTable = ({
status={element.status}
nhcount={element.nhcount}
defaultOption={hhPolicy?.defaultType}
optionMultiSelect={hhPolicy?.isMultiselect}
/>
</td>
))}
Expand Down
27 changes: 3 additions & 24 deletions src/components/table/unit.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { memo } from "react";
import { Badge } from "react-bootstrap";
import {
DEFAULT_CONGREGATION_OPTION_IS_MULTIPLE,
DEFAULT_MULTPLE_OPTION_DELIMITER,
STATUS_CODES
} from "../../utils/constants";
import { STATUS_CODES } from "../../utils/constants";
import { unitProps } from "../../utils/interface";
import NotHomeIcon from "./nothome";

Expand All @@ -14,8 +10,6 @@ const UnitStatus = memo((props: unitProps) => {
const currentStatus = props.status;
const nhcount = props.nhcount;
const defaultOption = props.defaultOption || "";
const isMultiSelect =
props.optionMultiSelect || DEFAULT_CONGREGATION_OPTION_IS_MULTIPLE;
let status = "";

if (currentStatus === STATUS_CODES.INVALID) {
Expand All @@ -29,22 +23,7 @@ const UnitStatus = memo((props: unitProps) => {
status = "🚫 ";
}

const getHouseholdBadge = (
householdType: string,
isMultiSelect: boolean,
defaultOption: string
) => {
if (isMultiSelect) {
const multHouseholdTypes = householdType
.split(DEFAULT_MULTPLE_OPTION_DELIMITER)
.filter((type) => type !== defaultOption)
.join(DEFAULT_MULTPLE_OPTION_DELIMITER);
return (
<Badge bg="secondary" className="me-1" pill>
{multHouseholdTypes}
</Badge>
);
}
const getHouseholdBadge = (householdType: string, defaultOption: string) => {
if (householdType === defaultOption) {
return <></>;
}
Expand All @@ -62,7 +41,7 @@ const UnitStatus = memo((props: unitProps) => {
<NotHomeIcon nhcount={nhcount} classProp={"me-1"} />
)}
{note && <>🗒️ </>}
{getHouseholdBadge(householdType, isMultiSelect, defaultOption)}
{getHouseholdBadge(householdType, defaultOption)}
</>
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const FIREBASE_FUNCTION_TIMEOUT = 3000;
const DEFAULT_CONGREGATION_MAX_TRIES = 2;

const DEFAULT_CONGREGATION_OPTION_IS_MULTIPLE = false;
const DEFAULT_MULTPLE_OPTION_DELIMITER = ",";
const DEFAULT_MULTPLE_OPTION_DELIMITER = ", ";

const COUNTABLE_HOUSEHOLD_STATUS = [
STATUS_CODES.DONE,
Expand Down
1 change: 0 additions & 1 deletion src/utils/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export interface unitProps {
status: string;
nhcount?: string;
defaultOption?: string;
optionMultiSelect?: boolean;
}

export interface valuesDetails {
Expand Down

0 comments on commit cf6d26a

Please sign in to comment.