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

feat: added table column and row logic for the new api response structure for producer overview #6433

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Typography } from 'antd';
import dayjs from 'dayjs';
import { History } from 'history';
import {
convertToTitleCase,
RowData,
} from 'pages/MessagingQueues/MessagingQueuesUtils';

interface ProducerLatencyOverviewColumn {
timestamp: string;
data: {
[key: string]: number | string;
};
}

export interface TopicThroughputProducerOverviewResponse {
status: string;
payload: {
resultType: string;
result: {
queryName: string;
list: ProducerLatencyOverviewColumn[];
}[];
};
}

export const getColumnsForProduderLatencyOverview = (
SagarRajput-7 marked this conversation as resolved.
Show resolved Hide resolved
list: ProducerLatencyOverviewColumn[],
history: History<unknown>,
): RowData[] => {
if (list?.length === 0) {
return [];
}

const columns: {
title: string;
dataIndex: string;
key: string;
}[] = Object.keys(list[0].data)?.map((column) => ({
title: convertToTitleCase(column),
dataIndex: column,
key: column,
render: (data: string | number): JSX.Element => {
if (column === 'service_name') {
return (
<Typography.Link
onClick={(e): void => {
e.preventDefault();
e.stopPropagation();
history.push(`/services/${encodeURIComponent(data as string)}`);
}}
>
{data}
</Typography.Link>
);
}

if (column === 'ts') {
const date =
typeof data === 'string'
? dayjs(data).format('YYYY-MM-DD HH:mm:ss.SSS')
: dayjs(data / 1e6).format('YYYY-MM-DD HH:mm:ss.SSS');
return <Typography.Text>{date}</Typography.Text>;
}

if (typeof data === 'number') {
return <Typography.Text>{data.toFixed(3)}</Typography.Text>;
}

return <Typography.Text>{data}</Typography.Text>;
},
}));

return columns;
};

export const getTableDataForProducerLatencyOverview = (
list: ProducerLatencyOverviewColumn[],
): RowData[] => {
if (list?.length === 0) {
return [];
}

const tableData: RowData[] = list?.map(
(row, index: number): RowData => ({
...row.data,
key: index,
}),
);

return tableData;
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import {
MessagingQueueServicePayload,
MessagingQueuesPayloadProps,
} from './getConsumerLagDetails';
import {
getColumnsForProduderLatencyOverview,
getTableDataForProducerLatencyOverview,
TopicThroughputProducerOverviewResponse,
} from './MQTableUtils';

const INITIAL_PAGE_SIZE = 10;

Expand Down Expand Up @@ -126,7 +131,13 @@ function MessagingQueuesTable({
tableApi: (
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is tableApi getting passed on like this ?

props: MessagingQueueServicePayload,
) => Promise<
SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse
| SuccessResponse<
(
| MessagingQueuesPayloadProps
| TopicThroughputProducerOverviewResponse
)['payload']
>
| ErrorResponse
>;
validConfigPresent?: boolean;
type?: 'Detail' | 'Overview';
Expand Down Expand Up @@ -177,8 +188,35 @@ function MessagingQueuesTable({
{
onSuccess: (data) => {
if (data.payload) {
setColumns(getColumns(data?.payload, history));
setTableData(getTableData(data?.payload));
if (
type === 'Overview' &&
selectedView === MessagingQueuesViewType.producerLatency.value &&
tableApiPayload?.detailType === 'producer'
) {
setColumns(
getColumnsForProduderLatencyOverview(
(data?.payload as TopicThroughputProducerOverviewResponse['payload'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

why as TopicThroughputProducerOverviewResponse['payload']?

.result[0].list,
Copy link
Collaborator

Choose a reason for hiding this comment

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

will result[0].list always be present ?

history,
),
);
setTableData(
getTableDataForProducerLatencyOverview(
(data?.payload as TopicThroughputProducerOverviewResponse['payload'])
.result[0].list,
),
);
} else {
setColumns(
getColumns(
data?.payload as MessagingQueuesPayloadProps['payload'],
history,
),
);
setTableData(
getTableData(data?.payload as MessagingQueuesPayloadProps['payload']),
);
}
}
},
onError: handleConsumerDetailsOnError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import {
MessagingQueueServicePayload,
MessagingQueuesPayloadProps,
} from './getConsumerLagDetails';
import { TopicThroughputProducerOverviewResponse } from './MQTableUtils';

export const getTopicThroughputOverview = async (
props: Omit<MessagingQueueServicePayload, 'variables'>,
): Promise<
SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse
| SuccessResponse<
(
| MessagingQueuesPayloadProps
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is ideally not a good structure to expect different types of responses based on different conditions.

| TopicThroughputProducerOverviewResponse
)['payload']
>
| ErrorResponse
> => {
const { detailType, start, end } = props;
const response = await axios.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ function MessagingQueueOverview({
? 'producer'
: 'consumer'
: undefined,
evalTime:
selectedView === MessagingQueuesViewType.dropRate.value
? 2363404
: undefined,
};

return (
Expand Down
Loading