Skip to content

Commit

Permalink
Alerts date fix (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leshe4ka authored Jul 22, 2022
1 parent 06a8adf commit 7747f9a
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Typography } from '@mui/material';
import React from 'react';
import { Link } from 'react-router-dom';
import { format } from 'date-fns';
import { Alert } from 'generated-sources';
import AlertStatusItem from 'components/shared/AlertStatusItem/AlertStatusItem';
import KebabIcon from 'components/shared/Icons/KebabIcon';
import EntityClassItem from 'components/shared/EntityClassItem/EntityClassItem';
Expand All @@ -11,6 +10,8 @@ import AppTooltip from 'components/shared/AppTooltip/AppTooltip';
import AppPopover from 'components/shared/AppPopover/AppPopover';
import AppMenuItem from 'components/shared/AppMenuItem/AppMenuItem';
import { useAppPaths } from 'lib/hooks';
import { Alert } from 'redux/interfaces';
import { alertDateFormat } from 'lib/constants';
import { ColContainer } from '../AlertsListStyles';
import * as S from './AlertItemStyles';

Expand All @@ -24,6 +25,7 @@ const AlertItem: React.FC<AlertItemProps> = ({
alertStatusHandler,
}) => {
const { dataEntityDetailsPath } = useAppPaths();

return (
<S.Container container>
<ColContainer
Expand Down Expand Up @@ -80,20 +82,14 @@ const AlertItem: React.FC<AlertItemProps> = ({
</ColContainer>
<ColContainer item $colType="createdTime">
<Typography variant="body1">
{alert.createdAt &&
format(alert.createdAt, 'd MMM yyyy, HH:MM a')}
{alert.createdAt && format(alert.createdAt, alertDateFormat)}
</Typography>
</ColContainer>
<ColContainer item $colType="updatedBy">
{/* <Typography variant="body1" noWrap> */}
{/* {alert.statusUpdatedBy?.owner?.name || */}
{/* alert.statusUpdatedBy?.identity.username} */}
{/* </Typography> */}
</ColContainer>
<ColContainer item $colType="updatedBy" />
<ColContainer item $colType="updatedAt">
<Typography variant="body1">
{alert.statusUpdatedAt &&
format(alert.statusUpdatedAt, 'd MMM yyyy, HH:MM a')}
format(alert.statusUpdatedAt, alertDateFormat)}
</Typography>
</ColContainer>
<ColContainer item $colType="actionBtn">
Expand Down
64 changes: 32 additions & 32 deletions odd-platform-ui/src/components/Alerts/AlertsList/AlertsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,46 @@ const AlertsList: React.FC<AlertsListProps> = ({ fetchAlerts }) => {
<S.ColContainer item $colType="createdTime">
<Typography variant="caption">Created at</Typography>
</S.ColContainer>
<S.ColContainer item $colType="updatedBy">
{/* <Typography variant="caption">Status updated by</Typography> */}
</S.ColContainer>
<S.ColContainer item $colType="updatedBy" />
<S.ColContainer item $colType="updatedAt">
<Typography variant="caption">Status updated at</Typography>
</S.ColContainer>
<S.ColContainer item $colType="actionBtn" />
</S.AlertsTableHeader>
<Grid container>
<InfiniteScroll
dataLength={alerts?.length}
next={fetchNextPage}
hasMore={!!pageInfo?.hasNext}
loader={
(isAlertListFetching ||
isMyAlertListFetching ||
isMyDependentsAlertListFetching) && (
<SkeletonWrapper
renderContent={({ randomSkeletonPercentWidth, key }) => (
<AlertListSkeleton
width={randomSkeletonPercentWidth()}
key={key}
/>
<div style={{ width: '100%' }}>
<InfiniteScroll
dataLength={alerts?.length}
next={fetchNextPage}
hasMore={!!pageInfo?.hasNext}
loader={
(isAlertListFetching ||
isMyAlertListFetching ||
isMyDependentsAlertListFetching) && (
<SkeletonWrapper
renderContent={({ randomSkeletonPercentWidth, key }) => (
<AlertListSkeleton
width={randomSkeletonPercentWidth()}
key={key}
/>
)}
/>
)
}
scrollThreshold="200px"
>
{alerts?.map(alert => (
<AlertItem
alertStatusHandler={alertStatusHandler(
alert.id,
alert.status
)}
key={alert.id}
alert={alert}
/>
)
}
scrollThreshold="200px"
>
{alerts?.map(alert => (
<AlertItem
alertStatusHandler={alertStatusHandler(
alert.id,
alert.status
)}
key={alert.id}
alert={alert}
/>
))}
</InfiniteScroll>
))}
</InfiniteScroll>
</div>
</Grid>
{(!isAlertListFetching ||
!isMyAlertListFetching ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { Typography } from '@mui/material';
import { Alert } from 'generated-sources';
import { format } from 'date-fns';
import lowerCase from 'lodash/lowerCase';
import AlertStatusItem from 'components/shared/AlertStatusItem/AlertStatusItem';
import AppTooltip from 'components/shared/AppTooltip/AppTooltip';
import AppButton from 'components/shared/AppButton/AppButton';
import { Alert } from 'redux/interfaces';
import { alertDateFormat } from 'lib/constants';
import { ColContainer } from '../DataEntityAlertsStyles';
import {
ActionButtonsContainer,
Expand All @@ -24,7 +25,7 @@ const DataEntityAlertItem: React.FC<DataEntityAlertItemProps> = ({
<Container container>
<ColContainer item $colType="date">
<Typography variant="body1">
{alert.createdAt && format(alert.createdAt, 'd MMM yyyy, HH:MM a')}
{alert.createdAt && format(alert.createdAt, alertDateFormat)}
</Typography>
</ColContainer>
<ColContainer item $colType="type">
Expand All @@ -51,7 +52,7 @@ const DataEntityAlertItem: React.FC<DataEntityAlertItemProps> = ({
<ColContainer item $colType="updatedTime">
<Typography variant="body1">
{alert.statusUpdatedAt &&
format(alert.statusUpdatedAt, 'd MMM yyyy, HH:MM a')}
format(alert.statusUpdatedAt, alertDateFormat)}
</Typography>
</ColContainer>
<ActionButtonsContainer item $colType="actionBtn">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const TabsContainer = styled(Tabs)<{ $type: TabType }>(
position: 'absolute',
content: '""',
bottom: '0px',
width: 'calc(100% - 16px)',
width: '100%',
zIndex: -1,
borderBottom: '1px solid',
borderBottomColor: theme.palette.info.light,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const AppToolbar: React.FC<AppToolbarProps> = ({

React.useEffect(() => {
const newTabIndex = tabs.findIndex(tab => {
if (tab.link === '/activity') {
if (tab.link === '/activity' || tab.link === '/alerts') {
return (
location.pathname.includes(tab.link) &&
!location.pathname.includes('dataentities')
Expand Down
3 changes: 3 additions & 0 deletions odd-platform-ui/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ export const mainSkeletonHeight = '100%';
// tabs constants
export const primaryTabsHeight = 32;
export const tabsContainerMargin = 16;

// time formats
export const alertDateFormat = 'd MMM yyyy, HH:mm';
5 changes: 5 additions & 0 deletions odd-platform-ui/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const toDateWithoutOffset = (dateToCast: number): Date => {
return new Date(date.getTime() - userTimezoneOffset);
};

export const toTimestampWithoutOffset = (dateToCast: Date): number => {
const userTimezoneOffset = dateToCast.getTimezoneOffset() * 60000;
return dateToCast.getTime() + userTimezoneOffset;
};

export const setActivityBackgroundColor = (
theme: Theme,
eventType?: CRUDType
Expand Down
21 changes: 21 additions & 0 deletions odd-platform-ui/src/lib/redux/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { toTimestampWithoutOffset } from 'lib/helpers';

export const assignWith = <TargetType, SourceType>(
target: TargetType,
source: SourceType,
Expand All @@ -14,3 +16,22 @@ export const assignWith = <TargetType, SourceType>(

export const createActionType = (actionPrefix: string, action: string) =>
`${actionPrefix}/${action}`;

export const isDateType = (value: any) =>
typeof value === 'object' && value instanceof Date;

export const castItemDatesToTimestampInArray = <Data, RData>(
data: Array<Data>
): Array<RData> =>
data.map<RData>(item =>
Object.entries(item).reduce<RData>(
(memo, [key, value]) =>
isDateType(value)
? {
...memo,
[key]: toTimestampWithoutOffset(value),
}
: { ...memo, [key]: value },
{} as RData
)
);
7 changes: 7 additions & 0 deletions odd-platform-ui/src/redux/interfaces/alerts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Alert as GeneratedAlert } from 'generated-sources';

export interface Alert
extends Omit<GeneratedAlert, 'createdAt' | 'statusUpdatedAt'> {
createdAt: number;
statusUpdatedAt: number;
}
2 changes: 1 addition & 1 deletion odd-platform-ui/src/redux/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export * from './datasetStructure';
export * from './dataQualityTest';
export * from './common';
export * from './dataEntityGroup';
export * from './termGroup';
export * from './collectors';
export * from './termSearch';
export * from './dataentityLineage';
export * from './activities';
export * from './alerts';
2 changes: 1 addition & 1 deletion odd-platform-ui/src/redux/interfaces/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EntityState, ThunkAction } from '@reduxjs/toolkit';
import { ActionType } from 'typesafe-actions';
import {
ActivityCountInfo,
Alert,
AlertTotals,
AppInfo,
AssociatedOwner,
Expand Down Expand Up @@ -37,6 +36,7 @@ import { store } from 'redux/store';
import {
Activity,
ActivityQueryParams,
Alert,
CurrentPageInfo,
DataEntityDetailsState,
DataEntityLineageById,
Expand Down
7 changes: 0 additions & 7 deletions odd-platform-ui/src/redux/interfaces/termGroup.ts

This file was deleted.

3 changes: 2 additions & 1 deletion odd-platform-ui/src/redux/reducers/alerts.slice.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { AlertsState } from 'redux/interfaces';
import { Alert } from 'generated-sources';
import { createEntityAdapter, createSlice } from '@reduxjs/toolkit';
import { alertsActionPrefix } from 'redux/actions';

import * as thunks from 'redux/thunks';
import { Alert } from 'redux/interfaces/alerts';

export const alertsAdapter = createEntityAdapter<Alert>({
selectId: alert => alert.id,
sortComparer: (a, b) => b.createdAt - a.createdAt,
});

export const initialState: AlertsState = {
Expand Down
22 changes: 12 additions & 10 deletions odd-platform-ui/src/redux/thunks/alerts.thunks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Alert,
Alert as GeneratedAlert,
AlertApi,
AlertApiChangeAlertStatusRequest,
AlertApiGetAllAlertsRequest,
Expand All @@ -15,7 +15,8 @@ import {
import { createAsyncThunk } from '@reduxjs/toolkit';
import * as actions from 'redux/actions';
import { BASE_PARAMS } from 'lib/constants';
import { CurrentPageInfo } from 'redux/interfaces';
import { Alert, CurrentPageInfo } from 'redux/interfaces';
import { castItemDatesToTimestampInArray } from 'lib/redux/helpers';

const apiClientConf = new Configuration(BASE_PARAMS);
const alertApi = new AlertApi(apiClientConf);
Expand All @@ -28,10 +29,7 @@ export interface AlertsResponse {

export const fetchAlertsTotals = createAsyncThunk<AlertTotals>(
actions.fetchAlertsTotalsActionType,
async () => {
const response = await alertApi.getAlertTotals();
return response;
}
async () => alertApi.getAlertTotals()
);

export const fetchAllAlertList = createAsyncThunk<
Expand All @@ -42,8 +40,9 @@ export const fetchAllAlertList = createAsyncThunk<
page,
size,
});

return {
items,
items: castItemDatesToTimestampInArray<GeneratedAlert, Alert>(items),
pageInfo: { ...pageInfo, page },
};
});
Expand All @@ -57,7 +56,7 @@ export const fetchMyAlertList = createAsyncThunk<
size,
});
return {
items,
items: castItemDatesToTimestampInArray<GeneratedAlert, Alert>(items),
pageInfo: { ...pageInfo, page },
};
});
Expand All @@ -71,7 +70,7 @@ export const fetchMyDependentsAlertList = createAsyncThunk<
size,
});
return {
items,
items: castItemDatesToTimestampInArray<GeneratedAlert, Alert>(items),
pageInfo: { ...pageInfo, page },
};
});
Expand All @@ -98,5 +97,8 @@ export const fetchDataEntityAlerts = createAsyncThunk<
const { items, pageInfo } = await dataEntityApi.getDataEntityAlerts({
dataEntityId,
});
return { items, pageInfo };
return {
items: castItemDatesToTimestampInArray<GeneratedAlert, Alert>(items),
pageInfo,
};
});

0 comments on commit 7747f9a

Please sign in to comment.