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
4162c2f0
Unverified
Commit
4162c2f0
authored
4 months ago
by
Oisin Coveney
Committed by
GitHub
4 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Memoize useChartSettingsSections variables (#49470)
parent
de559f49
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/metabase/visualizations/components/ChartSettings/BaseChartSettings/hooks.ts
+40
-28
40 additions, 28 deletions
...tions/components/ChartSettings/BaseChartSettings/hooks.ts
with
40 additions
and
28 deletions
frontend/src/metabase/visualizations/components/ChartSettings/BaseChartSettings/hooks.ts
+
40
−
28
View file @
4162c2f0
...
...
@@ -35,22 +35,26 @@ export const useChartSettingsSections = ({
return
sectionObj
;
},
[
widgets
]);
const
sectionNames
=
Object
.
keys
(
sections
);
// This sorts the section radio buttons.
const
sectionSortOrder
=
[
"
data
"
,
"
display
"
,
"
axes
"
,
// include all section names so any forgotten sections are sorted to the end
...
sectionNames
.
map
(
x
=>
x
.
toLowerCase
()),
];
sectionNames
.
sort
((
a
,
b
)
=>
{
const
[
aIdx
,
bIdx
]
=
[
a
,
b
].
map
(
x
=>
sectionSortOrder
.
indexOf
(
x
.
toLowerCase
()),
);
return
aIdx
-
bIdx
;
});
const
sectionNames
=
useMemo
(()
=>
{
const
names
=
Object
.
keys
(
sections
);
const
sectionSortOrder
=
[
"
data
"
,
"
display
"
,
"
axes
"
,
// include all section names so any forgotten sections are sorted to the end
...
names
.
map
(
x
=>
x
.
toLowerCase
()),
];
names
.
sort
((
a
,
b
)
=>
{
const
[
aIdx
,
bIdx
]
=
[
a
,
b
].
map
(
x
=>
sectionSortOrder
.
indexOf
(
x
.
toLowerCase
()),
);
return
aIdx
-
bIdx
;
});
return
names
;
},
[
sections
]);
const
chartSettingCurrentSection
=
useMemo
(
()
=>
...
...
@@ -61,22 +65,30 @@ export const useChartSettingsSections = ({
[
currentSection
,
sectionNames
,
sections
],
);
const
visibleWidgets
=
sections
[
chartSettingCurrentSection
]
||
[];
const
visibleWidgets
=
useMemo
(
()
=>
sections
[
chartSettingCurrentSection
]
||
[],
[
chartSettingCurrentSection
,
sections
],
);
const
currentSectionHasColumnSettings
=
visibleWidgets
.
some
(
(
widget
:
Widget
)
=>
widget
.
id
===
"
column_settings
"
,
const
currentSectionHasColumnSettings
=
useMemo
(
()
=>
visibleWidgets
.
some
((
widget
:
Widget
)
=>
widget
.
id
===
"
column_settings
"
),
[
visibleWidgets
],
);
const
showSectionPicker
=
// don't show section tabs for a single section
sectionNames
.
length
>
1
&&
// hide the section picker if the only widget is column_settings
!
(
visibleWidgets
.
length
===
1
&&
visibleWidgets
[
0
].
id
===
"
column_settings
"
&&
// and this section doesn't have that as a direct child
!
currentSectionHasColumnSettings
);
const
showSectionPicker
=
useMemo
(
()
=>
// don't show section tabs for a single section
sectionNames
.
length
>
1
&&
// hide the section picker if the only widget is column_settings
!
(
visibleWidgets
.
length
===
1
&&
visibleWidgets
[
0
].
id
===
"
column_settings
"
&&
// and this section doesn't have that as a direct child
!
currentSectionHasColumnSettings
),
[
currentSectionHasColumnSettings
,
sectionNames
.
length
,
visibleWidgets
],
);
return
{
sectionNames
,
...
...
This diff is collapsed.
Click to expand it.
Nicholas Bentley
@nbentley
mentioned in commit
c495e319
·
4 months ago
mentioned in commit
c495e319
mentioned in commit c495e319008f3c0075a37f3585fc4f1e04481373
Toggle commit list
Nicholas Bentley
@nbentley
mentioned in commit
d843caea
·
4 months ago
mentioned in commit
d843caea
mentioned in commit d843caea39f61f368aa00969c4d7cc14525bffe7
Toggle commit list
Nicholas Bentley
@nbentley
mentioned in commit
5871c7a3
·
4 months ago
mentioned in commit
5871c7a3
mentioned in commit 5871c7a30864ee9ed24f9f984ccbabe184707af2
Toggle commit list
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