Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(me): sort dashboards list #16919

Merged
merged 4 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v2.0.0-beta.5 [unreleased]

### Features

### Bug Fixes
1. [16919](https://github.com/influxdata/influxdb/pull/16919): Sort dashboards on homepage alphabetically

## v2.0.0-beta.4 [2020-02-14]

### Features
Expand Down
16 changes: 12 additions & 4 deletions ui/src/me/components/DashboardsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {EmptyState} from '@influxdata/clockface'
// Types
import {Dashboard, Organization, AppState, ResourceType} from 'src/types'
import {ComponentSize} from '@influxdata/clockface'
import {getSortedDashboardNames} from 'src/me/constants'

// Selectors
import {getOrg} from 'src/organizations/selectors'
Expand Down Expand Up @@ -51,10 +52,17 @@ class DashboardList extends PureComponent<Props> {
}
}

const mstp = (state: AppState): StateProps => ({
dashboards: getAll<Dashboard>(state, ResourceType.Dashboards),
org: getOrg(state),
})
const mstp = (state: AppState): StateProps => {
// map names and sort via a selector
const dashboards = getSortedDashboardNames(
getAll<Dashboard>(state, ResourceType.Dashboards)
)

return {
dashboards: dashboards,
org: getOrg(state),
}
}

export default connect<StateProps, {}, {}>(
mstp,
Expand Down
11 changes: 11 additions & 0 deletions ui/src/me/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash'
import {Dashboard} from 'src/types'

interface Greeting {
text: string
Expand Down Expand Up @@ -159,3 +160,13 @@ const randomGreetings: Greeting[] = [
export const generateRandomGreeting = (): Greeting => {
return _.sample(randomGreetings)
}

const sortFunc = (a: Dashboard, b: Dashboard) => {
const firstDashboard = `${a.name || ''}`.toLowerCase()
const secondDashboard = `${b.name || ''}`.toLowerCase()
return firstDashboard.localeCompare(secondDashboard)
}

export const getSortedDashboardNames = (dashboards: Dashboard[]) => {
return dashboards.sort(sortFunc)
}