style: redesign view (#770)

* style: add new design to the view item

* feat: add no of filters
This commit is contained in:
Saheb Giri 2023-04-10 22:46:09 +05:30 committed by GitHub
parent 2dbe1dd401
commit d411cd7576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 59 deletions

View File

@ -1,23 +1,24 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { mutate } from "swr";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { IView } from "types";
// icons // icons
import { TrashIcon, StarIcon } from "@heroicons/react/24/outline"; import { TrashIcon, StarIcon, PencilIcon } from "@heroicons/react/24/outline";
import { StackedLayersIcon } from "components/icons"; import { StackedLayersIcon } from "components/icons";
//components //components
import { CustomMenu } from "components/ui"; import { CustomMenu, Tooltip } from "components/ui";
// services
import viewsService from "services/views.service"; import viewsService from "services/views.service";
// types
import { mutate } from "swr"; import { IView } from "types";
// fetch keys
import { VIEWS_LIST } from "constants/fetch-keys"; import { VIEWS_LIST } from "constants/fetch-keys";
// hooks
import useToast from "hooks/use-toast"; import useToast from "hooks/use-toast";
// helpers
import { truncateText } from "helpers/string.helper";
import { renderShortDate, renderShortTime } from "helpers/date-time.helper";
type Props = { type Props = {
view: IView; view: IView;
@ -81,63 +82,94 @@ export const SingleViewItem: React.FC<Props> = ({ view, setSelectedView }) => {
}; };
return ( return (
<Link href={`/${workspaceSlug}/projects/${projectId}/views/${view.id}`}> <li>
<a> <Link href={`/${workspaceSlug}/projects/${projectId}/views/${view.id}`}>
<div className="flex items-center cursor-pointer justify-between border-b bg-white p-4 first:rounded-t-[10px] last:rounded-b-[10px]"> <a>
<div className="flex flex-col w-full gap-3"> <div className="relative rounded p-4 hover:bg-gray-100">
<div className="flex justify-between w-full"> <div className="flex items-center justify-between">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<StackedLayersIcon height={18} width={18} /> <StackedLayersIcon height={18} width={18} />
<a>{view.name}</a> <p className="mr-2 truncate text-sm font-medium">{truncateText(view.name, 75)}</p>
</div> </div>
<div className="flex"> <div className="ml-2 flex flex-shrink-0">
{view.is_favorite ? ( <div className="flex items-center gap-2">
<button <p className="text-xs bg-gray-300 text-gray-600 py-0.5 px-2 rounded-full">
type="button" {Object.keys(view.query_data)
onClick={(e) => { .map((key: string) =>
e.preventDefault(); view.query_data[key as keyof typeof view.query_data] !== null
e.stopPropagation(); ? (view.query_data[key as keyof typeof view.query_data] as any).length
handleRemoveFromFavorites(); : 0
}} )
.reduce((curr, prev) => curr + prev, 0)}{" "}
filters
</p>
<Tooltip
tooltipContent={`Last updated at ${renderShortTime(
view.updated_at
)} ${renderShortDate(view.updated_at)}`}
> >
<StarIcon className="h-4 w-4 text-orange-400" fill="#f6ad55" /> <p className="text-sm text-gray-400">{renderShortTime(view.updated_at)}</p>
</button> </Tooltip>
) : ( {view.is_favorite ? (
<button <button
type="button" type="button"
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
handleAddToFavorites(); handleRemoveFromFavorites();
}} }}
> >
<StarIcon className="h-4 w-4 " color="#858E96" /> <StarIcon className="h-4 w-4 text-orange-400" fill="#f6ad55" />
</button> </button>
)} ) : (
<CustomMenu width="auto" verticalEllipsis> <button
<CustomMenu.MenuItem type="button"
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
setSelectedView(view); handleAddToFavorites();
}} }}
> >
<span className="flex items-center justify-start gap-2"> <StarIcon className="h-4 w-4 " color="#858e96" />
<TrashIcon className="h-4 w-4" /> </button>
<span>Delete</span> )}
</span> <CustomMenu width="auto" verticalEllipsis>
</CustomMenu.MenuItem> {/* <CustomMenu.MenuItem
</CustomMenu> onClick={(e: any) => {
e.preventDefault();
e.stopPropagation();
// handleEditView();
}}
>
<span className="flex items-center justify-start gap-2">
<PencilIcon className="h-3.5 w-3.5" />
<span>Edit View</span>
</span>
</CustomMenu.MenuItem> */}
<CustomMenu.MenuItem
onClick={(e: any) => {
e.preventDefault();
e.stopPropagation();
setSelectedView(view);
}}
>
<span className="flex items-center justify-start gap-2">
<TrashIcon className="h-3.5 w-3.5" />
<span>Delete View</span>
</span>
</CustomMenu.MenuItem>
</CustomMenu>
</div>
</div> </div>
</div> </div>
{view?.description && ( {view?.description && (
<p className="text-sm text-[#858E96] font-normal leading-5 px-[27px]"> <p className="text-sm text-gray-400 font-normal leading-5 px-[27px]">
{view.description} {view.description}
</p> </p>
)} )}
</div> </div>
</div> </a>
</a> </Link>
</Link> </li>
); );
}; };

View File

@ -86,11 +86,11 @@ const ProjectViews: NextPage = () => {
views.length > 0 ? ( views.length > 0 ? (
<div className="space-y-5"> <div className="space-y-5">
<h3 className="text-3xl font-semibold text-black">Views</h3> <h3 className="text-3xl font-semibold text-black">Views</h3>
<div className="rounded-[10px] border"> <ul role="list" className="divide-y">
{views.map((view) => ( {views.map((view) => (
<SingleViewItem key={view.id} view={view} setSelectedView={setSelectedView} /> <SingleViewItem key={view.id} view={view} setSelectedView={setSelectedView} />
))} ))}
</div> </ul>
</div> </div>
) : ( ) : (
<EmptyState <EmptyState