import { FC, useEffect, useMemo, useState } from "react"; import { observer } from "mobx-react-lite"; import { CheckCircle } from "lucide-react"; // hooks import { useView, useViewDetail } from "hooks/store"; import useToast from "hooks/use-toast"; // components import { ViewRoot, ViewCreateEdit, ViewFiltersRoot, ViewAppliedFiltersRoot, ViewLayoutRoot } from "."; // ui import { Spinner } from "@plane/ui"; // constants import { VIEW_TYPES } from "constants/view"; // types import { TViewOperations } from "./types"; import { TView, TViewFilters, TViewDisplayFilters, TViewDisplayProperties } from "@plane/types"; type TAllIssuesViewRoot = { workspaceSlug: string; projectId: string | undefined; viewId: string; }; export const AllIssuesViewRoot: FC = observer((props) => { const { workspaceSlug, projectId, viewId } = props; // states const [viewType, setViewType] = useState(VIEW_TYPES.WORKSPACE_VIEWS); const workspaceViewTabOptions = [ { key: VIEW_TYPES.WORKSPACE_YOUR_VIEWS, title: "Your views", onClick: () => VIEW_TYPES.WORKSPACE_YOUR_VIEWS != viewType && setViewType(VIEW_TYPES.WORKSPACE_YOUR_VIEWS), }, { key: VIEW_TYPES.WORKSPACE_VIEWS, title: "Workspace Views", onClick: () => VIEW_TYPES.WORKSPACE_VIEWS != viewType && setViewType(VIEW_TYPES.WORKSPACE_VIEWS), }, ]; // hooks const viewStore = useView(workspaceSlug, projectId, viewType); const viewDetailStore = useViewDetail(workspaceSlug, projectId, viewId, viewType); const { setToastAlert } = useToast(); const viewOperations: TViewOperations = useMemo( () => ({ localViewCreate: (data) => viewStore?.localViewCreate(data), clearLocalView: (viewId: string) => viewStore?.clearLocalView(viewId), setFilters: (filters: Partial) => viewDetailStore?.setFilters(filters), setDisplayFilters: (display_filters: Partial) => viewDetailStore?.setDisplayFilters(display_filters), setDisplayProperties: (display_properties: Partial) => viewDetailStore?.setDisplayProperties(display_properties), fetch: async () => await viewStore?.fetch(), create: async (data: Partial) => { try { await viewStore?.create(data); if (data.id) viewOperations.clearLocalView(data.id); } catch { setToastAlert({ title: "Error", message: "Error creating view", type: "error" }); } }, }), [viewStore, viewDetailStore, setToastAlert] ); useEffect(() => { if (workspaceSlug && viewId && viewType && viewStore) viewStore?.fetch(viewStore?.viewIds.length > 0 ? "mutation-loader" : "init-loader"); }, [workspaceSlug, viewId, viewType, viewStore]); return (
All Issues
{workspaceViewTabOptions.map((tab) => (
{tab.title}
))}
{viewStore?.loader && viewStore?.loader === "init-loader" ? (
) : ( <> {/* */}
Filters
Display Filters
{!viewDetailStore?.is_local_view && (
Edit
)}
)}
); });