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
a9331949
Commit
a9331949
authored
7 years ago
by
Atte Keinänen
Browse files
Options
Downloads
Patches
Plain Diff
Extract add button to a reusable component
parent
adf8d62b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/components/AddButton.jsx
+29
-0
29 additions, 0 deletions
frontend/src/metabase/components/AddButton.jsx
frontend/src/metabase/query_builder/components/CardEditor.jsx
+10
-30
10 additions, 30 deletions
...tend/src/metabase/query_builder/components/CardEditor.jsx
with
39 additions
and
30 deletions
frontend/src/metabase/components/AddButton.jsx
0 → 100644
+
29
−
0
View file @
a9331949
import
React
,
{
Component
}
from
"
react
"
;
import
IconBorder
from
"
metabase/components/IconBorder
"
;
import
Icon
from
"
metabase/components/Icon
"
;
const
AddButton
=
({
text
,
onClick
,
targetRefName
})
=>
{
const
addIcon
=
<
IconBorder
borderRadius
=
"3px"
ref
=
{
targetRefName
}
>
<
Icon
name
=
"add"
size
=
{
14
}
/>
</
IconBorder
>;
let
className
=
"
AddButton text-grey-2 text-bold flex align-center text-grey-4-hover cursor-pointer no-decoration transition-color
"
;
if
(
onClick
)
{
return
(
<
a
className
=
{
className
}
onClick
=
{
onClick
}
>
{
text
&&
<
span
className
=
"mr1"
>
{
text
}
</
span
>
}
{
addIcon
}
</
a
>
);
}
else
{
return
(
<
span
className
=
{
className
}
>
{
text
&&
<
span
className
=
"mr1"
>
{
text
}
</
span
>
}
{
addIcon
}
</
span
>
);
}
};
export
default
AddButton
;
This diff is collapsed.
Click to expand it.
frontend/src/metabase/query_builder/components/CardEditor.jsx
+
10
−
30
View file @
a9331949
...
...
@@ -16,6 +16,7 @@ import Query from "metabase/lib/query";
import
cx
from
"
classnames
"
;
import
_
from
"
underscore
"
;
import
AddButton
from
"
metabase/components/AddButton
"
;
export
default
class
CardEditor
extends
Component
{
...
...
@@ -51,33 +52,6 @@ export default class CardEditor extends Component {
supportMultipleAggregations
:
true
};
renderAdd
(
text
,
onClick
,
targetRefName
)
{
let
className
=
"
AddButton text-grey-2 text-bold flex align-center text-grey-4-hover cursor-pointer no-decoration transition-color
"
;
if
(
onClick
)
{
return
(
<
a
className
=
{
className
}
onClick
=
{
onClick
}
>
{
text
&&
<
span
className
=
"mr1"
>
{
text
}
</
span
>
}
{
this
.
renderAddIcon
(
targetRefName
)
}
</
a
>
);
}
else
{
return
(
<
span
className
=
{
className
}
>
{
text
&&
<
span
className
=
"mr1"
>
{
text
}
</
span
>
}
{
this
.
renderAddIcon
(
targetRefName
)
}
</
span
>
);
}
}
renderAddIcon
(
targetRefName
)
{
return
(
<
IconBorder
borderRadius
=
"3px"
ref
=
{
targetRefName
}
>
<
Icon
name
=
"add"
size
=
{
14
}
/>
</
IconBorder
>
)
}
renderFilters
()
{
if
(
!
this
.
props
.
features
.
filter
)
return
;
...
...
@@ -101,11 +75,17 @@ export default class CardEditor extends Component {
}
if
(
Query
.
canAddFilter
(
this
.
props
.
datasetQuery
.
query
))
{
addFilterButton
=
this
.
renderAdd
((
filterList
?
null
:
"
Add filters to narrow your answer
"
),
null
,
"
addFilterTarget
"
);
addFilterButton
=
<
AddButton
text
=
{
filterList
?
null
:
"
Add filters to narrow your answer
"
}
targetRefName
=
"addFilterTarget"
/>
}
}
else
{
enabled
=
false
;
addFilterButton
=
this
.
renderAdd
(
"
Add filters to narrow your answer
"
,
null
,
"
addFilterTarget
"
);
addFilterButton
=
<
AddButton
text
=
{
"
Add filters to narrow your answer
"
}
targetRefName
=
"addFilterTarget"
/>;
}
return
(
...
...
@@ -169,7 +149,7 @@ export default class CardEditor extends Component {
customFields
=
{
Query
.
getExpressions
(
this
.
props
.
datasetQuery
.
query
)
}
updateAggregation
=
{
(
aggregation
)
=>
this
.
props
.
updateQueryAggregation
(
index
,
aggregation
)
}
removeAggregation
=
{
canRemoveAggregation
?
this
.
props
.
removeQueryAggregation
.
bind
(
null
,
index
)
:
null
}
addButton
=
{
this
.
renderAdd
(
null
)
}
addButton
=
{
<
AddButton
/>
}
/>
);
if
(
aggregations
[
index
+
1
]
!=
null
&&
aggregations
[
index
+
1
].
length
>
0
)
{
...
...
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