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, ViewCreateEditForm, ViewAppliedFiltersRoot, ViewLayoutRoot } from "."; // ui import { Spinner } from "@plane/ui"; // constants import { VIEW_TYPES, viewLocalPayload } 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 [currentCreateEditViewId, setCurrentCreateEditViewId] = useState(undefined); 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( () => ({ setName: (name: string) => viewDetailStore?.setName(name), setDescription: (name: string) => viewDetailStore?.setDescription(name), setFilters: (filters: Partial) => viewDetailStore?.setFilters(filters), setDisplayFilters: (display_filters: Partial) => viewDetailStore?.setDisplayFilters(display_filters), setDisplayProperties: (display_properties: Partial) => viewDetailStore?.setDisplayProperties(display_properties), localViewCreateEdit: (viewId: string | undefined) => { if (viewId === undefined) { const viewPayload = viewLocalPayload; setCurrentCreateEditViewId(viewPayload.id); viewStore?.localViewCreate(viewPayload as TView); } else setCurrentCreateEditViewId(viewId); }, localViewCreateEditClear: async (viewId: string | undefined) => { console.log("viewId", viewId); if (viewId) viewStore?.remove(viewId); setCurrentCreateEditViewId(undefined); }, fetch: async () => await viewStore?.fetch(), create: async (data: Partial) => { try { await viewStore?.create(data); setCurrentCreateEditViewId(undefined); } catch { setToastAlert({ title: "Error", message: "Error creating view", type: "error" }); } }, update: async () => { try { await viewDetailStore?.saveChanges(); setCurrentCreateEditViewId(undefined); } catch { setToastAlert({ title: "Error", message: "Error creating view", type: "error" }); } }, remove: async (viewId: string) => { try { await viewStore?.remove(viewId); } 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
)} */}
)} {currentCreateEditViewId != undefined && ( )}
); });