Skip to content
Snippets Groups Projects
Unverified Commit 3b40312e authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Remove unused stuff in metabase-lib/queries/utils/description.js (#29192)

parent 53bae050
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,6 @@ import inflection from "inflection";
import { stripId } from "metabase/lib/formatting";
import * as FIELD_REF from "./field-ref";
import { FilterClause, MetricClause } from "./description.styled.tsx";
// NOTE: This doesn't support every MBQL clause, e.x. joins. It should also be moved to StructuredQuery.
......@@ -22,13 +21,16 @@ export function formatField(fieldDef, options = {}) {
// metadata available, and the server side will generate a data structure
// containing all the applicable data for formatting a user-friendly description
// of a query.
//
// TODO: This is almost 100% duplicated with code in Question.ts, find a way to
// consolidate them
// -----------------------------------------------------------------------------
export function formatTableDescription({ table }, options = {}) {
function formatTableDescription({ table }, options = {}) {
return [inflection.pluralize(table)];
}
export function formatAggregationDescription({ aggregation }, options = {}) {
function formatAggregationDescription({ aggregation }, options = {}) {
if (!aggregation || !aggregation.length) {
return [];
}
......@@ -80,21 +82,7 @@ export function formatAggregationDescription({ aggregation }, options = {}) {
);
}
export function formatBreakoutDescription({ breakout }, options = {}) {
if (!breakout || !breakout.length) {
return [];
}
return [
t`Grouped by `,
joinList(
breakout.map(b => b),
" and ",
),
];
}
export function formatFilterDescription({ filter }, options = {}) {
function formatFilterDescription({ filter }, options = {}) {
if (!filter || !filter.length) {
return [];
}
......@@ -118,34 +106,6 @@ export function formatFilterDescription({ filter }, options = {}) {
];
}
export function formatOrderByDescription(parts, options = {}) {
const orderBy = parts["order-by"];
if (!orderBy || !orderBy.length) {
return [];
}
return [
t`Sorted by `,
joinList(
orderBy.map(
field =>
field["field"] +
" " +
(field["direction"] === "asc" ? "ascending" : "descending"),
),
" and ",
),
];
}
export function formatLimitDescription({ limit }, options = {}) {
if (limit == null) {
return [];
}
return [limit, " ", inflection.inflect("row", limit)];
}
export function formatQueryDescription(parts, options = {}) {
if (!parts) {
return "";
......@@ -153,24 +113,14 @@ export function formatQueryDescription(parts, options = {}) {
options = {
jsx: false,
sections: [
"table",
"aggregation",
"breakout",
"filter",
"order-by",
"limit",
],
sections: ["table", "aggregation", "filter"],
...options,
};
const sectionFns = {
table: formatTableDescription,
aggregation: formatAggregationDescription,
breakout: formatBreakoutDescription,
filter: formatFilterDescription,
"order-by": formatOrderByDescription,
limit: formatLimitDescription,
};
// these array gymnastics are needed to support JSX formatting
......@@ -188,33 +138,6 @@ export function formatQueryDescription(parts, options = {}) {
}
}
export function getDatetimeFieldUnit(field) {
if (field && FIELD_REF.isLocalField(field)) {
const options = field[2];
if (options) {
return options["temporal-unit"];
}
}
return null;
}
export function getAggregationType(aggregation) {
return aggregation && aggregation[0];
}
export function getAggregationField(aggregation) {
return aggregation && aggregation[1];
}
export function getQueryColumn(tableMetadata, field) {
const target = FIELD_REF.getFieldTarget(field, tableMetadata);
const column = { ...target.field };
if (FIELD_REF.isLocalField(field) && getDatetimeFieldUnit(field)) {
column.unit = getDatetimeFieldUnit(field);
}
return column;
}
export function joinList(list, joiner) {
return _.flatten(
list.map((l, i) => (i === list.length - 1 ? [l] : [l, joiner])),
......
......@@ -303,7 +303,7 @@
"Rewrite various 'syntatic sugar' filter clauses like `:time-interval` and `:inside` as simpler, logically
equivalent clauses. This can be used to simplify the number of filter clauses that need to be supported by anything
that needs to enumerate all the possible filter types (such as driver query processor implementations, or the
implementation `negate-filter-clause` below.)"
implementation [[negate-filter-clause]] below.)"
[filter-clause :- mbql.s/Filter]
(-> filter-clause
desugar-current-relative-datetime
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment