Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
2af4deed
Unverified
Commit
2af4deed
authored
Nov 25, 2020
by
kay delaney
Committed by
GitHub
Nov 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Panels/DashList: Fix order of recent dashboards (#29366)
Closes #29182
parent
0b2a6ec7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
15 deletions
+23
-15
public/app/plugins/panel/dashlist/DashList.tsx
+23
-15
No files found.
public/app/plugins/panel/dashlist/DashList.tsx
View file @
2af4deed
...
...
@@ -27,8 +27,9 @@ async function fetchDashboards(options: DashListOptions) {
}
let
recentDashboards
:
Promise
<
Dashboard
[]
>
=
Promise
.
resolve
([]);
let
dashIds
:
number
[]
=
[];
if
(
options
.
showRecentlyViewed
)
{
const
dashIds
=
take
(
impressionSrv
.
getDashboardOpened
(),
options
.
maxItems
);
dashIds
=
take
<
number
>
(
impressionSrv
.
getDashboardOpened
(),
options
.
maxItems
);
recentDashboards
=
getBackendSrv
().
search
({
dashboardIds
:
dashIds
,
limit
:
options
.
maxItems
});
}
...
...
@@ -46,24 +47,29 @@ async function fetchDashboards(options: DashListOptions) {
}
const
[
starred
,
searched
,
recent
]
=
await
Promise
.
all
([
starredDashboards
,
searchedDashboards
,
recentDashboards
]);
const
dashMap
=
starred
.
reduce
(
(
acc
,
dash
)
=>
Object
.
assign
(
acc
,
{
[
dash
.
id
]:
dash
}),
{}
as
Record
<
number
,
Dashboard
>
);
// We deliberately deal with recent dashboards first so that the order of dash IDs is preserved
let
dashMap
=
new
Map
<
number
,
Dashboard
>
();
for
(
const
dashId
of
dashIds
)
{
const
dash
=
recent
.
find
(
d
=>
d
.
id
===
dashId
);
if
(
dash
)
{
dashMap
.
set
(
dashId
,
{
...
dash
,
isRecent
:
true
});
}
}
searched
.
forEach
(
dash
=>
{
if
(
dashMap
.
has
OwnProperty
(
dash
.
id
))
{
dashMap
[
dash
.
id
]
.
isSearchResult
=
true
;
if
(
dashMap
.
has
(
dash
.
id
))
{
dashMap
.
get
(
dash
.
id
)
!
.
isSearchResult
=
true
;
}
else
{
dashMap
[
dash
.
id
]
=
{
...
dash
,
isSearchResult
:
true
}
;
dashMap
.
set
(
dash
.
id
,
{
...
dash
,
isSearchResult
:
true
})
;
}
});
recent
.
forEach
(
dash
=>
{
if
(
dashMap
.
has
OwnProperty
(
dash
.
id
))
{
dashMap
[
dash
.
id
].
isRecent
=
true
;
starred
.
forEach
(
dash
=>
{
if
(
dashMap
.
has
(
dash
.
id
))
{
dashMap
.
get
(
dash
.
id
)
!
.
isStarred
=
true
;
}
else
{
dashMap
[
dash
.
id
]
=
{
...
dash
,
isRecent
:
true
}
;
dashMap
.
set
(
dash
.
id
,
{
...
dash
,
isStarred
:
true
})
;
}
});
...
...
@@ -71,7 +77,7 @@ async function fetchDashboards(options: DashListOptions) {
}
export
function
DashList
(
props
:
PanelProps
<
DashListOptions
>
)
{
const
[
dashboards
,
setDashboards
]
=
useState
<
Record
<
number
,
Dashboard
>>
({}
);
const
[
dashboards
,
setDashboards
]
=
useState
(
new
Map
<
number
,
Dashboard
>
()
);
useEffect
(()
=>
{
fetchDashboards
(
props
.
options
).
then
(
dashes
=>
{
setDashboards
(
dashes
);
...
...
@@ -91,11 +97,13 @@ export function DashList(props: PanelProps<DashListOptions>) {
e
.
stopPropagation
();
const
isStarred
=
await
getDashboardSrv
().
starDashboard
(
dash
.
id
.
toString
(),
dash
.
isStarred
);
setDashboards
(
Object
.
assign
({},
dashboards
,
{
[
dash
.
id
]:
{
...
dash
,
isStarred
}
}));
const
updatedDashboards
=
new
Map
(
dashboards
);
updatedDashboards
.
set
(
dash
.
id
,
{
...
dash
,
isStarred
});
setDashboards
(
updatedDashboards
);
};
const
[
starredDashboards
,
recentDashboards
,
searchedDashboards
]
=
useMemo
(()
=>
{
const
dashboardList
=
Object
.
values
(
dashboards
)
;
const
dashboardList
=
[...
dashboards
.
values
()]
;
return
[
dashboardList
.
filter
(
dash
=>
dash
.
isStarred
),
dashboardList
.
filter
(
dash
=>
dash
.
isRecent
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment