Skip to content

Commit

Permalink
time difference issue fixed, added node module in gitignore in main s…
Browse files Browse the repository at this point in the history
…uperagi folder
  • Loading branch information
NishantBorthakur committed Jun 27, 2023
1 parent bed681a commit b33110d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ superagi/controllers/__pycache__
**agent_dictvenv
**/__gitpycache__/
gui/node_modules
node_modules
gui/.next
.DS_Store
.DS_Store?
Expand Down
6 changes: 3 additions & 3 deletions gui/pages/Content/Agents/ActionConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import styles from './Agents.module.css';
import Image from 'next/image';
import { updatePermissions } from '@/pages/api/DashboardService';
import { formatTime } from '@/utils/utils';
import {formatTimeDifference} from '@/utils/utils';

function ActionBox({ action, index, denied, reasons, handleDeny, handleSelection, setReasons }) {
const isDenied = denied[index];
Expand Down Expand Up @@ -49,7 +49,7 @@ function ActionBox({ action, index, denied, reasons, handleDeny, handleSelection
<div>
<Image width={12} height={12} src="/images/schedule.svg" alt="schedule-icon" />
</div>
<div className={styles.history_info}>{formatTime(action.created_at)}</div>
<div className={styles.history_info}>{formatTimeDifference(action.time_difference)}</div>
</div>
</div>
);
Expand Down Expand Up @@ -81,7 +81,7 @@ function HistoryBox({ action }){
<div>
<Image width={12} height={12} src="/images/schedule.svg" alt="schedule-icon" />
</div>
<div className={styles.history_info}>{formatTime(action.created_at)}</div>
<div className={styles.history_info}>{formatTimeDifference(action.time_difference)}</div>
</div>
</div>
</div>
Expand Down
7 changes: 3 additions & 4 deletions gui/pages/Content/Agents/ActivityFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useEffect, useRef, useState} from 'react';
import styles from './Agents.module.css';
import {getExecutionFeeds} from "@/pages/api/DashboardService";
import Image from "next/image";
import {formatTime, loadingTextEffect} from "@/utils/utils";
import {loadingTextEffect, formatTimeDifference} from "@/utils/utils";
import {EventBus} from "@/utils/eventBus";

export default function ActivityFeed({selectedRunId, selectedView, setFetchedData }) {
Expand Down Expand Up @@ -57,7 +57,6 @@ export default function ActivityFeed({selectedRunId, selectedView, setFetchedDat
const data = response.data;
setFeeds(data.feeds);
setRunStatus(data.status);
console.log(data.permissions)
setFetchedData(data.permissions);
})
.catch((error) => {
Expand Down Expand Up @@ -90,13 +89,13 @@ export default function ActivityFeed({selectedRunId, selectedView, setFetchedDat
<div className={styles.feed_title}>{f?.feed || ''}</div>
</div>
<div className={styles.more_details_wrapper}>
{f.updated_at && formatTime(f.updated_at) !== 'Invalid Time' && <div className={styles.more_details}>
{f.time_difference && formatTimeDifference(f.time_difference) !== 'Invalid Time' && <div className={styles.more_details}>
<div style={{display: 'flex', alignItems: 'center'}}>
<div>
<Image width={12} height={12} src="/images/schedule.svg" alt="schedule-icon"/>
</div>
<div className={styles.history_info}>
{formatTime(f.updated_at)}
{formatTimeDifference(f.time_difference)}
</div>
</div>
</div>}
Expand Down
4 changes: 2 additions & 2 deletions gui/pages/Content/Agents/RunHistory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import styles from './Agents.module.css';
import Image from "next/image";
import {formatTime, formatNumber} from "@/utils/utils";
import {formatNumber, formatTimeDifference} from "@/utils/utils";

export default function RunHistory({runs, setHistory, selectedRunId, setSelectedRun}) {
return (<>
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function RunHistory({runs, setHistory, selectedRunId, setSelected
<Image width={12} height={12} src="/images/schedule.svg" alt="schedule-icon"/>
</div>
<div className={styles.history_info}>
{formatTime(run.last_execution_time)}
{formatTimeDifference(run.time_difference)}
</div>
</div>
</div>
Expand Down
25 changes: 12 additions & 13 deletions gui/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { formatDistanceToNow, parseISO } from 'date-fns';
import {baseUrl} from "@/pages/api/apiConfig";

export const formatTime = (lastExecutionTime) => {
try {
const parsedTime = parseISO(lastExecutionTime);
if (isNaN(parsedTime.getTime())) {
throw new Error('Invalid time value');
export const formatTimeDifference = (timeDifference) => {
const units = ['years', 'months', 'days', 'hours', 'minutes'];

for (const unit of units) {
if (timeDifference[unit] !== 0) {
if (unit === 'minutes') {
return `${timeDifference[unit]} minutes ago`;
} else {
return `${timeDifference[unit]} ${unit} ago`;
}
}
return formatDistanceToNow(parsedTime, {
addSuffix: true,
includeSeconds: true,
}).replace(/about\s/, '');
} catch (error) {
console.error('Error formatting time:', error);
return 'Invalid Time';
}

return 'Just now';
};

export const formatNumber = (number) => {
Expand Down

0 comments on commit b33110d

Please sign in to comment.