refactor: favorite projects fetch function, chore: update tooltip design (#1526)

* chore: update tooltip design

* fix: due date popup overflow

* fix: build error

* fix: build error

* chore: add key to map return value

* refactor: favorite projects sidebar list
This commit is contained in:
Aaryan Khandelwal 2023-07-14 15:08:07 +05:30 committed by GitHub
parent 7914bcf486
commit da6ecd439c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 90 additions and 128 deletions

View File

@ -60,6 +60,10 @@ export const SingleBoard: React.FC<Props> = ({
const [properties] = useIssuesProperties(workspaceSlug as string, projectId as string); const [properties] = useIssuesProperties(workspaceSlug as string, projectId as string);
// Check if it has at least 4 tickets since it is enough to accommodate the Calendar height
const issuesLength = groupedByIssues?.[groupTitle].length;
const hasMinimumNumberOfCards = issuesLength ? issuesLength >= 4 : false;
const isNotAllowed = userAuth.isGuest || userAuth.isViewer || isCompleted; const isNotAllowed = userAuth.isGuest || userAuth.isViewer || isCompleted;
return ( return (
@ -103,7 +107,11 @@ export const SingleBoard: React.FC<Props> = ({
</div> </div>
</> </>
)} )}
<div className="pt-3 overflow-hidden overflow-y-scroll"> <div
className={`pt-3 ${
hasMinimumNumberOfCards ? "overflow-hidden overflow-y-scroll" : ""
} `}
>
{groupedByIssues?.[groupTitle].map((issue, index) => ( {groupedByIssues?.[groupTitle].map((issue, index) => (
<Draggable <Draggable
key={issue.id} key={issue.id}

View File

@ -11,7 +11,7 @@ import useEstimateOption from "hooks/use-estimate-option";
// components // components
import { SelectFilters } from "components/views"; import { SelectFilters } from "components/views";
// ui // ui
import { CustomMenu, Icon, ToggleSwitch } from "components/ui"; import { CustomMenu, Icon, ToggleSwitch, Tooltip } from "components/ui";
// icons // icons
import { import {
ChevronDownIcon, ChevronDownIcon,
@ -82,18 +82,25 @@ export const IssuesFilterView: React.FC = () => {
{!isArchivedIssues && ( {!isArchivedIssues && (
<div className="flex items-center gap-x-1"> <div className="flex items-center gap-x-1">
{issueViewOptions.map((option) => ( {issueViewOptions.map((option) => (
<button <Tooltip
key={option.type} key={option.type}
type="button" tooltipContent={
className={`grid h-7 w-7 place-items-center rounded p-1 outline-none hover:bg-custom-sidebar-background-80 duration-300 ${ <span className="capitalize">{replaceUnderscoreIfSnakeCase(option.type)} View</span>
issueView === option.type }
? "bg-custom-sidebar-background-80" position="bottom"
: "text-custom-sidebar-text-200"
}`}
onClick={() => setIssueView(option.type)}
> >
{option.icon} <button
</button> type="button"
className={`grid h-7 w-7 place-items-center rounded p-1 outline-none hover:bg-custom-sidebar-background-80 duration-300 ${
issueView === option.type
? "bg-custom-sidebar-background-80"
: "text-custom-sidebar-text-200"
}`}
onClick={() => setIssueView(option.type)}
>
{option.icon}
</button>
</Tooltip>
))} ))}
</div> </div>
)} )}

View File

@ -69,13 +69,12 @@ export const IssueAttachments = () => {
<div className="h-7 w-7">{getFileIcon(getFileExtension(file.asset))}</div> <div className="h-7 w-7">{getFileIcon(getFileExtension(file.asset))}</div>
<div className="flex flex-col gap-1"> <div className="flex flex-col gap-1">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Tooltip theme="dark" tooltipContent={getFileName(file.attributes.name)}> <Tooltip tooltipContent={getFileName(file.attributes.name)}>
<span className="text-sm"> <span className="text-sm">
{truncateText(`${getFileName(file.attributes.name)}`, 10)} {truncateText(`${getFileName(file.attributes.name)}`, 10)}
</span> </span>
</Tooltip> </Tooltip>
<Tooltip <Tooltip
theme="dark"
tooltipContent={`${ tooltipContent={`${
people?.find((person) => person.member.id === file.updated_by)?.member people?.find((person) => person.member.id === file.updated_by)?.member
.first_name ?? "" .first_name ?? ""

View File

@ -141,7 +141,6 @@ export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
? "This page is only visible to you." ? "This page is only visible to you."
: "This page can be viewed by anyone in the project." : "This page can be viewed by anyone in the project."
}`} }`}
theme="dark"
> >
<button <button
type="button" type="button"
@ -160,7 +159,6 @@ export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
</Tooltip> </Tooltip>
)} )}
<Tooltip <Tooltip
theme="dark"
position="top-right" position="top-right"
tooltipContent={`Created by ${ tooltipContent={`Created by ${
people?.find((person) => person.member.id === page.created_by)?.member people?.find((person) => person.member.id === page.created_by)?.member

View File

@ -140,7 +140,6 @@ export const SinglePageListItem: React.FC<TSingleStatProps> = ({
? "This page is only visible to you." ? "This page is only visible to you."
: "This page can be viewed by anyone in the project." : "This page can be viewed by anyone in the project."
}`} }`}
theme="dark"
> >
<button <button
type="button" type="button"
@ -159,7 +158,6 @@ export const SinglePageListItem: React.FC<TSingleStatProps> = ({
</Tooltip> </Tooltip>
)} )}
<Tooltip <Tooltip
theme="dark"
position="top-right" position="top-right"
tooltipContent={`Created by ${ tooltipContent={`Created by ${
people?.find((person) => person.member.id === page.created_by)?.member people?.find((person) => person.member.id === page.created_by)?.member

View File

@ -71,13 +71,6 @@ export const DeleteProjectModal: React.FC<TConfirmProjectDeletionProps> = ({
setIsDeleteLoading(true); setIsDeleteLoading(true);
if (data.is_favorite)
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: true }),
(prevData) => prevData?.filter((project: IProject) => project.id !== data.id),
false
);
mutate<IProject[]>( mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }), PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
(prevData) => prevData?.filter((project: IProject) => project.id !== data.id), (prevData) => prevData?.filter((project: IProject) => project.id !== data.id),

View File

@ -29,8 +29,8 @@ export const ProjectSidebarList: FC = () => {
const { collapsed: sidebarCollapse } = useTheme(); const { collapsed: sidebarCollapse } = useTheme();
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
const { projects: favoriteProjects } = useProjects(true);
const { projects: allProjects } = useProjects(); const { projects: allProjects } = useProjects();
const favoriteProjects = allProjects?.filter((p) => p.is_favorite);
const handleDeleteProject = (project: IProject) => { const handleDeleteProject = (project: IProject) => {
setProjectToDelete(project); setProjectToDelete(project);

View File

@ -55,11 +55,6 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
const handleAddToFavorites = () => { const handleAddToFavorites = () => {
if (!workspaceSlug) return; if (!workspaceSlug) return;
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: true }),
(prevData) => [...(prevData ?? []), { ...project, is_favorite: true }],
false
);
mutate<IProject[]>( mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }), PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
(prevData) => (prevData) =>
@ -90,11 +85,6 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
const handleRemoveFromFavorites = () => { const handleRemoveFromFavorites = () => {
if (!workspaceSlug || !project) return; if (!workspaceSlug || !project) return;
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: true }),
(prevData) => (prevData ?? []).filter((p) => p.id !== project.id),
false
);
mutate<IProject[]>( mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }), PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
(prevData) => (prevData) =>
@ -203,7 +193,6 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
<Tooltip <Tooltip
tooltipContent={`Created at ${renderShortDateWithYearFormat(project.created_at)}`} tooltipContent={`Created at ${renderShortDateWithYearFormat(project.created_at)}`}
position="bottom" position="bottom"
theme="dark"
> >
<div className="flex cursor-default items-center gap-1.5 text-xs"> <div className="flex cursor-default items-center gap-1.5 text-xs">
<CalendarDaysIcon className="h-4 w-4" /> <CalendarDaysIcon className="h-4 w-4" />

View File

@ -77,11 +77,6 @@ export const SingleSidebarProject: React.FC<Props> = ({
const handleAddToFavorites = () => { const handleAddToFavorites = () => {
if (!workspaceSlug) return; if (!workspaceSlug) return;
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: true }),
(prevData) => [...(prevData ?? []), { ...project, is_favorite: true }],
false
);
mutate<IProject[]>( mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }), PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
(prevData) => (prevData) =>
@ -105,11 +100,6 @@ export const SingleSidebarProject: React.FC<Props> = ({
const handleRemoveFromFavorites = () => { const handleRemoveFromFavorites = () => {
if (!workspaceSlug) return; if (!workspaceSlug) return;
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: true }),
(prevData) => (prevData ?? []).filter((p) => p.id !== project.id),
false
);
mutate<IProject[]>( mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }), PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
(prevData) => (prevData) =>

View File

@ -1,11 +1,13 @@
import React from "react"; import React from "react";
// next-themes
import { useTheme } from "next-themes";
// tooltip2
import { Tooltip2 } from "@blueprintjs/popover2"; import { Tooltip2 } from "@blueprintjs/popover2";
type Props = { type Props = {
tooltipHeading?: string; tooltipHeading?: string;
tooltipContent: string | JSX.Element; tooltipContent: string | React.ReactNode;
triangle?: boolean;
position?: position?:
| "top" | "top"
| "right" | "right"
@ -25,7 +27,8 @@ type Props = {
children: JSX.Element; children: JSX.Element;
disabled?: boolean; disabled?: boolean;
className?: string; className?: string;
theme?: "light" | "dark"; openDelay?: number;
closeDelay?: number;
}; };
export const Tooltip: React.FC<Props> = ({ export const Tooltip: React.FC<Props> = ({
@ -35,24 +38,40 @@ export const Tooltip: React.FC<Props> = ({
children, children,
disabled = false, disabled = false,
className = "", className = "",
theme = "light", openDelay = 500,
triangle, closeDelay,
}) => ( }) => {
<Tooltip2 const { theme } = useTheme();
disabled={disabled}
content={ return (
<div <Tooltip2
className={`${className} relative z-50 flex max-w-[600px] flex-col items-start justify-center gap-1 rounded-md p-2 text-left text-xs shadow-md ${ disabled={disabled}
theme === "light" ? "text-custom-text-200 bg-custom-background-80" : "bg-black text-white" hoverOpenDelay={openDelay}
}`} hoverCloseDelay={closeDelay}
> content={
{tooltipHeading && <h5 className="font-medium">{tooltipHeading}</h5>} <div
{tooltipContent} className={`relative z-50 max-w-xs gap-1 rounded-md p-2 text-xs shadow-md ${
</div> theme === "custom"
} ? "bg-custom-background-100 text-custom-text-200"
position={position} : "bg-black text-gray-400"
renderTarget={({ isOpen: isTooltipOpen, ref: eleReference, ...tooltipProps }) => } break-words overflow-hidden ${className}`}
React.cloneElement(children, { ref: eleReference, ...tooltipProps, ...children.props }) >
} {tooltipHeading && (
/> <h5
); className={`font-medium ${
theme === "custom" ? "text-custom-text-100" : "text-white"
}`}
>
{tooltipHeading}
</h5>
)}
{tooltipContent}
</div>
}
position={position}
renderTarget={({ isOpen: isTooltipOpen, ref: eleReference, ...tooltipProps }) =>
React.cloneElement(children, { ref: eleReference, ...tooltipProps, ...children.props })
}
/>
);
};

View File

@ -110,7 +110,6 @@ export const ActivityGraph: React.FC<Props> = ({ activities }) => {
tooltipContent={`${ tooltipContent={`${
isActive ? isActive.activity_count : 0 isActive ? isActive.activity_count : 0
} activities on ${renderShortDateWithYearFormat(date)}`} } activities on ${renderShortDateWithYearFormat(date)}`}
theme="dark"
> >
<div <div
className={`${ className={`${

View File

@ -20,7 +20,7 @@ const Sidebar: React.FC<SidebarProps> = ({ toggleSidebar, setToggleSidebar }) =>
return ( return (
<div <div
className={`fixed md:relative inset-y-0 flex flex-col bg-custom-sidebar-background-100 h-full flex-shrink-0 flex-grow-0 border-r border-custom-sidebar-border-100 z-20 duration-300 ${ className={`fixed md:relative inset-y-0 flex flex-col bg-custom-sidebar-background-100 h-full flex-shrink-0 flex-grow-0 border-r border-custom-sidebar-border-100 z-20 duration-300 ${
sidebarCollapse ? "" : "md:w-72" sidebarCollapse ? "" : "md:w-[280px]"
} ${toggleSidebar ? "left-0" : "-left-full md:left-0"}`} } ${toggleSidebar ? "left-0" : "-left-full md:left-0"}`}
> >
<div className="flex h-full w-full flex-1 flex-col"> <div className="flex h-full w-full flex-1 flex-col">

View File

@ -482,7 +482,6 @@ const SinglePage: NextPage = () => {
? "This page is only visible to you." ? "This page is only visible to you."
: "This page can be viewed by anyone in the project." : "This page can be viewed by anyone in the project."
}`} }`}
theme="dark"
> >
{pageDetails.access ? ( {pageDetails.access ? (
<button onClick={() => partialUpdatePage({ access: 0 })} className="z-10"> <button onClick={() => partialUpdatePage({ access: 0 })} className="z-10">

View File

@ -33,24 +33,24 @@ const AutomationsSettings: NextPage = () => {
const { projectDetails } = useProjectDetails(); const { projectDetails } = useProjectDetails();
const handleChange = async (formData: Partial<IProject>) => { const handleChange = async (formData: Partial<IProject>) => {
if (!workspaceSlug || !projectId) return; if (!workspaceSlug || !projectId || !projectDetails) return;
mutate<IProject>( mutate<IProject>(
PROJECT_DETAILS(projectId as string), PROJECT_DETAILS(projectId as string),
(prevData) => ({ ...(prevData as IProject), ...formData }), (prevData) => ({ ...(prevData as IProject), ...formData }),
false false
); );
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
(prevData) =>
(prevData ?? []).map((p) => (p.id === projectDetails.id ? { ...p, ...formData } : p)),
false
);
await projectService await projectService
.updateProject(workspaceSlug as string, projectId as string, formData, user) .updateProject(workspaceSlug as string, projectId as string, formData, user)
.then(() => { .then(() => {})
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string),
(prevData) =>
(prevData ?? []).map((p) => (p.id === projectDetails?.id ? { ...p, ...formData } : p)),
false
);
mutate(PROJECT_DETAILS(projectId as string));
})
.catch(() => { .catch(() => {
setToastAlert({ setToastAlert({
type: "error", type: "error",

View File

@ -71,13 +71,6 @@ const ControlSettings: NextPage = () => {
.then((res) => { .then((res) => {
mutate(PROJECT_DETAILS(projectId as string)); mutate(PROJECT_DETAILS(projectId as string));
if (projectDetails.is_favorite)
mutate(
PROJECTS_LIST(workspaceSlug as string, {
is_favorite: true,
})
);
mutate( mutate(
PROJECTS_LIST(workspaceSlug as string, { PROJECTS_LIST(workspaceSlug as string, {
is_favorite: "all", is_favorite: "all",

View File

@ -99,44 +99,21 @@ const FeaturesSettings: NextPage = () => {
const handleSubmit = async (formData: Partial<IProject>) => { const handleSubmit = async (formData: Partial<IProject>) => {
if (!workspaceSlug || !projectId || !projectDetails) return; if (!workspaceSlug || !projectId || !projectDetails) return;
if (projectDetails.is_favorite)
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug.toString(), {
is_favorite: true,
}),
(prevData) =>
prevData?.map((p) => {
if (p.id === projectId)
return {
...p,
...formData,
};
return p;
}),
false
);
mutate<IProject[]>( mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug.toString(), { PROJECTS_LIST(workspaceSlug.toString(), {
is_favorite: "all", is_favorite: "all",
}), }),
(prevData) => (prevData) => prevData?.map((p) => (p.id === projectId ? { ...p, ...formData } : p)),
prevData?.map((p) => {
if (p.id === projectId)
return {
...p,
...formData,
};
return p;
}),
false false
); );
mutate<IProject>( mutate<IProject>(
PROJECT_DETAILS(projectId as string), PROJECT_DETAILS(projectId as string),
(prevData) => ({ ...(prevData as IProject), ...formData }), (prevData) => {
if (!prevData) return prevData;
return { ...prevData, ...formData };
},
false false
); );

View File

@ -95,13 +95,6 @@ const GeneralSettings: NextPage = () => {
false false
); );
if (projectDetails.is_favorite)
mutate(
PROJECTS_LIST(workspaceSlug as string, {
is_favorite: true,
})
);
mutate( mutate(
PROJECTS_LIST(workspaceSlug as string, { PROJECTS_LIST(workspaceSlug as string, {
is_favorite: "all", is_favorite: "all",

View File

@ -1,5 +1,5 @@
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@200;300;400;500;600;700;800&display=swap"); @import url("https://fonts.googleapis.com/css2?family=Inter:wght@200;300;400;500;600;700;800&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@48,400,0,0"); @import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@48,400,0,0&display=swap");
@tailwind base; @tailwind base;
@tailwind components; @tailwind components;