Skip to content

Commit

Permalink
feat: Make group-by functionality in SortPopover optional
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaZeta committed Jul 11, 2022
1 parent 9a4c0a8 commit dfbc34f
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/sort/SortPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ interface Props {
filters: Filters;
updateData: (func: (data: FilterData) => FilterData) => void;
getLabelsFromKeys: (acc: DataKeyLabel[], key: string) => DataKeyLabel[];
showGroupBy?: boolean;
}

export const SortPopover = ({
data,
filters,
updateData,
getLabelsFromKeys,
showGroupBy,
}: Props): ReactElement => {
const [inputKey, setInputKey] = useState<DataKeyLabel>({
key: "",
Expand Down Expand Up @@ -131,19 +133,21 @@ export const SortPopover = ({
/>
</RadioGroup>
</FormControl>
<FormControlLabel
control={
<Checkbox
checked={isGrouped}
onChange={() => {
filters.toggleIsGrouped();
setIsGrouped((value) => !value);
}}
name="group-by"
/>
}
label="Group by value"
/>
{showGroupBy && (
<FormControlLabel
control={
<Checkbox
checked={isGrouped}
onChange={() => {
filters.toggleIsGrouped();
setIsGrouped((value) => !value);
}}
name="group-by"
/>
}
label="Group by value"
/>
)}
</>
)}
</Paper>
Expand All @@ -160,7 +164,9 @@ export const SortPopover = ({
sortOrder === "asc"
);

newMetadata = filters.groupByValue(newMetadata || metadata);
if (showGroupBy) {
newMetadata = filters.groupByValue(newMetadata || metadata);
}

return newMetadata;
});
Expand All @@ -171,3 +177,7 @@ export const SortPopover = ({
</Popover>
);
};

SortPopover.defaultProps = {
showGroupBy: true,
};

0 comments on commit dfbc34f

Please sign in to comment.