Skip to content

Commit 09d289f

Browse files
committed
feat: remove from now duration util
1 parent e6c3a61 commit 09d289f

File tree

7 files changed

+24
-39
lines changed

7 files changed

+24
-39
lines changed

src/Shared/utils.tsx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import moment from 'moment'
2-
31
import { AppType } from '@devtron-labs/devtron-fe-common-lib'
42

53
const getAppTypeCategory = (appType: AppType) => {
@@ -20,29 +18,3 @@ const getAppTypeCategory = (appType: AppType) => {
2018

2119
export const getAIAnalyticsEvents = (context: string, appType?: AppType) =>
2220
`AI_${appType ? `${getAppTypeCategory(appType)}_` : ''}${context}`
23-
24-
export const formatDurationFromNow = (timestamp: string | number | Date): string => {
25-
if (!timestamp) {
26-
return ''
27-
}
28-
const now = moment()
29-
const then = moment(timestamp)
30-
const duration = moment.duration(now.diff(then))
31-
32-
const units = [
33-
{ label: 'd', value: duration.days() },
34-
{ label: 'h', value: duration.hours() },
35-
{ label: 'm', value: duration.minutes() },
36-
{ label: 's', value: duration.seconds() },
37-
]
38-
39-
// Filter out zero values and take the first two non-zero units
40-
const nonZeroUnits = units.filter((unit) => unit.value > 0).slice(0, 2)
41-
42-
// If all units are zero, show "0s"
43-
if (nonZeroUnits.length === 0) {
44-
return '0s'
45-
}
46-
47-
return nonZeroUnits.map((unit) => `${unit.value}${unit.label}`).join(' ')
48-
}

src/components/ClusterNodes/ClusterEvents.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { PodEventsType } from '../v2/appDetails/k8Resource/nodeDetail/NodeDetail
2222
import MessageUI from '../v2/common/message.ui'
2323
import { getClusterEvents } from './clusterNodes.service'
2424
import { ClusterEventsType } from './types'
25+
import { getAIAnalyticsEvents } from 'src/Shared'
2526

2627
export default function ClusterEvents({ terminalAccessId, reconnectStart, clusterId }: ClusterEventsType) {
2728
const [events, setEvents] = useState([])
@@ -81,7 +82,7 @@ export default function ClusterEvents({ terminalAccessId, reconnectStart, cluste
8182
errorValue={errorValue}
8283
reconnect={reconnectStart}
8384
clusterId={clusterId}
84-
aiWidgetAnalyticsEvent='AI_RB_EVENT'
85+
aiWidgetAnalyticsEvent={getAIAnalyticsEvents('RB_EVENT')}
8586
/>
8687
)
8788
}

src/components/ResourceBrowser/ResourceList/BaseResourceList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { useEffect, useMemo, useRef, useState } from 'react'
1818
import { useHistory, useLocation, useRouteMatch } from 'react-router-dom'
1919
import DOMPurify from 'dompurify'
20+
import { getAIAnalyticsEvents } from 'src/Shared'
2021

2122
import {
2223
ALL_NAMESPACE_OPTION,
@@ -565,7 +566,7 @@ const BaseResourceListContent = ({
565566
status: resourceData.status ?? '',
566567
},
567568
prompt: `Debug what's wrong with ${resourceData.name}/${selectedResource?.gvk?.Kind} of ${resourceData.namespace}`,
568-
analyticsCategory: 'AI_RB_RESOURCE',
569+
analyticsCategory: getAIAnalyticsEvents('RB__RESOURCE'),
569570
}}
570571
/>
571572
</div>

src/components/ResourceBrowser/ResourceList/EventList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
/* eslint-disable react/no-danger */
1818
import DOMPurify from 'dompurify'
19+
import { getAIAnalyticsEvents } from 'src/Shared'
1920

2021
import { highlightSearchText, Tooltip } from '@devtron-labs/devtron-fe-common-lib'
2122

@@ -160,7 +161,7 @@ export const EventList = ({ listRef, filteredData, handleResourceClick, searchTe
160161
clusterId,
161162
metadata: eventDetails,
162163
prompt: JSON.stringify(eventDetails),
163-
analyticsCategory: 'AI_RB_RESOURCE',
164+
analyticsCategory: getAIAnalyticsEvents('RB_RESOURCE'),
164165
}}
165166
/>
166167
) : (

src/components/ResourceBrowser/ResourceList/K8SResourceList.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { useMemo, useRef, useState } from 'react'
1818
import { useLocation, useParams } from 'react-router-dom'
19+
import { getAIAnalyticsEvents } from 'src/Shared'
1920

2021
import {
2122
abortPreviousRequests,
@@ -133,7 +134,10 @@ export const K8SResourceList = ({
133134
handleResourceClick={handleResourceClick}
134135
>
135136
{PodRestart && (
136-
<PodRestart aiWidgetAnalyticsEvent="AI_RB_POD_RESTART" rbacPayload={getPodRestartRBACPayload()} />
137+
<PodRestart
138+
aiWidgetAnalyticsEvent={getAIAnalyticsEvents('RB_POD_RESTART')}
139+
rbacPayload={getPodRestartRBACPayload()}
140+
/>
137141
)}
138142
</BaseResourceList>
139143
)

src/components/app/details/appDetails/AppStatusCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const AppStatusCard = ({ appDetails, status, cardLoading, setDetailed, message }
5656
</Tippy>
5757
)}
5858
<div className="app-details-info-card__bottom-container__details fs-12 fw-6">Details</div>
59-
{!isStatusHealthy && (debugNode || message) && (
59+
{ExplainWithAIButton && !isStatusHealthy && (debugNode || message) && (
6060
<ExplainWithAIButton
6161
intelligenceConfig={{
6262
clusterId: appDetails.clusterId,

src/components/v2/appDetails/k8Resource/nodeDetail/NodeDetailTabs/EventsTable.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { formatDurationFromNow } from 'src/Shared'
18-
19-
import { AppThemeType, getComponentSpecificThemeClass, Icon } from '@devtron-labs/devtron-fe-common-lib'
17+
import {
18+
AppThemeType,
19+
getComponentSpecificThemeClass,
20+
getTimeDifference,
21+
Icon,
22+
} from '@devtron-labs/devtron-fe-common-lib'
2023

2124
import { importComponentFromFELibrary } from '@Components/common'
2225

@@ -32,8 +35,8 @@ const EVENTS_TABLE_HEADERS = [
3235
'Reason',
3336
'Message',
3437
'Count',
35-
'Last Seen',
3638
'Age',
39+
'Last Seen',
3740
...(ExplainWithAIButton ? [''] : []),
3841
]
3942

@@ -83,8 +86,11 @@ export const EventsTable = ({
8386
</div>
8487
{eventsList.map((event, index) => {
8588
const { type, reason, message, count, firstTimestamp, lastTimestamp } = event
86-
const lastSeen = formatDurationFromNow(lastTimestamp)
87-
const age = formatDurationFromNow(firstTimestamp)
89+
90+
const currentTimeStamp = new Date().toISOString()
91+
const lastSeen = getTimeDifference({ startTime: lastTimestamp, endTime: currentTimeStamp })
92+
const age = getTimeDifference({ startTime: firstTimestamp, endTime: currentTimeStamp })
93+
8894
const isNormalEventType = type === 'Normal'
8995
return (
9096
<div

0 commit comments

Comments
 (0)