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

fix(logs): feedback #4 #2269

Merged
merged 5 commits into from
Jun 6, 2024
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
30 changes: 20 additions & 10 deletions packages/shared/lib/services/notification/slack.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ export class SlackService {
const connectionWord = count === 1 ? 'connection' : 'connections';
const flowType = type;
const date = new Date();
const dateString = date.toISOString().split('T')[0] as string;
const payload: NotificationPayload = {
content: this.getMessage({ type, count, connectionWord, flowType, name, envName, originalActivityLogId, date: dateString, resolved: false }),
content: this.getMessage({ type, count, connectionWord, flowType, name, envName, originalActivityLogId, date, resolved: false }),
status: 'open',
providerConfigKey: nangoConnection.provider_config_key,
provider
Expand Down Expand Up @@ -386,7 +385,7 @@ export class SlackService {
name: syncName,
envName,
originalActivityLogId,
date: new Date().toISOString().split('T')[0] as string,
date: new Date(),
resolved: true
});
} else {
Expand All @@ -400,7 +399,7 @@ export class SlackService {
name: syncName,
envName,
originalActivityLogId,
date: new Date().toISOString().split('T')[0] as string,
date: new Date(),
resolved: false
});
}
Expand Down Expand Up @@ -690,18 +689,29 @@ export class SlackService {
envName: string;
originalActivityLogId: number | null;
name: string;
date: string;
date: Date;
type: string;
}) {
if (!originalActivityLogId) {
return `${basePublicUrl}/${envName}/activity?${type === 'auth' ? 'connection' : 'script'}=${name}date=${date}`;
const usp = new URLSearchParams();

if (originalActivityLogId) {
usp.set('operationId', String(originalActivityLogId));
}

const from = new Date(date);
from.setHours(0, 0);
const to = new Date(date);
to.setHours(23, 59);
usp.set('from', from.toISOString());
usp.set('to', to.toISOString());

if (type === 'auth') {
return `${basePublicUrl}/${envName}/activity?activity_log_id=${originalActivityLogId}&connection=${name}&date=${date}`;
usp.set('connections', name);
} else {
return `${basePublicUrl}/${envName}/activity?activity_log_id=${originalActivityLogId}&script=${name}&date=${date}`;
usp.set('syncs', name);
}

return `${basePublicUrl}/${envName}/logs?${usp.toString()}`;
}

private getMessage({
Expand All @@ -722,7 +732,7 @@ export class SlackService {
name: string;
envName: string;
originalActivityLogId: number | null;
date: string;
date: Date;
resolved: boolean;
}): string {
switch (type) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/components/ui/ScrollArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cn } from '../../utils/utils';

const ScrollArea = React.forwardRef<React.ElementRef<typeof ScrollAreaPrimitive.Root>, React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>>(
({ className, children, ...props }, ref) => (
<ScrollAreaPrimitive.Root ref={ref} className={cn('relative overflow-hidden', className)} {...props}>
<ScrollAreaPrimitive.Root ref={ref} className={cn('relative overflow-hidden pointer-events-auto', className)} {...props}>
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">{children}</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
Expand Down
12 changes: 10 additions & 2 deletions packages/webapp/src/hooks/useLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type { GetOperation, SearchFilters, SearchMessages, SearchOperations } fr
import { useEffect, useRef, useState } from 'react';
import useSWR from 'swr';
import { apiFetch, swrFetcher } from '../utils/api';
import { slidePeriod } from '../utils/logs';

export function useSearchOperations(env: string, body: SearchOperations['Body']) {
export function useSearchOperations(env: string, body: SearchOperations['Body'], isLive: boolean) {
const [loading, setLoading] = useState<boolean>(false);
const [data, setData] = useState<SearchOperations['Success']>();
const [error, setError] = useState<SearchOperations['Errors']>();
Expand All @@ -17,9 +18,16 @@ export function useSearchOperations(env: string, body: SearchOperations['Body'])
setLoading(true);
signal.current = new AbortController();
try {
let period = body.period;
// Slide the window automatically when live
// We do it only at query time so the URL stays shareable (datadog style)
if (isLive && period) {
period = slidePeriod(period);
}

const res = await apiFetch(`/api/v1/logs/operations?env=${env}`, {
method: 'POST',
body: JSON.stringify({ ...body, cursor }),
body: JSON.stringify({ ...body, period, cursor }),
signal: signal.current.signal
});
if (res.status !== 200) {
Expand Down
17 changes: 11 additions & 6 deletions packages/webapp/src/pages/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { LeftNavBarItems } from '../components/LeftNavBar';
import type { ActivityMessageResponse, ActivityResponse } from '../types';

import { useStore } from '../store';
import Info from '../components/ui/Info';

interface Props {
data: string | number | undefined;
Expand Down Expand Up @@ -380,16 +381,20 @@ export default function Activity() {
return (
<DashboardLayout selectedItem={LeftNavBarItems.Activity}>
<div className="relative -left-24">
<div className="flex items-center mb-6">
<div className="flex items-center mb-3">
<div className="flex flex-col text-left">
<span className="flex items-center mb-3">
<h2 className="text-3xl font-semibold tracking-tight text-white mr-4">Logs</h2>
</span>
<span>
<p className="text-white text-left">Note that logs older than 15 days are cleared</p>
<span className="flex items-center">
<h2 className="text-3xl font-semibold tracking-tight text-white">Activity</h2>
</span>
</div>
</div>
<Info color="blue" classNames="min-w-[1150px] text-sm mb-6" padding="p-2" size={15}>
This page is being replaced by our new faster and cleaner{' '}
<Link to="/logs" className="underline">
logs
</Link>{' '}
page
</Info>
{activities && activities.length === 0 && !status && !selectedIntegration && !selectedScript && !selectedConnection && !selectedDate ? null : (
<div className="flex justify-between p-3 mb-6 items-center border border-border-gray rounded-md min-w-[1150px]">
<div className="flex space-x-10 justify-between px-2 w-full">
Expand Down
12 changes: 9 additions & 3 deletions packages/webapp/src/pages/Connection/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import Syncs from './Syncs';
import Authorization from './Authorization';
import type { SyncResponse } from '../../types';
import PageNotFound from '../PageNotFound';
import { isHosted, getSimpleDate } from '../../utils/utils';
import { isHosted } from '../../utils/utils';
import { connectSlack } from '../../utils/slack-connection';
import type { GetConnection } from '@nangohq/types';

import { useStore } from '../../store';
import { getLogsUrl } from '../../utils/logs';

export enum Tabs {
Syncs,
Expand Down Expand Up @@ -265,7 +266,12 @@ We could not retrieve and/or refresh your access token due to the following erro
<ErrorCircle />
<span className="ml-2">There was an error refreshing the credentials</span>
<Link
to={`/${env}/activity?activity_log_id=${connectionResponse.errorLog.activity_log_id}&connection=${connectionResponse.connection.connection_id}&date=${getSimpleDate(connectionResponse.errorLog?.created_at?.toString())}`}
to={getLogsUrl({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When clicking from the connections page I get this

image

which in of itself the x looks misaligned

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad-link.mov

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird, thanks for testing that looking into it

Copy link
Collaborator Author

@bodinsamuel bodinsamuel Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any issue on my side, however I noted the Failed state does not appear if the schedule is paused

Screen.Recording.2024-06-06.at.11.36.21.mov

env,
operationId: connectionResponse.errorLog.activity_log_id,
connections: connectionResponse.connection.connection_id,
day: connectionResponse.errorLog?.created_at
})}
className="ml-1 cursor-pointer underline"
>
(logs).
Expand All @@ -290,7 +296,7 @@ We could not retrieve and/or refresh your access token due to the following erro
{sync.name} (
<Link
className="underline"
to={`/${env}/activity?activity_log_id=${sync.active_logs?.activity_log_id}&script=${sync.name}`}
to={getLogsUrl({ env, operationId: sync.active_logs?.activity_log_id, syncs: sync.name })}
>
logs
</Link>
Expand Down
79 changes: 52 additions & 27 deletions packages/webapp/src/pages/Connection/Syncs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import {
import type { SyncResponse, RunSyncCommand } from '../../types';
import type { Connection } from '@nangohq/types';
import { UserFacingSyncCommand } from '../../types';
import { formatFrequency, getRunTime, parseLatestSyncResult, formatDateToUSFormat, interpretNextRun, getSimpleDate } from '../../utils/utils';
import { formatFrequency, getRunTime, parseLatestSyncResult, formatDateToUSFormat, interpretNextRun } from '../../utils/utils';
import Button from '../../components/ui/button/Button';
import { useRunSyncAPI } from '../../utils/api';
import { getLogsUrl } from '../../utils/logs';

interface SyncsProps {
syncs: SyncResponse[] | undefined;
Expand Down Expand Up @@ -120,11 +121,17 @@ export default function Syncs({ syncs, connection, provider, reload, loaded, syn
setShowTriggerFullLoader(false);
};

const renderBubble = (bubbleType: ReactNode, sync: SyncResponse) => {
const RenderBubble = ({ sync, children }: { sync: SyncResponse; children: ReactNode }) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed that to a proper component for clarification

const hasActivityLogId = sync.latest_sync?.activity_log_id !== null;
const linkPath = `/${env}/activity?activity_log_id=${sync.latest_sync?.activity_log_id}&connection=${connection?.connection_id}&script=${sync.name}&date=${getSimpleDate(sync.latest_sync?.updated_at)}`;
const linkPath = getLogsUrl({
env,
operationId: sync.latest_sync?.activity_log_id,
connections: connection?.connection_id,
syncs: sync.name,
day: new Date(sync.latest_sync?.updated_at)
});

return hasActivityLogId ? <Link to={linkPath}>{bubbleType}</Link> : <div>{bubbleType}</div>;
return hasActivityLogId ? <Link to={linkPath}>{children}</Link> : <div>{children}</div>;
};

if (!loaded || !syncLoaded || syncs === null) return <Loading spaceRatio={2.5} className="top-24" />;
Expand Down Expand Up @@ -199,34 +206,34 @@ export default function Syncs({ syncs, connection, provider, reload, loaded, syn
</div>
<div className="flex w-20 -ml-2">
<span className="">
{sync.status === 'PAUSED' &&
renderBubble(
{sync.status === 'PAUSED' && (
<RenderBubble sync={sync}>
<Tag bgClassName="bg-yellow-500 bg-opacity-30" textClassName="text-yellow-500">
Paused
</Tag>,
sync
)}
{(sync?.status === 'ERROR' || sync?.status === 'STOPPED') &&
renderBubble(
</Tag>
</RenderBubble>
)}
{(sync?.status === 'ERROR' || sync?.status === 'STOPPED') && (
<RenderBubble sync={sync}>
<Tag bgClassName="bg-red-base bg-opacity-30" textClassName="text-red-base">
Failed
</Tag>,
sync
)}
{sync?.status === 'RUNNING' &&
renderBubble(
</Tag>
</RenderBubble>
)}
{sync?.status === 'RUNNING' && (
<RenderBubble sync={sync}>
<Tag bgClassName="bg-blue-base bg-opacity-30" textClassName="text-blue-base">
Syncing
</Tag>,
sync
)}
{sync?.status === 'SUCCESS' &&
renderBubble(
</Tag>
</RenderBubble>
)}
{sync?.status === 'SUCCESS' && (
<RenderBubble sync={sync}>
<Tag bgClassName="bg-green-base bg-opacity-30" textClassName="text-green-base">
Success
</Tag>,
sync
)}
</Tag>
</RenderBubble>
)}
</span>
</div>
<div className="flex items-center w-10">{formatFrequency(sync.frequency)}</div>
Expand All @@ -235,7 +242,13 @@ export default function Syncs({ syncs, connection, provider, reload, loaded, syn
<Tooltip text={<pre>{parseLatestSyncResult(sync.latest_sync.result, sync.latest_sync.models)}</pre>} type="dark">
{sync.latest_sync?.activity_log_id !== null ? (
<Link
to={`/${env}/activity?activity_log_id=${sync.latest_sync?.activity_log_id}&connection=${connection?.connection_id}&script=${sync.name}&date=${getSimpleDate(sync.latest_sync?.updated_at)}`}
to={getLogsUrl({
env,
operationId: sync.latest_sync?.activity_log_id,
connections: connection?.connection_id,
syncs: sync.name,
day: new Date(sync.latest_sync?.updated_at)
})}
className="block w-32 ml-1"
>
{formatDateToUSFormat(sync.latest_sync?.updated_at)}
Expand All @@ -248,7 +261,13 @@ export default function Syncs({ syncs, connection, provider, reload, loaded, syn
<>
{sync.latest_sync?.activity_log_id ? (
<Link
to={`/${env}/activity?activity_log_id=${sync.latest_sync?.activity_log_id}&connection=${connection?.connection_id}&script=${sync.name}&date=${getSimpleDate(sync.latest_sync?.updated_at)}`}
to={getLogsUrl({
env,
operationId: sync.latest_sync?.activity_log_id,
connections: connection?.connection_id,
syncs: sync.name,
day: new Date(sync.latest_sync?.updated_at)
})}
className=""
>
{formatDateToUSFormat(sync.latest_sync?.updated_at)}
Expand Down Expand Up @@ -396,7 +415,13 @@ export default function Syncs({ syncs, connection, provider, reload, loaded, syn
</span>
</div>
<Link
to={`/${env}/activity?activity_log_id=${sync.latest_sync?.activity_log_id || sync.active_logs?.activity_log_id}&connection=${connection?.connection_id}&script=${sync.name}&date=${getSimpleDate(sync.latest_sync?.updated_at)}`}
to={getLogsUrl({
env,
operationId: sync.latest_sync?.activity_log_id || sync.active_logs?.activity_log_id,
connections: connection?.connection_id,
syncs: sync.name,
day: new Date(sync.latest_sync?.updated_at)
})}
className={`flex items-center w-full whitespace-nowrap hover:bg-neutral-800 px-4 py-2`}
>
<QueueListIcon className={`flex h-6 w-6 text-gray-400 cursor-pointer`} />
Expand Down
Loading
Loading