2023-10-17 07:16:38 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-10-23 13:47:42 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2023-11-03 13:47:13 +00:00
|
|
|
import { Plus } from "lucide-react";
|
2023-10-23 13:47:42 +00:00
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
// hooks
|
|
|
|
import useLocalStorage from "hooks/use-local-storage";
|
2023-10-17 07:16:38 +00:00
|
|
|
// ui
|
2023-11-03 12:31:49 +00:00
|
|
|
import { Breadcrumbs, Button, Tooltip, DiceIcon } from "@plane/ui";
|
2023-10-17 07:16:38 +00:00
|
|
|
// helper
|
2023-11-03 12:31:49 +00:00
|
|
|
import { renderEmoji } from "helpers/emoji.helper";
|
2023-11-03 13:47:13 +00:00
|
|
|
// constants
|
|
|
|
import { MODULE_VIEW_LAYOUTS } from "constants/module";
|
2023-12-11 11:59:43 +00:00
|
|
|
import { EUserWorkspaceRoles } from "constants/workspace";
|
2023-10-17 07:16:38 +00:00
|
|
|
|
2023-10-23 13:47:42 +00:00
|
|
|
export const ModulesListHeader: React.FC = observer(() => {
|
2023-10-17 07:16:38 +00:00
|
|
|
// router
|
|
|
|
const router = useRouter();
|
2023-11-01 13:52:10 +00:00
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
// store
|
2023-12-11 11:59:43 +00:00
|
|
|
const {
|
|
|
|
project: projectStore,
|
|
|
|
commandPalette: commandPaletteStore,
|
|
|
|
user: { currentProjectRole },
|
|
|
|
} = useMobxStore();
|
2023-11-01 13:52:10 +00:00
|
|
|
const { currentProjectDetails } = projectStore;
|
2023-10-23 13:47:42 +00:00
|
|
|
|
|
|
|
const { storedValue: modulesView, setValue: setModulesView } = useLocalStorage("modules_view", "grid");
|
2023-10-17 07:16:38 +00:00
|
|
|
|
2023-12-11 11:59:43 +00:00
|
|
|
const canUserCreateModule =
|
|
|
|
currentProjectRole && [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER].includes(currentProjectRole);
|
|
|
|
|
2023-10-17 07:16:38 +00:00
|
|
|
return (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="relative z-10 flex h-[3.75rem] w-full flex-shrink-0 flex-row items-center justify-between gap-x-2 gap-y-4 border-b border-custom-border-200 bg-custom-sidebar-background-100 p-4">
|
2023-10-17 11:55:02 +00:00
|
|
|
<div className="flex w-full flex-grow items-center gap-2 overflow-ellipsis whitespace-nowrap">
|
2023-10-17 07:16:38 +00:00
|
|
|
<div>
|
2023-11-03 12:31:49 +00:00
|
|
|
<Breadcrumbs>
|
|
|
|
<Breadcrumbs.BreadcrumbItem
|
|
|
|
type="text"
|
|
|
|
label={currentProjectDetails?.name ?? "Project"}
|
|
|
|
icon={
|
|
|
|
currentProjectDetails?.emoji ? (
|
|
|
|
renderEmoji(currentProjectDetails.emoji)
|
|
|
|
) : currentProjectDetails?.icon_prop ? (
|
|
|
|
renderEmoji(currentProjectDetails.icon_prop)
|
|
|
|
) : (
|
|
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded bg-gray-700 uppercase text-white">
|
|
|
|
{currentProjectDetails?.name.charAt(0)}
|
|
|
|
</span>
|
|
|
|
)
|
2023-10-17 11:55:02 +00:00
|
|
|
}
|
2023-11-03 12:31:49 +00:00
|
|
|
link={`/${workspaceSlug}/projects/${currentProjectDetails?.id}/issues`}
|
|
|
|
/>
|
|
|
|
<Breadcrumbs.BreadcrumbItem
|
|
|
|
type="text"
|
|
|
|
icon={<DiceIcon className="h-4 w-4 text-custom-text-300" />}
|
|
|
|
label="Modules"
|
2023-10-17 11:55:02 +00:00
|
|
|
/>
|
2023-10-17 07:16:38 +00:00
|
|
|
</Breadcrumbs>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center gap-2">
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex items-center gap-1 rounded bg-custom-background-80 p-1">
|
2023-11-03 13:47:13 +00:00
|
|
|
{MODULE_VIEW_LAYOUTS.map((layout) => (
|
|
|
|
<Tooltip key={layout.key} tooltipContent={layout.title}>
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`group grid h-[22px] w-7 place-items-center overflow-hidden rounded transition-all hover:bg-custom-background-100 ${
|
2023-11-03 13:47:13 +00:00
|
|
|
modulesView == layout.key ? "bg-custom-background-100 shadow-custom-shadow-2xs" : ""
|
|
|
|
}`}
|
|
|
|
onClick={() => setModulesView(layout.key)}
|
|
|
|
>
|
|
|
|
<layout.icon
|
|
|
|
strokeWidth={2}
|
|
|
|
className={`h-3.5 w-3.5 ${
|
|
|
|
modulesView == layout.key ? "text-custom-text-100" : "text-custom-text-200"
|
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-12-11 11:59:43 +00:00
|
|
|
{canUserCreateModule && (
|
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
size="sm"
|
|
|
|
prependIcon={<Plus />}
|
|
|
|
onClick={() => commandPaletteStore.toggleCreateModuleModal(true)}
|
|
|
|
>
|
|
|
|
Add Module
|
|
|
|
</Button>
|
|
|
|
)}
|
2023-10-17 07:16:38 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-10-23 13:47:42 +00:00
|
|
|
});
|