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
e27901d8
Unverified
Commit
e27901d8
authored
2 years ago
by
Gustavo Saiani
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Simplify DimensionList component (#25041)
parent
ab043137
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/metabase/query_builder/components/DimensionList.jsx
+34
-34
34 additions, 34 deletions
...d/src/metabase/query_builder/components/DimensionList.jsx
with
34 additions
and
34 deletions
frontend/src/metabase/query_builder/components/DimensionList.jsx
+
34
−
34
View file @
e27901d8
...
...
@@ -31,27 +31,29 @@ export default class DimensionList extends Component {
};
UNSAFE_componentWillMount
()
{
this
.
_
updateSections
(
this
.
props
.
sections
);
this
.
updateSections
(
this
.
props
.
sections
);
}
UNSAFE_componentWillReceiveProps
(
nextProps
)
{
if
(
this
.
props
.
sections
!==
nextProps
.
sections
)
{
this
.
_
updateSections
(
nextProps
.
sections
);
this
.
updateSections
(
nextProps
.
sections
);
}
}
_updateSections
(
sections
)
{
updateSections
(
sections
=
[])
{
this
.
setState
({
sections
:
(
sections
||
[])
.
map
(
section
=>
({
sections
:
sections
.
map
(
section
=>
({
...
section
,
items
:
section
.
items
.
map
(
item
=>
({
...
item
,
name
:
item
.
name
||
(
item
.
dimension
&&
item
.
dimension
.
displayName
()
)
,
icon
:
item
.
icon
||
(
item
.
dimension
&&
item
.
dimension
.
icon
()
)
,
name
:
item
.
name
||
item
.
dimension
?
.
displayName
(),
icon
:
item
.
icon
||
item
.
dimension
?
.
icon
(),
})),
})),
});
}
_
getDimensions
()
{
getDimensions
()
{
return
(
this
.
props
.
dimensions
||
(
this
.
props
.
dimension
?
[
this
.
props
.
dimension
]
:
[])
...
...
@@ -59,20 +61,19 @@ export default class DimensionList extends Component {
}
itemIsSelected
=
item
=>
{
const
dimensions
=
this
.
_getDimensions
();
const
{
dimension
}
=
item
;
const
dimensions
=
this
.
getDimensions
();
return
(
item
.
dimension
&&
_
.
any
(
dimensions
,
d
=>
{
// sometimes `dimension` has a join-alias and `d` doesn't -- with/without is equivalent in this scenario
return
d
.
isSameBaseDimension
(
dimension
.
withoutJoinAlias
());
_
.
any
(
dimensions
,
dimension
=>
{
// sometimes `item.dimension` has a join-alias and `dimension` doesn't
// with/without is equivalent in this scenario
return
dimension
.
isSameBaseDimension
(
item
.
dimension
.
withoutJoinAlias
());
})
);
};
renderItemExtra
=
(
item
,
itemIndex
,
isSelected
)
=>
{
const
{
dimension
,
enableSubDimensions
,
preventNumberSubDimensions
,
onAddDimension
,
...
...
@@ -84,28 +85,26 @@ export default class DimensionList extends Component {
const
subDimensions
=
enableSubDimensions
&&
item
.
dimension
&&
// Do not display sub dimension if this is an FK (metabase#16787)
!
item
.
dimension
.
field
().
isFK
()
&&
!
item
.
dimension
?
.
field
().
isFK
()
&&
!
surpressSubDimensions
&&
item
.
dimension
.
dimensions
();
const
multiSelect
=
!!
(
onAddDimension
||
onRemoveDimension
);
const
sectionDimension
=
dimension
?
dimension
const
sectionDimension
=
this
.
props
.
dimension
?
this
.
props
.
dimension
:
_
.
find
(
this
.
_
getDimensions
(),
d
=>
d
.
field
()
===
item
.
dimension
.
field
(),
this
.
getDimensions
(),
d
imension
=>
dimension
.
field
()
===
item
.
dimension
.
field
(),
);
return
(
<
div
className
=
"Field-extra flex align-center"
>
{
/* {item.segment && this.renderSegmentTooltip(item.segment)} */
}
{
item
.
dimension
&&
item
.
dimension
.
tag
&&
(
{
item
.
dimension
?.
tag
&&
(
<
span
className
=
"h5 text-light px1"
>
{
item
.
dimension
.
tag
}
</
span
>
)
}
{
subDimensions
&&
subDimensions
.
length
>
0
?
(
{
subDimensions
?
.
length
>
0
?
(
<
PopoverWithTrigger
className
=
{
this
.
props
.
className
}
hasArrow
=
{
false
}
...
...
@@ -160,11 +159,12 @@ export default class DimensionList extends Component {
};
renderSubDimensionTrigger
(
otherDimension
,
multiSelect
)
{
const
dimensions
=
this
.
_
getDimensions
();
const
dimensions
=
this
.
getDimensions
();
const
subDimension
=
_
.
find
(
dimensions
,
d
=>
d
.
isSameBaseDimension
(
otherDimension
))
||
otherDimension
.
defaultDimension
();
const
name
=
subDimension
?
subDimension
.
subTriggerDisplayName
()
:
null
;
_
.
find
(
dimensions
,
dimension
=>
dimension
.
isSameBaseDimension
(
otherDimension
),
)
||
otherDimension
.
defaultDimension
();
const
name
=
subDimension
?.
subTriggerDisplayName
()
??
null
;
return
(
<
FieldListGroupingTrigger
...
...
@@ -177,7 +177,7 @@ export default class DimensionList extends Component {
);
}
_
getDimensionFromItem
(
item
)
{
getDimensionFromItem
(
item
)
{
const
{
enableSubDimensions
,
useOriginalDimension
,
...
...
@@ -211,23 +211,23 @@ export default class DimensionList extends Component {
// ensure if we select the same item we don't reset the subdimension
onChangeDimension
(
dimension
,
item
);
}
else
if
(
item
.
dimension
)
{
onChangeDimension
(
this
.
_
getDimensionFromItem
(
item
),
item
);
onChangeDimension
(
this
.
getDimensionFromItem
(
item
),
item
);
}
else
if
(
onChangeOther
)
{
onChangeOther
(
item
);
}
};
handleAdd
=
item
=>
{
const
d
=
this
.
_
getDimensionFromItem
(
item
);
if
(
d
&&
this
.
props
.
onAddDimension
)
{
this
.
props
.
onAddDimension
(
d
,
item
);
const
d
imension
=
this
.
getDimensionFromItem
(
item
);
if
(
d
imension
&&
this
.
props
.
onAddDimension
)
{
this
.
props
.
onAddDimension
(
d
imension
,
item
);
}
};
handleRemove
=
item
=>
{
const
d
=
this
.
_
getDimensionFromItem
(
item
);
if
(
d
&&
this
.
props
.
onRemoveDimension
)
{
this
.
props
.
onRemoveDimension
(
d
,
item
);
const
d
imension
=
this
.
getDimensionFromItem
(
item
);
if
(
d
imension
&&
this
.
props
.
onRemoveDimension
)
{
this
.
props
.
onRemoveDimension
(
d
imension
,
item
);
}
};
...
...
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