From 546ff3040b0ff53190266201650de6f3c86011d2 Mon Sep 17 00:00:00 2001 From: Anton Kulyk <kuliks.anton@gmail.com> Date: Thu, 20 Jan 2022 20:51:27 +0200 Subject: [PATCH] Fix model metadata strength calculation (#19803) * Use `display_name` for metadata completeness calc * Fix unit tests --- .../src/metabase/lib/data-modeling/metadata.ts | 5 +++-- .../lib/data-modeling/metadata.unit.spec.js | 16 ++++++++-------- ...DatasetMetadataStrengthIndicator.unit.spec.js | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/frontend/src/metabase/lib/data-modeling/metadata.ts b/frontend/src/metabase/lib/data-modeling/metadata.ts index d118192e39b..2773487ce9a 100644 --- a/frontend/src/metabase/lib/data-modeling/metadata.ts +++ b/frontend/src/metabase/lib/data-modeling/metadata.ts @@ -1,6 +1,7 @@ export type FieldMetadata = { id?: number; name: string; + display_name: string; description?: string | null; semantic_type?: string | null; }; @@ -23,13 +24,13 @@ const MAX_FIELD_SCORE = 3; * @returns {number} — int between 0 and 3 */ function getFieldMetadataScore({ - name, + display_name, description, semantic_type, }: FieldMetadata): number { let score = 0; - const isNameDirty = name.includes("→") || name.includes("_"); + const isNameDirty = display_name.includes("→") || display_name.includes("_"); if (!isNameDirty) { score++; diff --git a/frontend/src/metabase/lib/data-modeling/metadata.unit.spec.js b/frontend/src/metabase/lib/data-modeling/metadata.unit.spec.js index a0020b047f9..c627c84ce22 100644 --- a/frontend/src/metabase/lib/data-modeling/metadata.unit.spec.js +++ b/frontend/src/metabase/lib/data-modeling/metadata.unit.spec.js @@ -7,8 +7,8 @@ describe("getDatasetMetadataCompletenessPercentage", () => { it("returns 0 for completely missing metadata", () => { const percent = getDatasetMetadataCompletenessPercentage([ - { name: "Created_At" }, - { name: "Products → Category" }, + { display_name: "Created_At" }, + { display_name: "Products → Category" }, ]); expect(percent).toBe(0); }); @@ -16,12 +16,12 @@ describe("getDatasetMetadataCompletenessPercentage", () => { it("returns 1 for complete metadata", () => { const percent = getDatasetMetadataCompletenessPercentage([ { - name: "Created At", + display_name: "Created At", description: "Date created", semantic_type: "DateTime", }, { - name: "Product Category", + display_name: "Product Category", description: "The name is pretty self-explaining", semantic_type: "String", }, @@ -31,9 +31,9 @@ describe("getDatasetMetadataCompletenessPercentage", () => { it("returns 0.5 for half-complete metadata", () => { const percent = getDatasetMetadataCompletenessPercentage([ - { name: "Created_At" }, + { display_name: "Created_At" }, { - name: "Product Category", + display_name: "Product Category", description: "The name is pretty self-explaining", semantic_type: "String", }, @@ -43,9 +43,9 @@ describe("getDatasetMetadataCompletenessPercentage", () => { it("returns percent value for partially complete metadata", () => { const percent = getDatasetMetadataCompletenessPercentage([ - { name: "Created_At" }, + { display_name: "Created_At" }, { - name: "Product Category", + display_name: "Product Category", semantic_type: "String", }, ]); diff --git a/frontend/src/metabase/query_builder/components/view/sidebars/DatasetManagementSection/DatasetMetadataStrengthIndicator/DatasetMetadataStrengthIndicator.unit.spec.js b/frontend/src/metabase/query_builder/components/view/sidebars/DatasetManagementSection/DatasetMetadataStrengthIndicator/DatasetMetadataStrengthIndicator.unit.spec.js index c03d92f64d2..7525a377f5f 100644 --- a/frontend/src/metabase/query_builder/components/view/sidebars/DatasetManagementSection/DatasetMetadataStrengthIndicator/DatasetMetadataStrengthIndicator.unit.spec.js +++ b/frontend/src/metabase/query_builder/components/view/sidebars/DatasetManagementSection/DatasetMetadataStrengthIndicator/DatasetMetadataStrengthIndicator.unit.spec.js @@ -17,16 +17,16 @@ function setup({ resultMetadata } = {}) { describe("DatasetMetadataStrengthIndicator", () => { const FULLY_COMPLETE_METADATA = { id: 1, - name: "ID", + display_name: "ID", description: "Well, that's an ID", semantic_type: "type/PK", }; const PARTIALLY_COMPLETE_METADATA = { id: 1, - name: "ID", + display_name: "ID", semantic_type: "type/PK", }; - const FULLY_INCOMPLETE_METADATA = { name: "CREATED_AT" }; + const FULLY_INCOMPLETE_METADATA = { display_name: "CREATED_AT" }; it("doesn't render if result metadata is not defined", () => { setup({ resultMetadata: undefined }); -- GitLab