chore: set sub group by to null if group by and sub group by are same (#2621)

This commit is contained in:
Aaryan Khandelwal 2023-11-03 13:15:50 +05:30 committed by GitHub
parent 7a11161cd0
commit c66d76df26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 15 deletions

View File

@ -47,8 +47,7 @@ export const DisplayFiltersSelection: React.FC<Props> = observer((props) => {
{isDisplayFilterEnabled("group_by") && ( {isDisplayFilterEnabled("group_by") && (
<div className="py-2"> <div className="py-2">
<FilterGroupBy <FilterGroupBy
selectedGroupBy={displayFilters.group_by} displayFilters={displayFilters}
selectedSubGroupBy={displayFilters.sub_group_by}
groupByOptions={layoutDisplayFiltersOptions?.display_filters.group_by ?? []} groupByOptions={layoutDisplayFiltersOptions?.display_filters.group_by ?? []}
handleUpdate={(val) => handleUpdate={(val) =>
handleDisplayFiltersUpdate({ handleDisplayFiltersUpdate({
@ -65,8 +64,7 @@ export const DisplayFiltersSelection: React.FC<Props> = observer((props) => {
displayFilters.layout === "kanban" && ( displayFilters.layout === "kanban" && (
<div className="py-2"> <div className="py-2">
<FilterSubGroupBy <FilterSubGroupBy
selectedGroupBy={displayFilters.group_by} displayFilters={displayFilters}
selectedSubGroupBy={displayFilters.sub_group_by}
handleUpdate={(val) => handleUpdate={(val) =>
handleDisplayFiltersUpdate({ handleDisplayFiltersUpdate({
sub_group_by: val, sub_group_by: val,

View File

@ -4,23 +4,23 @@ import { observer } from "mobx-react-lite";
// components // components
import { FilterHeader, FilterOption } from "components/issues"; import { FilterHeader, FilterOption } from "components/issues";
// types // types
import { TIssueGroupByOptions } from "types"; import { IIssueDisplayFilterOptions, TIssueGroupByOptions } from "types";
// constants // constants
import { ISSUE_GROUP_BY_OPTIONS } from "constants/issue"; import { ISSUE_GROUP_BY_OPTIONS } from "constants/issue";
type Props = { type Props = {
selectedGroupBy: TIssueGroupByOptions | undefined; displayFilters: IIssueDisplayFilterOptions;
selectedSubGroupBy: TIssueGroupByOptions | undefined;
groupByOptions: TIssueGroupByOptions[]; groupByOptions: TIssueGroupByOptions[];
handleUpdate: (val: TIssueGroupByOptions) => void; handleUpdate: (val: TIssueGroupByOptions) => void;
}; };
export const FilterGroupBy: React.FC<Props> = observer((props) => { export const FilterGroupBy: React.FC<Props> = observer((props) => {
const { selectedGroupBy, selectedSubGroupBy, groupByOptions, handleUpdate } = props; const { displayFilters, groupByOptions, handleUpdate } = props;
const [previewEnabled, setPreviewEnabled] = useState(true); const [previewEnabled, setPreviewEnabled] = useState(true);
const activeGroupBy = selectedGroupBy ?? null; const selectedGroupBy = displayFilters.group_by ?? null;
const selectedSubGroupBy = displayFilters.sub_group_by ?? null;
return ( return (
<> <>
@ -32,12 +32,13 @@ export const FilterGroupBy: React.FC<Props> = observer((props) => {
{previewEnabled && ( {previewEnabled && (
<div> <div>
{ISSUE_GROUP_BY_OPTIONS.filter((option) => groupByOptions.includes(option.key)).map((groupBy) => { {ISSUE_GROUP_BY_OPTIONS.filter((option) => groupByOptions.includes(option.key)).map((groupBy) => {
if (selectedSubGroupBy !== null && groupBy.key === selectedSubGroupBy) return null; if (displayFilters.layout === "kanban" && selectedSubGroupBy !== null && groupBy.key === selectedSubGroupBy)
return null;
return ( return (
<FilterOption <FilterOption
key={groupBy?.key} key={groupBy?.key}
isChecked={activeGroupBy === groupBy?.key ? true : false} isChecked={selectedGroupBy === groupBy?.key ? true : false}
onClick={() => handleUpdate(groupBy.key)} onClick={() => handleUpdate(groupBy.key)}
title={groupBy.title} title={groupBy.title}
multiple={false} multiple={false}

View File

@ -4,22 +4,24 @@ import { observer } from "mobx-react-lite";
// components // components
import { FilterHeader, FilterOption } from "components/issues"; import { FilterHeader, FilterOption } from "components/issues";
// types // types
import { TIssueGroupByOptions } from "types"; import { IIssueDisplayFilterOptions, TIssueGroupByOptions } from "types";
// constants // constants
import { ISSUE_GROUP_BY_OPTIONS } from "constants/issue"; import { ISSUE_GROUP_BY_OPTIONS } from "constants/issue";
type Props = { type Props = {
selectedGroupBy: TIssueGroupByOptions | undefined; displayFilters: IIssueDisplayFilterOptions;
selectedSubGroupBy: TIssueGroupByOptions | undefined;
handleUpdate: (val: TIssueGroupByOptions) => void; handleUpdate: (val: TIssueGroupByOptions) => void;
subGroupByOptions: TIssueGroupByOptions[]; subGroupByOptions: TIssueGroupByOptions[];
}; };
export const FilterSubGroupBy: React.FC<Props> = observer((props) => { export const FilterSubGroupBy: React.FC<Props> = observer((props) => {
const { selectedGroupBy, selectedSubGroupBy, handleUpdate, subGroupByOptions } = props; const { displayFilters, handleUpdate, subGroupByOptions } = props;
const [previewEnabled, setPreviewEnabled] = useState(true); const [previewEnabled, setPreviewEnabled] = useState(true);
const selectedGroupBy = displayFilters.group_by ?? null;
const selectedSubGroupBy = displayFilters.sub_group_by ?? null;
return ( return (
<> <>
<FilterHeader <FilterHeader

View File

@ -186,6 +186,13 @@ export class IssueFilterStore implements IIssueFilterStore {
// set sub_group_by to null if group_by is set to null // set sub_group_by to null if group_by is set to null
if (newViewProps.display_filters.group_by === null) newViewProps.display_filters.sub_group_by = null; if (newViewProps.display_filters.group_by === null) newViewProps.display_filters.sub_group_by = null;
// set sub_group_by to null if layout is switched to kanban group_by and sub_group_by are same
if (
newViewProps.display_filters.layout === "kanban" &&
newViewProps.display_filters.group_by === newViewProps.display_filters.sub_group_by
)
newViewProps.display_filters.sub_group_by = null;
// set group_by to state if layout is switched to kanban and group_by is null // set group_by to state if layout is switched to kanban and group_by is null
if (newViewProps.display_filters.layout === "kanban" && newViewProps.display_filters.group_by === null) if (newViewProps.display_filters.layout === "kanban" && newViewProps.display_filters.group_by === null)
newViewProps.display_filters.group_by = "state"; newViewProps.display_filters.group_by = "state";