Skip to content

Commit

Permalink
[ui-metrics-cuix] Updating metrics to sync with Cloudera design (#3826)
Browse files Browse the repository at this point in the history
* Updating metrics to sync with Cloudera design

* Fixing the style lint

* Checking

* Realigning to the style

* adding I18n

* Fixing linting issues

* Fixing the failing tests due to change in h4 to span

* fixing linting of previous test commit

* I18n changes and linting

* style issues fixed

* WIP

* useMemo and I18n fix

* Correcting the interface name
  • Loading branch information
ananya-agarwal authored Sep 3, 2024
1 parent 64dac7f commit 15c0dd5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 61 deletions.
19 changes: 11 additions & 8 deletions desktop/core/src/desktop/js/apps/admin/Metrics/Metrics.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

@import '../../components/styles/variables';

.metrics-component {
.metrics-component.antd.cuix {
background-color: $fluidx-gray-100;
padding: 0 24px 24px 24px;

.metrics-heading {
color: $fluidx-gray-700;
padding-left: $font-size-lg;
font-size: $fluidx-heading-h4-size;
line-height: $fluidx-heading-h4-line-height;
font-weight: $fluidx-heading-h4-weight;
font-size: $font-size-base;
font-weight: 500;
color: $fluidx-gray-900;
}

.metrics-filter {
Expand All @@ -38,8 +36,13 @@
}
}

.metrics-table th {
width: 30%;
.metrics-table {
th {
width: 30%;
background-color: $fluidx-gray-040;
}

margin-bottom: $font-size-base;
}

.metrics-select {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ describe('Metrics', () => {
if (secondOption) {
fireEvent.click(secondOption);
await waitFor(() => {
const headings = screen.queryAllByRole('heading', { level: 4 });
// const headings = screen.queryAllByRole('heading', { level: 4 });
const headings = screen.queryAllByText(
(_, element) =>
element?.tagName.toLowerCase() === 'span' && element?.className === 'metrics-heading'
);
expect(headings).toHaveLength(1);
});
}
Expand Down
25 changes: 14 additions & 11 deletions desktop/core/src/desktop/js/apps/admin/Metrics/Metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// limitations under the License.

import React, { useState, useEffect, useRef } from 'react';
import MetricsTable, { MetricsResponse } from './MetricsTable';
import MetricsTable, { MetricsResponse, MetricsTableProps } from './MetricsTable';
import { Spin, Input, Select, Alert } from 'antd';
import { get } from 'api/utils';
import { get } from '../../../api/utils';
import { SearchOutlined } from '@ant-design/icons';
import { i18nReact } from '../../../utils/i18nReact';
import './Metrics.scss';

const { Option } = Select;
Expand All @@ -31,7 +32,7 @@ const Metrics: React.FC = (): JSX.Element => {
const [searchQuery, setSearchQuery] = useState<string>('');
const [selectedMetric, setSelectedMetric] = useState<string>('');
const [showAllTables, setShowAllTables] = useState(true);
const [filteredMetricsData, setFilteredMetricsData] = useState<MetricsData[]>([]);
const [filteredMetricsData, setFilteredMetricsData] = useState<MetricsTableProps[]>([]);
const dropdownRef = useRef(null);

useEffect(() => {
Expand Down Expand Up @@ -86,19 +87,13 @@ const Metrics: React.FC = (): JSX.Element => {
setSearchQuery(e.target.value);
};

const { t } = i18nReact.useTranslation();

return (
<div className="cuix antd metrics-component">
<Spin spinning={loading}>
{!error && (
<>
<Input
className="metrics-filter"
placeholder="Filter metrics..."
value={searchQuery}
onChange={handleFilterInputChange}
prefix={<SearchOutlined />}
/>

<Select
className="metrics-select"
//to make sure antd class gets applied
Expand All @@ -115,6 +110,14 @@ const Metrics: React.FC = (): JSX.Element => {
</Option>
))}
</Select>

<Input
className="metrics-filter"
placeholder={t('Filter metrics...')}
value={searchQuery}
onChange={handleFilterInputChange}
prefix={<SearchOutlined />}
/>
</>
)}

Expand Down
84 changes: 43 additions & 41 deletions desktop/core/src/desktop/js/apps/admin/Metrics/MetricsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import React from 'react';
import React, { useMemo } from 'react';
import Table from 'cuix/dist/components/Table/Table';
import type { ColumnType } from 'antd/es/table';
import './Metrics.scss';
import I18n from 'utils/i18n';
import { i18nReact } from '../../../utils/i18nReact';

interface MetricsValue {
value: number;
Expand Down Expand Up @@ -74,56 +74,58 @@ interface DataSourceItem {
value: number | MetricsTime;
}

interface MetricsTableProps {
export interface MetricsTableProps {
caption: string;
dataSource: DataSourceItem[];
}

const metricLabels: { [key: string]: string } = {
'queries.number': I18n('Number of Queries'),
'requests.active': I18n('Active Requests'),
'requests.exceptions': I18n('Request Exceptions'),
'requests.response-time': I18n('Request Response Time'),
'threads.daemon': I18n('Daemon Threads'),
'threads.total': I18n('Total Threads'),
users: I18n('Users'),
'users.active': I18n('Active Users'),
'users.active.total': I18n('Total Active Users')
'queries.number': 'Number of Queries',
'requests.active': 'Active Requests',
'requests.exceptions': 'Request Exceptions',
'requests.response-time': 'Request Response Time',
'threads.daemon': 'Daemon Threads',
'threads.total': 'Total Threads',
users: 'Users',
'users.active': 'Active Users',
'users.active.total': 'Total Active Users'
};

const transformMetricNames = (dataSource: DataSourceItem[]): DataSourceItem[] =>
dataSource.map(item => ({
...item,
name: metricLabels[item.name] || item.name
}));
const metricsColumns: ColumnType<DataSourceItem>[] = [
{
title: 'Name',
dataIndex: 'name',
key: 'name'
},
{
title: 'Value',
dataIndex: 'value',
key: 'value',
render: value => (typeof value === 'number' ? value : JSON.stringify(value))
}
];

const MetricsTable: React.FC<MetricsTableProps> = ({ caption, dataSource }) => {
const transformedDataSource = transformMetricNames(dataSource);
const { t } = i18nReact.useTranslation();

const metricsColumns: ColumnType<DataSourceItem>[] = [
{
title: 'Name',
dataIndex: 'name',
key: 'name'
},
{
title: 'Value',
dataIndex: 'value',
key: 'value',
render: value => (typeof value === 'number' ? value : JSON.stringify(value))
}
];
const transformedDataSource: DataSourceItem[] = useMemo(
() =>
dataSource.map(item => ({
...item,
name: t(metricLabels[item.name]) || item.name
})),
[dataSource]
);

return (
<>
<h4 className="metrics-heading">{caption}</h4>
<Table
className="metrics-table"
dataSource={transformedDataSource}
rowKey="name"
columns={metricsColumns}
pagination={false}
/>
</>
<Table
className="metrics-table"
dataSource={transformedDataSource}
rowKey="name"
columns={metricsColumns}
pagination={false}
title={() => <span className="metrics-heading">{caption}</span>}
/>
);
};

Expand Down

0 comments on commit 15c0dd5

Please sign in to comment.