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

[WEB-1442] feat: Save all filters and properties for views #4728

Merged
merged 1 commit into from
Jun 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { EUserProjectRoles } from "@/constants/project";
// helpers
import { replaceUnderscoreIfSnakeCase } from "@/helpers/string.helper";
// hooks
import { useAppRouter, useUser } from "@/hooks/store";
import { useUser } from "@/hooks/store";

type Props = {
appliedFilters: IIssueFilterOptions;
Expand All @@ -36,7 +36,6 @@ const dateFilters = ["start_date", "target_date"];
export const AppliedFiltersList: React.FC<Props> = observer((props) => {
const { appliedFilters, handleClearAllFilters, handleRemoveFilter, labels, states, alwaysAllowEditing } = props;
// store hooks
const { moduleId, cycleId } = useAppRouter();
const {
membership: { currentProjectRole },
} = useUser();
Expand Down Expand Up @@ -108,14 +107,14 @@ export const AppliedFiltersList: React.FC<Props> = observer((props) => {
values={value}
/>
)}
{filterKey === "cycle" && !cycleId && (
{filterKey === "cycle" && (
<AppliedCycleFilters
editable={isEditingAllowed}
handleRemove={(val) => handleRemoveFilter("cycle", val)}
values={value}
/>
)}
{filterKey === "module" && !moduleId && (
{filterKey === "module" && (
<AppliedModuleFilters
editable={isEditingAllowed}
handleRemove={(val) => handleRemoveFilter("module", val)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { observer } from "mobx-react";
import { useRouter } from "next/router";
import { IIssueFilterOptions } from "@plane/types";
// hooks
import { AppliedFiltersList, SaveFilterView } from "@/components/issues";
import { AppliedFiltersList } from "@/components/issues";
import { EIssueFilterType, EIssuesStoreType } from "@/constants/issue";
import { useIssues, useLabel, useProjectState } from "@/hooks/store";
// components
Expand Down Expand Up @@ -76,8 +76,6 @@ export const ArchivedIssueAppliedFiltersRoot: React.FC = observer(() => {
labels={projectLabels ?? []}
states={projectStates}
/>

<SaveFilterView workspaceSlug={workspaceSlug} projectId={projectId} filterParams={appliedFilters} />
</div>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const CycleAppliedFiltersRoot: React.FC = observer(() => {
};

// return if no filters are applied
if (Object.keys(appliedFilters).length === 0 || !workspaceSlug || !projectId) return null;
if (Object.keys(appliedFilters).length === 0 || !workspaceSlug || !projectId || !cycleId) return null;

return (
<div className="flex justify-between p-4 gap-2.5">
Expand All @@ -89,7 +89,11 @@ export const CycleAppliedFiltersRoot: React.FC = observer(() => {
<SaveFilterView
workspaceSlug={workspaceSlug.toString()}
projectId={projectId.toString()}
filterParams={appliedFilters}
filterParams={{
filters: { ...appliedFilters, cycle: [cycleId?.toString()] },
display_filters: issueFilters?.displayFilters,
display_properties: issueFilters?.displayProperties,
}}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { observer } from "mobx-react";
import { useRouter } from "next/router";
import { IIssueFilterOptions } from "@plane/types";
// hooks
import { AppliedFiltersList, SaveFilterView } from "@/components/issues";
import { AppliedFiltersList } from "@/components/issues";
import { EIssueFilterType, EIssuesStoreType } from "@/constants/issue";
import { useIssues, useLabel, useProjectState } from "@/hooks/store";
// components
Expand Down Expand Up @@ -71,8 +71,6 @@ export const DraftIssueAppliedFiltersRoot: React.FC = observer(() => {
labels={projectLabels ?? []}
states={projectStates}
/>

<SaveFilterView workspaceSlug={workspaceSlug} projectId={projectId} filterParams={appliedFilters} />
</div>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const ModuleAppliedFiltersRoot: React.FC = observer(() => {
};

// return if no filters are applied
if (!workspaceSlug || !projectId || Object.keys(appliedFilters).length === 0) return null;
if (!workspaceSlug || !projectId || !moduleId || Object.keys(appliedFilters).length === 0) return null;

return (
<div className="flex justify-between p-4 gap-2.5">
Expand All @@ -88,7 +88,11 @@ export const ModuleAppliedFiltersRoot: React.FC = observer(() => {
<SaveFilterView
workspaceSlug={workspaceSlug.toString()}
projectId={projectId.toString()}
filterParams={appliedFilters}
filterParams={{
filters: { ...appliedFilters, module: [moduleId.toString()] },
display_filters: issueFilters?.displayFilters,
display_properties: issueFilters?.displayProperties,
}}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ export const ProjectAppliedFiltersRoot: React.FC = observer(() => {
states={projectStates}
/>
{isEditingAllowed && (
<SaveFilterView workspaceSlug={workspaceSlug} projectId={projectId} filterParams={appliedFilters} />
<SaveFilterView
workspaceSlug={workspaceSlug}
projectId={projectId}
filterParams={{
filters: appliedFilters,
display_filters: issueFilters?.displayFilters,
display_properties: issueFilters?.displayProperties,
}}
/>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isEmpty from "lodash/isEmpty";
import isEqual from "lodash/isEqual";
import { observer } from "mobx-react";
import { useRouter } from "next/router";
import { IIssueFilterOptions } from "@plane/types";
Expand All @@ -8,6 +7,7 @@ import { Button } from "@plane/ui";
import { AppliedFiltersList } from "@/components/issues";
import { EIssueFilterType, EIssuesStoreType } from "@/constants/issue";
import { useIssues, useLabel, useProjectState, useProjectView } from "@/hooks/store";
import { getAreFiltersEqual } from "../../../utils";
// components
// ui
// types
Expand Down Expand Up @@ -79,7 +79,7 @@ export const ProjectViewAppliedFiltersRoot: React.FC = observer(() => {
);
};

const areFiltersEqual = isEqual(appliedFilters ?? {}, viewDetails?.filters ?? {});
const areFiltersEqual = getAreFiltersEqual(appliedFilters, issueFilters, viewDetails);

// return if no filters are applied
if (isEmpty(appliedFilters) && areFiltersEqual) return null;
Expand All @@ -91,6 +91,12 @@ export const ProjectViewAppliedFiltersRoot: React.FC = observer(() => {
filters: {
...(appliedFilters ?? {}),
},
display_filters: {
pushya22 marked this conversation as resolved.
Show resolved Hide resolved
...issueFilters?.displayFilters,
},
display_properties: {
...issueFilters?.displayProperties,
},
});
};

Expand Down
9 changes: 7 additions & 2 deletions web/components/issues/issue-layouts/save-filter-view.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { FC, useState } from "react";
import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions } from "@plane/types";
import { Button } from "@plane/ui";
// components
import { CreateUpdateProjectViewModal } from "@/components/views";

interface ISaveFilterView {
workspaceSlug: string;
projectId: string;
filterParams: any;
filterParams: {
filters: IIssueFilterOptions;
display_filters?: IIssueDisplayFilterOptions;
display_properties?: IIssueDisplayProperties;
};
}

export const SaveFilterView: FC<ISaveFilterView> = (props) => {
Expand All @@ -19,7 +24,7 @@ export const SaveFilterView: FC<ISaveFilterView> = (props) => {
<CreateUpdateProjectViewModal
workspaceSlug={workspaceSlug}
projectId={projectId}
preLoadedData={{ filters: { ...filterParams } }}
preLoadedData={{ ...filterParams }}
isOpen={viewModal}
onClose={() => setViewModal(false)}
/>
Expand Down
20 changes: 20 additions & 0 deletions web/components/issues/issue-layouts/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
import clone from "lodash/clone";
import concat from "lodash/concat";
import isEqual from "lodash/isEqual";
import pull from "lodash/pull";
import uniq from "lodash/uniq";
import scrollIntoView from "smooth-scroll-into-view-if-needed";
Expand All @@ -13,6 +14,9 @@ import {
IPragmaticDropPayload,
TIssue,
TIssueGroupByOptions,
IIssueFilterOptions,
IIssueFilters,
IProjectView,
} from "@plane/types";
// ui
import { Avatar, CycleGroupIcon, DiceIcon, PriorityIcon, StateGroupIcon } from "@plane/ui";
Expand Down Expand Up @@ -535,3 +539,19 @@ export const handleGroupDragDrop = async (
return await updateIssueOnDrop(sourceIssue.project_id, sourceIssue.id, updatedIssue, issueUpdates);
}
};

/**
* This Method compares filters and returns a boolean based on which and updateView button is shown
* @param appliedFilters
* @param issueFilters
* @param viewDetails
* @returns
*/
export const getAreFiltersEqual = (
appliedFilters: IIssueFilterOptions | undefined,
issueFilters: IIssueFilters | undefined,
viewDetails: IProjectView | null
) =>
isEqual(appliedFilters ?? {}, viewDetails?.filters ?? {}) &&
isEqual(issueFilters?.displayFilters ?? {}, viewDetails?.display_filters ?? {}) &&
isEqual(issueFilters?.displayProperties ?? {}, viewDetails?.display_properties ?? {});
2 changes: 2 additions & 0 deletions web/components/views/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export const ProjectViewForm: React.FC<Props> = observer((props) => {
description: formData.description,
logo_props: formData.logo_props,
filters: formData.filters,
display_filters: formData.display_filters,
display_properties: formData.display_properties,
} as IProjectView);

reset({
Expand Down
Loading