Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
16c9f4ea
Unverified
Commit
16c9f4ea
authored
8 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Refactor AggregationWidget for named aggregations
parent
d41222f4
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/lib/expressions/formatter.js
+1
-1
1 addition, 1 deletion
frontend/src/metabase/lib/expressions/formatter.js
frontend/src/metabase/query_builder/components/AggregationWidget.jsx
+40
-38
40 additions, 38 deletions
...c/metabase/query_builder/components/AggregationWidget.jsx
with
41 additions
and
39 deletions
frontend/src/metabase/lib/expressions/formatter.js
+
1
−
1
View file @
16c9f4ea
...
...
@@ -15,7 +15,7 @@ export function format(expr, {
aggregations
=
VALID_AGGREGATIONS
},
parens
=
false
)
{
const
info
=
{
tableMetadata
,
customFields
,
operators
,
aggregations
};
if
(
expr
==
null
)
{
if
(
expr
==
null
||
_
.
isEqual
(
expr
,
[])
)
{
return
""
;
}
if
(
typeof
expr
===
"
number
"
)
{
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/query_builder/components/AggregationWidget.jsx
+
40
−
38
View file @
16c9f4ea
...
...
@@ -51,31 +51,26 @@ export default class AggregationWidget extends Component {
const
fieldId
=
AggregationClause
.
getField
(
aggregation
);
let
selectedAggregation
=
getAggregator
(
AggregationClause
.
getOperator
(
aggregation
));
if
(
selectedAggregation
&&
!
_
.
findWhere
(
tableMetadata
.
aggregation_options
,
{
short
:
selectedAggregation
.
short
}))
{
// if this table doesn't support the selected aggregation, prompt the user to select a different one
selectedAggregation
=
null
;
// if this table doesn't support the selected aggregation, prompt the user to select a different one
if
(
selectedAggregation
&&
_
.
findWhere
(
tableMetadata
.
aggregation_options
,
{
short
:
selectedAggregation
.
short
}))
{
return
(
<
span
className
=
"flex align-center"
>
{
selectedAggregation
.
name
.
replace
(
"
of ...
"
,
""
)
}
{
fieldId
&&
<
span
style
=
{
{
paddingRight
:
"
4px
"
,
paddingLeft
:
"
4px
"
}
}
className
=
"text-bold"
>
of
</
span
>
}
{
fieldId
&&
<
FieldName
className
=
"View-section-aggregation-target SelectionModule py1"
tableMetadata
=
{
tableMetadata
}
field
=
{
fieldId
}
fieldOptions
=
{
Query
.
getFieldOptions
(
tableMetadata
.
fields
,
true
)
}
customFieldOptions
=
{
this
.
props
.
customFields
}
/>
}
</
span
>
);
}
return
(
<
span
className
=
"View-section-aggregation QueryOption py1 mx1 flex align-center"
>
{
selectedAggregation
?
selectedAggregation
.
name
.
replace
(
"
of ...
"
,
""
)
:
"
Choose an aggregation
"
}
{
selectedAggregation
&&
fieldId
&&
<
span
style
=
{
{
paddingRight
:
"
4px
"
,
paddingLeft
:
"
4px
"
}
}
className
=
"text-bold"
>
of
</
span
>
}
{
selectedAggregation
&&
fieldId
&&
<
FieldName
className
=
"View-section-aggregation-target SelectionModule py1"
tableMetadata
=
{
tableMetadata
}
field
=
{
fieldId
}
fieldOptions
=
{
Query
.
getFieldOptions
(
tableMetadata
.
fields
,
true
)
}
customFieldOptions
=
{
this
.
props
.
customFields
}
/>
}
</
span
>
);
}
renderMetricAggregation
()
{
...
...
@@ -83,16 +78,14 @@ export default class AggregationWidget extends Component {
const
metricId
=
AggregationClause
.
getMetric
(
aggregation
);
let
selectedMetric
=
_
.
findWhere
(
tableMetadata
.
metrics
,
{
id
:
metricId
});
return
(
<
span
className
=
"View-section-aggregation QueryOption p1"
>
{
selectedMetric
?
selectedMetric
.
name
.
replace
(
"
of ...
"
,
""
)
:
"
Choose an aggregation
"
}
</
span
>
);
if
(
selectedMetric
)
{
return
selectedMetric
.
name
.
replace
(
"
of ...
"
,
""
)
}
}
renderCustomAggregation
()
{
const
{
aggregation
,
tableMetadata
,
customFields
}
=
this
.
props
;
return
(
<
span
className
=
"View-section-aggregation QueryOption p1"
>
{
aggregation
?
format
(
aggregation
,
{
tableMetadata
,
customFields
})
:
"
Choose an aggregation
"
}
</
span
>
);
return
format
(
aggregation
,
{
tableMetadata
,
customFields
});
}
renderPopover
()
{
...
...
@@ -121,20 +114,29 @@ export default class AggregationWidget extends Component {
}
render
()
{
const
{
aggregation
,
addButton
}
=
this
.
props
;
const
{
aggregation
,
addButton
,
name
}
=
this
.
props
;
if
(
aggregation
&&
aggregation
.
length
>
0
)
{
let
aggregationName
=
AggregationClause
.
isCustom
(
aggregation
)
?
this
.
renderCustomAggregation
()
:
AggregationClause
.
isMetric
(
aggregation
)
?
this
.
renderMetricAggregation
()
:
this
.
renderStandardAggregation
()
return
(
<
div
className
=
{
cx
(
"
Query-section Query-section-aggregation
"
,
{
"
selected
"
:
this
.
state
.
isOpen
})
}
>
<
div
>
<
Clearable
onClear
=
{
this
.
props
.
removeAggregation
}
>
<
div
id
=
"Query-section-aggregation"
onClick
=
{
this
.
open
}
className
=
"Query-section Query-section-aggregation cursor-pointer"
>
{
AggregationClause
.
isCustom
(
aggregation
)
?
this
.
renderCustomAggregation
()
:
AggregationClause
.
isMetric
(
aggregation
)
?
this
.
renderMetricAggregation
()
:
this
.
renderStandardAggregation
()
}
<
span
className
=
"View-section-aggregation QueryOption py1 mx1"
>
{
aggregationName
==
null
?
"
Choose an aggregation
"
:
name
?
name
:
aggregationName
}
</
span
>
</
div
>
</
Clearable
>
{
this
.
renderPopover
()
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment