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
c436cee5
Unverified
Commit
c436cee5
authored
1 year ago
by
Ryan Laurie
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Sort dashboard cards for mobile (#32185)
* sort dashboard cards for mobile * unit test sorting logic
parent
d7968721
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/dashboard/components/grid/utils.js
+13
-1
13 additions, 1 deletion
frontend/src/metabase/dashboard/components/grid/utils.js
frontend/src/metabase/dashboard/components/grid/utils.unit.spec.js
+36
-0
36 additions, 0 deletions
...src/metabase/dashboard/components/grid/utils.unit.spec.js
with
49 additions
and
1 deletion
frontend/src/metabase/dashboard/components/grid/utils.js
+
13
−
1
View file @
c436cee5
...
...
@@ -5,13 +5,25 @@ function sumVerticalSpace(layout) {
return
layout
.
reduce
((
sum
,
current
)
=>
sum
+
current
.
h
,
0
);
}
export
function
sortCardsForMobile
(
a
,
b
)
{
const
yDiff
=
a
.
y
-
b
.
y
;
// sort by y position first
if
(
yDiff
!==
0
)
{
return
yDiff
;
}
// for items on the same row, sort by x position
return
a
.
x
-
b
.
x
;
}
export
function
generateMobileLayout
({
desktopLayout
,
defaultCardHeight
,
heightByDisplayType
=
{},
})
{
const
mobile
=
[];
desktopLayout
.
forEach
(
item
=>
{
desktopLayout
.
sort
(
sortCardsForMobile
).
forEach
(
item
=>
{
const
card
=
item
.
dashcard
.
card
;
const
height
=
heightByDisplayType
[
card
.
display
]
||
defaultCardHeight
;
mobile
.
push
({
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/dashboard/components/grid/utils.unit.spec.js
0 → 100644
+
36
−
0
View file @
c436cee5
import
{
sortCardsForMobile
}
from
"
./utils
"
;
describe
(
"
Dashcard > grid > utils
"
,
()
=>
{
describe
(
"
sortCardsForMobile
"
,
()
=>
{
it
(
"
should sort cards by y position first
"
,
()
=>
{
const
a
=
{
id
:
"
top
"
,
y
:
1
,
x
:
3
};
const
b
=
{
id
:
"
middle
"
,
y
:
2
,
x
:
2
};
const
c
=
{
id
:
"
bottom
"
,
y
:
3
,
x
:
1
};
const
result
=
[
b
,
a
,
c
].
sort
(
sortCardsForMobile
);
expect
(
result
).
toEqual
([
a
,
b
,
c
]);
});
it
(
"
should sort cards by x position if y position is the same
"
,
()
=>
{
const
a
=
{
id
:
"
left
"
,
y
:
5
,
x
:
1
};
const
b
=
{
id
:
"
middle
"
,
y
:
5
,
x
:
2
};
const
c
=
{
id
:
"
right
"
,
y
:
5
,
x
:
3
};
const
result
=
[
c
,
a
,
b
].
sort
(
sortCardsForMobile
);
expect
(
result
).
toEqual
([
a
,
b
,
c
]);
});
it
(
"
should sort cards by x and y positions
"
,
()
=>
{
const
a
=
{
id
:
"
top
"
,
y
:
1
,
x
:
3
};
const
b
=
{
id
:
"
middle
"
,
y
:
2
,
x
:
2
};
const
c
=
{
id
:
"
bottom
"
,
y
:
3
,
x
:
1
};
const
d
=
{
id
:
"
left
"
,
y
:
5
,
x
:
1
};
const
e
=
{
id
:
"
middle
"
,
y
:
5
,
x
:
2
};
const
f
=
{
id
:
"
right
"
,
y
:
5
,
x
:
3
};
const
result
=
[
f
,
d
,
c
,
a
,
b
,
e
].
sort
(
sortCardsForMobile
);
expect
(
result
).
toEqual
([
a
,
b
,
c
,
d
,
e
,
f
]);
});
});
});
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