Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1387-notification-table-cannot-see-error #1471

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/components/JobsHistory/JobHistoryStatusColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { FaDotCircle } from "react-icons/fa";

type Props = {
status?: JobHistoryStatus;
onClick?: () => void;
};

export default function JobHistoryStatusColumn({ status }: Props) {
export default function JobHistoryStatusColumn({ status, onClick }: Props) {
const className = useMemo(() => {
if (status) {
return classNameMaps.get(status);
Expand All @@ -18,9 +19,20 @@ export default function JobHistoryStatusColumn({ status }: Props) {
}

return (
<>
<FaDotCircle className={`inline ${className}`} />
<span className="ml-1">{status}</span>
</>
<div
className="flex flex-row gap-2"
role="button"
onClick={(e) => {
if (!onClick) {
return;
}
e.preventDefault();
e.stopPropagation();
onClick();
}}
>
<FaDotCircle className={`${className}`} />
<span className="">{status}</span>
</div>
);
}
17 changes: 10 additions & 7 deletions src/components/JobsHistory/JobsHistoryDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import { Modal } from "../Modal";
import { JobHistory } from "./JobsHistoryTable";
import clsx from "clsx";

type JobsHistoryDetailsProps = {
job?: JobHistory;
isModalOpen: boolean;
setIsModalOpen: (value: boolean) => void;
};

interface CellProps {
children: React.ReactNode;
className?: string;
Expand All @@ -25,6 +19,12 @@ function Cell({ children, className }: CellProps) {
);
}

type JobsHistoryDetailsProps = {
job?: Pick<JobHistory, "details" | "name">;
isModalOpen: boolean;
setIsModalOpen: (value: boolean) => void;
};

export function JobsHistoryDetails({
job,
isModalOpen,
Expand Down Expand Up @@ -56,7 +56,10 @@ export function JobsHistoryDetails({
</thead>
<tbody>
{job.details?.errors?.map((error, index) => (
<tr className="last:border-b-0 border-b cursor-pointer">
<tr
key={error}
className="last:border-b-0 border-b cursor-pointer"
>
<Cell className="leading-5 text-gray-900 font-medium">
{error}
</Cell>
Expand Down
51 changes: 36 additions & 15 deletions src/components/Notifications/notificationsTableColumns.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { CellContext, ColumnDef } from "@tanstack/react-table";
import { useState } from "react";
import { Team, User } from "../../api/types/users";
import { DateCell } from "../../ui/table";
import { Avatar } from "../Avatar";
import { Badge } from "../Badge";
import { Icon } from "../Icon";
import JobHistoryStatusColumn from "../JobsHistory/JobHistoryStatusColumn";
import { JobsHistoryDetails } from "../JobsHistory/JobsHistoryDetails";
import { JobHistoryStatus } from "../JobsHistory/JobsHistoryTable";

export const notificationEvents = [
Expand Down Expand Up @@ -90,14 +92,31 @@ export const notificationEvents = [
}
].sort((a, b) => a.label.localeCompare(b.label));

export function JobStatusColumn({ cell }: CellContext<Notification, any>) {
export function StatusColumn({ cell }: CellContext<Notification, any>) {
const [isModalOpen, setIsModalOpen] = useState(false);
const value = cell.row.original.job_status;

return <JobHistoryStatusColumn status={value} />;
return (
<>
<JobHistoryStatusColumn
status={value}
onClick={() => setIsModalOpen(true)}
/>
<JobsHistoryDetails
isModalOpen={isModalOpen}
setIsModalOpen={setIsModalOpen}
job={{
details: cell.row.original.job_details,
name: cell.row.original.job_name ?? cell.row.original.title
}}
/>
</>
);
}

export type Notification = {
id: string;
title: string;
events: string[];
template: string;
filter?: string;
Expand All @@ -118,6 +137,10 @@ export type Notification = {
person?: User;
team?: Team;
job_status?: JobHistoryStatus;
job_name?: string;
job_details?: {
errors?: string[];
};
};

export type NewNotification = Omit<
Expand Down Expand Up @@ -156,17 +179,15 @@ export const notificationsTableColumns: ColumnDef<Notification, any>[] = [

{custom_services &&
custom_services.length > 0 &&
custom_services.map(
({ connection, name, filters, properties, url }) => (
<div className="flex flex-row gap-2 items-center">
<Icon
className="inline-block h-6"
name={connection ?? name}
/>
{name}
</div>
)
)}
custom_services.map(({ connection, name }) => (
<div
className="flex flex-row gap-2 items-center"
key={connection ?? name}
>
<Icon className="inline-block h-6" name={connection ?? name} />
{name}
</div>
))}
</div>
);
}
Expand All @@ -182,7 +203,7 @@ export const notificationsTableColumns: ColumnDef<Notification, any>[] = [
return (
<div className="w-full flex flex-col">
{value.map((event) => (
<div className="block p-1">
<div className="block p-1" key={event}>
<Badge text={event} className="w-auto text-sm" />
</div>
))}
Expand Down Expand Up @@ -217,7 +238,7 @@ export const notificationsTableColumns: ColumnDef<Notification, any>[] = [
{
header: "Status",
id: "job_status",
cell: JobStatusColumn
cell: StatusColumn
},
{
header: "Created At",
Expand Down
Loading