forked from github/plane
efd3ebf067
* refactor: updated preloaded function for the list view quick add * fix: resolved bug in the assignee dropdown * chore: issue sidebar link improvement * fix: resolved subscription store bug * chore: updated preloaded function for the kanban layout quick add * chore: resolved issues in the list filters and component * chore: filter store updated * fix: issue serializer changed * chore: quick add preload function updated * fix: build error * fix: serializer changed * fix: minor request change * chore: resolved build issues and updated the prepopulated data in the quick add issue. * fix: build fix and code refactor * fix: spreadsheet layout quick add fix * fix: issue peek overview link section updated * fix: cycle status bug fix * fix: serializer changes * fix: assignee and labels listing * chore: issue modal parent_id default value updated * fix: cycle and module issue serializer change * fix: cycle list serializer changed * chore: prepopulated validation in both list and kanban for quick add and group header add issues * chore: group header validation added * fix: issue response payload change * dev: make cycle and module issue create response simillar * chore: custom control link component added * dev: make issue create and update response simillar to list and retrieve * fix: build error * chore: control link component improvement * chore: globalise issue peek overview * chore: control link component improvement * chore: made changes and optimised the issue peek overview root * build-error: resolved build erros for issueId dependancy from issue detail store * chore: peek overview link fix * dev: update state nullable rule --------- Co-authored-by: gurusainath <gurusainath007@gmail.com> Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
129 lines
4.2 KiB
TypeScript
129 lines
4.2 KiB
TypeScript
import { FC, useMemo, useState } from "react";
|
|
import { Plus } from "lucide-react";
|
|
// hooks
|
|
import { useApplication, useIssueDetail } from "hooks/store";
|
|
import useToast from "hooks/use-toast";
|
|
// components
|
|
import { IssueLinkCreateUpdateModal } from "./create-update-link-modal";
|
|
import { IssueLinkList } from "./links";
|
|
// types
|
|
import { TIssueLink } from "@plane/types";
|
|
|
|
export type TLinkOperations = {
|
|
create: (data: Partial<TIssueLink>) => Promise<void>;
|
|
update: (linkId: string, data: Partial<TIssueLink>) => Promise<void>;
|
|
remove: (linkId: string) => Promise<void>;
|
|
};
|
|
|
|
export type TIssueLinkRoot = {
|
|
uneditable: boolean;
|
|
isAllowed: boolean;
|
|
};
|
|
|
|
export const IssueLinkRoot: FC<TIssueLinkRoot> = (props) => {
|
|
// props
|
|
const { uneditable, isAllowed } = props;
|
|
// hooks
|
|
const {
|
|
router: { workspaceSlug, projectId },
|
|
} = useApplication();
|
|
const { peekIssue, createLink, updateLink, removeLink } = useIssueDetail();
|
|
// state
|
|
const [isIssueLinkModalOpen, setIsIssueLinkModalOpen] = useState(false);
|
|
const toggleIssueLinkModal = (modalToggle: boolean) => setIsIssueLinkModalOpen(modalToggle);
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
const handleLinkOperations: TLinkOperations = useMemo(
|
|
() => ({
|
|
create: async (data: Partial<TIssueLink>) => {
|
|
try {
|
|
if (!workspaceSlug || !projectId || !peekIssue?.issueId) throw new Error("Missing required fields");
|
|
await createLink(workspaceSlug, projectId, peekIssue?.issueId, data);
|
|
setToastAlert({
|
|
message: "The link has been successfully created",
|
|
type: "success",
|
|
title: "Link created",
|
|
});
|
|
toggleIssueLinkModal(false);
|
|
} catch (error) {
|
|
setToastAlert({
|
|
message: "The link could not be created",
|
|
type: "error",
|
|
title: "Link not created",
|
|
});
|
|
}
|
|
},
|
|
update: async (linkId: string, data: Partial<TIssueLink>) => {
|
|
try {
|
|
if (!workspaceSlug || !projectId || !peekIssue?.issueId) throw new Error("Missing required fields");
|
|
await updateLink(workspaceSlug, projectId, peekIssue?.issueId, linkId, data);
|
|
setToastAlert({
|
|
message: "The link has been successfully updated",
|
|
type: "success",
|
|
title: "Link updated",
|
|
});
|
|
toggleIssueLinkModal(false);
|
|
} catch (error) {
|
|
setToastAlert({
|
|
message: "The link could not be updated",
|
|
type: "error",
|
|
title: "Link not updated",
|
|
});
|
|
}
|
|
},
|
|
remove: async (linkId: string) => {
|
|
try {
|
|
if (!workspaceSlug || !projectId || !peekIssue?.issueId) throw new Error("Missing required fields");
|
|
await removeLink(workspaceSlug, projectId, peekIssue?.issueId, linkId);
|
|
setToastAlert({
|
|
message: "The link has been successfully removed",
|
|
type: "success",
|
|
title: "Link removed",
|
|
});
|
|
toggleIssueLinkModal(false);
|
|
} catch (error) {
|
|
setToastAlert({
|
|
message: "The link could not be removed",
|
|
type: "error",
|
|
title: "Link not removed",
|
|
});
|
|
}
|
|
},
|
|
}),
|
|
[workspaceSlug, projectId, peekIssue, createLink, updateLink, removeLink, setToastAlert]
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<IssueLinkCreateUpdateModal
|
|
isModalOpen={isIssueLinkModalOpen}
|
|
handleModal={toggleIssueLinkModal}
|
|
linkOperations={handleLinkOperations}
|
|
/>
|
|
|
|
<div className={`py-1 text-xs ${uneditable ? "opacity-60" : ""}`}>
|
|
<div className="flex items-center justify-between gap-2">
|
|
<h4>Links</h4>
|
|
{isAllowed && (
|
|
<button
|
|
type="button"
|
|
className={`grid h-7 w-7 place-items-center rounded p-1 outline-none duration-300 hover:bg-custom-background-90 ${
|
|
uneditable ? "cursor-not-allowed" : "cursor-pointer"
|
|
}`}
|
|
onClick={() => setIsIssueLinkModalOpen(true)}
|
|
disabled={uneditable}
|
|
>
|
|
<Plus className="h-4 w-4" />
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
<div>
|
|
<IssueLinkList linkOperations={handleLinkOperations} />
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
};
|