import React, { useState, useRef } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; import useSWR from "swr"; // hooks import useUserAuth from "hooks/use-user-auth"; // services import { ProjectService } from "services/project"; import { IssueLabelService } from "services/issue"; // layouts import { ProjectAuthorizationWrapper } from "layouts/auth-layout-legacy"; // components import { CreateUpdateLabelInline, DeleteLabelModal, LabelsListModal, SingleLabel, SingleLabelGroup, } from "components/labels"; import { SettingsSidebar } from "components/project"; // ui import { BreadcrumbItem, Breadcrumbs, Button, Loader } from "@plane/ui"; import { EmptyState } from "components/common"; // images import emptyLabel from "public/empty-state/label.svg"; // types import { IIssueLabels } from "types"; import type { NextPage } from "next"; // fetch-keys import { PROJECT_DETAILS, PROJECT_ISSUE_LABELS } from "constants/fetch-keys"; // helper import { truncateText } from "helpers/string.helper"; // services const projectService = new ProjectService(); const issueLabelService = new IssueLabelService(); const LabelsSettings: NextPage = () => { // create/edit label form const [labelForm, setLabelForm] = useState(false); // edit label const [isUpdating, setIsUpdating] = useState(false); const [labelToUpdate, setLabelToUpdate] = useState(null); // labels list modal const [labelsListModal, setLabelsListModal] = useState(false); const [parentLabel, setParentLabel] = useState(undefined); // delete label const [selectDeleteLabel, setSelectDeleteLabel] = useState(null); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { user } = useUserAuth(); const scrollToRef = useRef(null); const { data: projectDetails } = useSWR( workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null, workspaceSlug && projectId ? () => projectService.getProject(workspaceSlug as string, projectId as string) : null ); const { data: issueLabels } = useSWR( workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null, workspaceSlug && projectId ? () => issueLabelService.getProjectIssueLabels(workspaceSlug as string, projectId as string) : null ); const newLabel = () => { setIsUpdating(false); setLabelForm(true); }; const addLabelToGroup = (parentLabel: IIssueLabels) => { setLabelsListModal(true); setParentLabel(parentLabel); }; const editLabel = (label: IIssueLabels) => { setLabelForm(true); setIsUpdating(true); setLabelToUpdate(label); }; return ( <> setLabelsListModal(false)} parent={parentLabel} user={user} /> setSelectDeleteLabel(null)} user={user} /> router.back()}>

{`${truncateText(projectDetails?.name ?? "Project", 32)}`}

} /> } >

Labels

{labelForm && ( { setLabelForm(false); setIsUpdating(false); setLabelToUpdate(null); }} ref={scrollToRef} /> )} <> {issueLabels ? ( issueLabels.length > 0 ? ( issueLabels.map((label) => { const children = issueLabels?.filter((l) => l.parent === label.id); if (children && children.length === 0) { if (!label.parent) return ( addLabelToGroup(label)} editLabel={(label) => { editLabel(label); scrollToRef.current?.scrollIntoView({ behavior: "smooth", }); }} handleLabelDelete={() => setSelectDeleteLabel(label)} /> ); } else return ( { editLabel(label); scrollToRef.current?.scrollIntoView({ behavior: "smooth", }); }} handleLabelDelete={() => setSelectDeleteLabel(label)} user={user} /> ); }) ) : ( newLabel(), }} isFullScreen={false} /> ) ) : ( )}
); }; export default LabelsSettings;