Skip to content

Commit

Permalink
Minor: show metric granularity in smallest to largest order unit (#18638
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Sachin-chaurasiya authored Nov 14, 2024
1 parent cefbdf0 commit 00fbf07
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
MetricType,
UnitOfMeasurement,
} from '../../../generated/entity/data/metric';
import { getSortedOptions } from '../../../utils/MetricEntityUtils/MetricUtils';
import { ExtraInfoLabel } from '../../DataAssets/DataAssetsHeader/DataAssetsHeader.component';
import './metric-header-info.less';

Expand Down Expand Up @@ -73,18 +74,8 @@ const MetricInfoItem: FC<MetricInfoItemProps> = ({
const modiFiedLabel = label.toLowerCase().replace(/\s+/g, '-');

const sortedOptions = useMemo(
() =>
options.sort((a, b) => {
if (a.value === value) {
return -1;
}
if (b.value === value) {
return 1;
}

return 0;
}),
[options, value]
() => getSortedOptions(options, value, valueKey),
[options, value, valueKey]
);

const handleUpdate = async (value: string | undefined) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"add": "Adicionar",
"add-a-new-service": "Adicionar um Novo Serviço",
"add-an-image": "Adicionar uma imagem",
"add-column": "Add Column",
"add-custom-entity-property": "Adicionar Propriedade Personalizada {{entity}}",
"add-deploy": "Adicionar & Implementar",
"add-entity": "Adicionar {{entity}}",
Expand Down Expand Up @@ -116,6 +117,7 @@
"auto-pii-confidence-score": "Pontuação de Confiança Automática PII",
"auto-tag-pii-uppercase": "Etiqueta Automática PII",
"automatically-generate": "Gerar Automaticamente",
"average-daily-active-users-on-the-platform": "Average Daily Active Users on the Platform",
"average-session": "Tempo Médio de Sessão",
"awaiting-status": "Aguardando status",
"aws-access-key-id": "ID da Chave de Acesso AWS",
Expand Down Expand Up @@ -144,6 +146,7 @@
"cancel": "Cancelar",
"category": "Category",
"category-plural": "Categorias",
"certification": "Certification",
"change-entity": "Mudar {{entity}}",
"change-parent-entity": "Change Parent {{entity}}",
"chart": "Gráfico",
Expand Down Expand Up @@ -181,6 +184,7 @@
"collection-plural": "Collections",
"color": "Cor",
"column": "Coluna",
"column-description": "Column Description",
"column-entity": "Coluna {{entity}}",
"column-level-lineage": "Column Level Lineage",
"column-lowercase": "coluna",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"add": "เพิ่ม",
"add-a-new-service": "เพิ่มบริการใหม่",
"add-an-image": "เพิ่มภาพ",
"add-column": "Add Column",
"add-custom-entity-property": "เพิ่มคุณสมบัติเช่น {{entity}}",
"add-deploy": "เพิ่ม & เรียกใช้",
"add-entity": "เพิ่ม {{entity}}",
Expand Down Expand Up @@ -116,6 +117,7 @@
"auto-pii-confidence-score": "คะแนนความมั่นใจ PII อัตโนมัติ",
"auto-tag-pii-uppercase": "แท็ก PII อัตโนมัติ",
"automatically-generate": "สร้างโดยอัตโนมัติ",
"average-daily-active-users-on-the-platform": "Average Daily Active Users on the Platform",
"average-session": "เวลาเซสชันเฉลี่ย",
"awaiting-status": "รอสถานะ",
"aws-access-key-id": "AWS Access Key ID",
Expand Down Expand Up @@ -144,6 +146,7 @@
"cancel": "ยกเลิก",
"category": "หมวดหมู่",
"category-plural": "หมวดหมู่หลายรายการ",
"certification": "Certification",
"change-entity": "เปลี่ยน {{entity}}",
"change-parent-entity": "เปลี่ยนผู้ปกครอง {{entity}}",
"chart": "กราฟ",
Expand Down Expand Up @@ -181,6 +184,7 @@
"collection-plural": "การรวบรวมหลายรายการ",
"color": "สี",
"column": "คอลัมน์",
"column-description": "Column Description",
"column-entity": "คอลัมน์ {{entity}}",
"column-level-lineage": "ลำดับชั้นของคอลัมน์",
"column-lowercase": "คอลัมน์",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { UnitOfMeasurement } from '../../generated/entity/data/metric';
import { getSortedOptions } from './MetricUtils';

describe('getSortedOptions', () => {
it('should sort options by granularity order if valueKey is granularity', () => {
const options = [
{ label: 'Second', value: 'second', key: '1' },
{ label: 'Minute', value: 'minute', key: '2' },
{ label: 'Hour', value: 'hour', key: '3' },
{ label: 'Day', value: 'day', key: '4' },
{ label: 'Week', value: 'week', key: '5' },
{ label: 'Month', value: 'month', key: '6' },
{ label: 'Quarter', value: 'quarter', key: '7' },
{ label: 'Year', value: 'year', key: '8' },
];
const value = 'day';
const valueKey = 'granularity';

const result = getSortedOptions(options, value, valueKey);

expect(result).toEqual([
{ label: 'Day', value: 'day', key: '4' },
{ label: 'Second', value: 'second', key: '1' },
{ label: 'Minute', value: 'minute', key: '2' },
{ label: 'Hour', value: 'hour', key: '3' },
{ label: 'Week', value: 'week', key: '5' },
{ label: 'Month', value: 'month', key: '6' },
{ label: 'Quarter', value: 'quarter', key: '7' },
{ label: 'Year', value: 'year', key: '8' },
]);
});

it('should sort options by default order if valueKey is not granularity', () => {
const options = Object.values(UnitOfMeasurement).map(
(unitOfMeasurement) => ({
key: unitOfMeasurement,
label: unitOfMeasurement,
value: unitOfMeasurement,
})
);
const value = 'SIZE';
const valueKey = 'unitOfMeasurement';

const result = getSortedOptions(options, value, valueKey);

expect(result).toEqual([
{ key: 'SIZE', label: 'SIZE', value: 'SIZE' },
{ key: 'COUNT', label: 'COUNT', value: 'COUNT' },
{ key: 'DOLLARS', label: 'DOLLARS', value: 'DOLLARS' },
{ key: 'EVENTS', label: 'EVENTS', value: 'EVENTS' },
{ key: 'PERCENTAGE', label: 'PERCENTAGE', value: 'PERCENTAGE' },
{ key: 'REQUESTS', label: 'REQUESTS', value: 'REQUESTS' },
{ key: 'TIMESTAMP', label: 'TIMESTAMP', value: 'TIMESTAMP' },
{ key: 'TRANSACTIONS', label: 'TRANSACTIONS', value: 'TRANSACTIONS' },
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Metric, MetricGranularity } from '../../generated/entity/data/metric';

const granularityOrder = [
MetricGranularity.Second,
MetricGranularity.Minute,
MetricGranularity.Hour,
MetricGranularity.Day,
MetricGranularity.Week,
MetricGranularity.Month,
MetricGranularity.Quarter,
MetricGranularity.Year,
];

export const getSortedOptions = (
options: {
label: string;
value: string;
key: string;
}[],
value: string | undefined,
valueKey: keyof Metric
) => {
return options.sort((a, b) => {
if (a.value === value) {
return -1;
}
if (b.value === value) {
return 1;
}

return valueKey === 'granularity'
? granularityOrder.indexOf(a.value as MetricGranularity) -
granularityOrder.indexOf(b.value as MetricGranularity)
: 0;
});
};

0 comments on commit 00fbf07

Please sign in to comment.