[WEB-1026] chore: clear search query on project change (#4225)

* chore: clear search query on project change

* fix: project query search
This commit is contained in:
Aaryan Khandelwal 2024-04-17 20:32:25 +05:30 committed by GitHub
parent 0c0bdd6969
commit 0d70960e4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 125 additions and 124 deletions

View File

@ -168,15 +168,14 @@ export const CycleQuickActions: React.FC<Props> = observer((props) => {
</span>
</CustomMenu.MenuItem>
)}
<hr className="my-2 border-custom-border-200" />
{!isCompleted && isEditingAllowed && (
<div className="border-t pt-1 mt-1">
<CustomMenu.MenuItem onClick={handleDeleteCycle}>
<span className="flex items-center justify-start gap-2">
<Trash2 className="h-3 w-3" />
<span>Delete cycle</span>
</span>
</CustomMenu.MenuItem>
</div>
)}
</CustomMenu>
</>

View File

@ -13,7 +13,7 @@ import { FiltersDropdown } from "@/components/issues";
import { ProjectFiltersSelection, ProjectOrderByDropdown } from "@/components/project";
import { EUserWorkspaceRoles } from "@/constants/workspace";
import { cn } from "@/helpers/common.helper";
import { useApplication, useEventTracker, useMember, useProject, useProjectFilter, useUser } from "@/hooks/store";
import { useApplication, useEventTracker, useMember, useProjectFilter, useUser } from "@/hooks/store";
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
export const ProjectsHeader = observer(() => {
@ -30,7 +30,6 @@ export const ProjectsHeader = observer(() => {
const {
membership: { currentWorkspaceRole },
} = useUser();
const { workspaceProjectIds } = useProject();
const {
currentWorkspaceDisplayFilters: displayFilters,
currentWorkspaceFilters: filters,
@ -89,7 +88,6 @@ export const ProjectsHeader = observer(() => {
</div>
</div>
<div className="w-full flex items-center justify-end gap-3">
{workspaceProjectIds && workspaceProjectIds?.length > 0 && (
<div className="flex items-center">
{!isSearchOpen && (
<button
@ -114,7 +112,7 @@ export const ProjectsHeader = observer(() => {
<Search className="h-3.5 w-3.5" />
<input
ref={inputRef}
className="w-full max-w-[234px] border-none bg-transparent text-sm text-custom-text-100 focus:outline-none"
className="w-full max-w-[234px] border-none bg-transparent text-sm text-custom-text-100 placeholder:text-custom-text-400 focus:outline-none"
placeholder="Search"
value={searchQuery}
onChange={(e) => updateSearchQuery(e.target.value)}
@ -134,7 +132,6 @@ export const ProjectsHeader = observer(() => {
)}
</div>
</div>
)}
<ProjectOrderByDropdown
value={displayFilters?.order_by}
onChange={(val) => {

View File

@ -42,7 +42,7 @@ export const InboxIssueOrderByDropdown: FC = observer(() => {
{inboxSorting?.order_by?.includes(option.key) && <Check className="h-3 w-3" />}
</CustomMenu.MenuItem>
))}
<hr className="my-2" />
<hr className="my-2 border-custom-border-200" />
{INBOX_ISSUE_SORT_BY_OPTIONS.map((option) => (
<CustomMenu.MenuItem
key={option.key}

View File

@ -46,7 +46,7 @@ export const ModuleOrderByDropdown: React.FC<Props> = (props) => {
{value?.includes(option.key) && <Check className="h-3 w-3" />}
</CustomMenu.MenuItem>
))}
<hr className="my-2" />
<hr className="my-2 border-custom-border-200" />
<CustomMenu.MenuItem
className="flex items-center justify-between gap-2"
onClick={() => {

View File

@ -1,16 +1,13 @@
import { observer } from "mobx-react-lite";
import Image from "next/image";
import { useRouter } from "next/router";
// hooks
// components
import { EmptyState } from "@/components/empty-state";
import { ModuleCardItem, ModuleListItem, ModulePeekOverview, ModulesListGanttChartView } from "@/components/modules";
// ui
import { CycleModuleBoardLayout, CycleModuleListLayout, GanttLayoutLoader } from "@/components/ui";
// assets
// constants
import { EmptyStateType } from "@/constants/empty-state";
import { calculateTotalFilters } from "@/helpers/filter.helper";
// hooks
import { useApplication, useEventTracker, useModule, useModuleFilter } from "@/hooks/store";
import AllFiltersImage from "public/empty-state/module/all-filters.svg";
import NameFilterImage from "public/empty-state/module/name-filter.svg";
@ -22,14 +19,13 @@ export const ModulesListView: React.FC = observer(() => {
// store hooks
const { commandPalette: commandPaletteStore } = useApplication();
const { setTrackElement } = useEventTracker();
const { getFilteredModuleIds, loader } = useModule();
const { currentProjectDisplayFilters: displayFilters, searchQuery, currentProjectFilters } = useModuleFilter();
const { getProjectModuleIds, getFilteredModuleIds, loader } = useModule();
const { currentProjectDisplayFilters: displayFilters, searchQuery } = useModuleFilter();
// derived values
const projectModuleIds = projectId ? getProjectModuleIds(projectId.toString()) : undefined;
const filteredModuleIds = projectId ? getFilteredModuleIds(projectId.toString()) : undefined;
const totalFilters = calculateTotalFilters(currentProjectFilters ?? {});
if (loader || !filteredModuleIds)
if (loader || !projectModuleIds || !filteredModuleIds)
return (
<>
{displayFilters?.layout === "list" && <CycleModuleListLayout />}
@ -38,7 +34,18 @@ export const ModulesListView: React.FC = observer(() => {
</>
);
if (totalFilters > 0 && filteredModuleIds.length === 0)
if (projectModuleIds.length === 0)
return (
<EmptyState
type={EmptyStateType.PROJECT_MODULE}
primaryButtonOnClick={() => {
setTrackElement("Module empty state");
commandPaletteStore.toggleCreateModuleModal(true);
}}
/>
);
if (filteredModuleIds.length === 0)
return (
<div className="h-full w-full grid place-items-center">
<div className="text-center">
@ -58,8 +65,6 @@ export const ModulesListView: React.FC = observer(() => {
);
return (
<>
{filteredModuleIds.length > 0 ? (
<>
{displayFilters?.layout === "list" && (
<div className="h-full overflow-y-auto">
@ -99,15 +104,5 @@ export const ModulesListView: React.FC = observer(() => {
)}
{displayFilters?.layout === "gantt" && <ModulesListGanttChartView />}
</>
) : (
<EmptyState
type={EmptyStateType.PROJECT_MODULE}
primaryButtonOnClick={() => {
setTrackElement("Module empty state");
commandPaletteStore.toggleCreateModuleModal(true);
}}
/>
)}
</>
);
});

View File

@ -163,15 +163,14 @@ export const ModuleQuickActions: React.FC<Props> = observer((props) => {
</span>
</CustomMenu.MenuItem>
)}
<hr className="my-2 border-custom-border-200" />
{isEditingAllowed && (
<div className="border-t pt-1 mt-1">
<CustomMenu.MenuItem onClick={handleDeleteModule}>
<span className="flex items-center justify-start gap-2">
<Trash2 className="h-3 w-3" />
<span>Delete module</span>
</span>
</CustomMenu.MenuItem>
</div>
)}
</CustomMenu>
</>

View File

@ -47,7 +47,7 @@ export const PageOrderByDropdown: React.FC<Props> = (props) => {
{sortKey === option.key && <Check className="h-3 w-3" />}
</CustomMenu.MenuItem>
))}
<hr className="my-2" />
<hr className="my-2 border-custom-border-200" />
<CustomMenu.MenuItem
className="flex items-center justify-between gap-2"
onClick={() => {

View File

@ -49,7 +49,7 @@ export const ProjectOrderByDropdown: React.FC<Props> = (props) => {
{value?.includes(option.key) && <Check className="h-3 w-3" />}
</CustomMenu.MenuItem>
))}
<hr className="my-2" />
<hr className="my-2 border-custom-border-200" />
<CustomMenu.MenuItem
className="flex items-center justify-between gap-2"
onClick={() => {

View File

@ -63,6 +63,7 @@ export class CycleFilterStore implements ICycleFilterStore {
(projectId) => {
if (!projectId) return;
this.initProjectCycleFilters(projectId);
this.searchQuery = "";
}
);
}

View File

@ -63,6 +63,7 @@ export class ModuleFilterStore implements IModuleFilterStore {
(projectId) => {
if (!projectId) return;
this.initProjectModuleFilters(projectId);
this.searchQuery = "";
}
);
}

View File

@ -1,6 +1,6 @@
import set from "lodash/set";
import unset from "lodash/unset";
import { makeObservable, observable, runInAction, action } from "mobx";
import { makeObservable, observable, runInAction, action, reaction } from "mobx";
import { computedFn } from "mobx-utils";
// types
import { TPage, TPageFilters, TPageNavigationTabs } from "@plane/types";
@ -64,8 +64,16 @@ export class ProjectPageStore implements IProjectPageStore {
createPage: action,
removePage: action,
});
// service
this.service = new PageService();
// initialize display filters of the current project
reaction(
() => this.store.app.router.projectId,
(projectId) => {
if (!projectId) return;
this.filters.searchQuery = "";
}
);
}
/**

View File

@ -59,6 +59,7 @@ export class ProjectFilterStore implements IProjectFilterStore {
(workspaceSlug) => {
if (!workspaceSlug) return;
this.initWorkspaceFilters(workspaceSlug);
this.searchQuery = "";
}
);
}