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

chore(alphabetize): alphabetizes dashboards in the saveas dropdown, variables in script editor, and alerts, endpoints and checks #18488

Merged
merged 2 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore(alphabetize): alphabetizes dashboards in the saveas dropdown, v…
…ariables in script editor, and alerts, endpoints and checks
  • Loading branch information
asalem1 committed Jun 12, 2020
commit 3bf9348afc4b75e0139e6f7f3d4611122fb7aedf
9 changes: 6 additions & 3 deletions ui/src/checks/components/ChecksColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {connect} from 'react-redux'

// Selectors
import {getAll} from 'src/resources/selectors'
import {sortChecksByName} from 'src/checks/selectors'
import {sortRulesByName} from 'src/notifications/rules/selectors'
import {sortEndpointsByName} from 'src/notifications/endpoints/selectors'

// Components
import CheckCards from 'src/checks/components/CheckCards'
Expand Down Expand Up @@ -105,9 +108,9 @@ const mstp = (state: AppState) => {
)

return {
checks,
rules,
endpoints,
checks: sortChecksByName(checks),
rules: sortRulesByName(rules),
endpoints: sortEndpointsByName(endpoints),
}
}

Expand Down
3 changes: 3 additions & 0 deletions ui/src/checks/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ export const getCheckIDs = (state: AppState): {[x: string]: boolean} => {
{}
)
}

export const sortChecksByName = (checks: Check[]): Check[] =>
checks.sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1))
15 changes: 14 additions & 1 deletion ui/src/dashboards/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import {get} from 'lodash'
import moment from 'moment'
import {AppState, View, Check, ViewType, TimeRange, TimeZone} from 'src/types'
import {
AppState,
Check,
Dashboard,
TimeRange,
TimeZone,
View,
ViewType,
} from 'src/types'
import {currentContext} from 'src/shared/selectors/currentContext'

// Constants
Expand Down Expand Up @@ -28,6 +36,11 @@ export const getTimeRangeWithTimezone = (state: AppState): TimeRange => {
return newTimeRange
}

export const sortDashboardByName = (dashboards: Dashboard[]): Dashboard[] =>
dashboards.sort((a, b) =>
a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1
)

// The purpose of this function is to set a user's custom time range selection
// from the local time to the same time in UTC if UTC is selected from the
// timezone dropdown. This is feature was original requested here:
Expand Down
7 changes: 6 additions & 1 deletion ui/src/dataExplorer/components/SaveAsCellForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {get, isEmpty} from 'lodash'
import {getSaveableView} from 'src/timeMachine/selectors'
import {getOrg} from 'src/organizations/selectors'
import {getAll} from 'src/resources/selectors'
import {sortDashboardByName} from 'src/dashboards/selectors'

// Components
import {Form, Input, Button, Grid} from '@influxdata/clockface'
Expand Down Expand Up @@ -234,7 +235,11 @@ const mstp = (state: AppState): StateProps => {
const org = getOrg(state)
const dashboards = getAll<Dashboard>(state, ResourceType.Dashboards)

return {dashboards, view, orgID: get(org, 'id', '')}
return {
dashboards: sortDashboardByName(dashboards),
view,
orgID: get(org, 'id', ''),
}
}

const mdtp: DispatchProps = {
Expand Down
9 changes: 8 additions & 1 deletion ui/src/notifications/endpoints/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {AppState} from 'src/types'
import {AppState, NotificationEndpoint} from 'src/types'

export const getEndpointIDs = (state: AppState): {[x: string]: boolean} => {
return state.resources.endpoints.allIDs.reduce(
(acc, id) => ({...acc, [id]: true}),
{}
)
}

export const sortEndpointsByName = (
endpoints: NotificationEndpoint[]
): NotificationEndpoint[] =>
endpoints.sort((a, b) =>
a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1
)
7 changes: 6 additions & 1 deletion ui/src/notifications/rules/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {AppState} from 'src/types'
import {AppState, NotificationRuleDraft} from 'src/types'

export const getRuleIDs = (state: AppState): {[x: string]: boolean} => {
return state.resources.rules.allIDs.reduce(
(acc, ruleID) => ({...acc, [ruleID]: true}),
{}
)
}

export const sortRulesByName = (
rules: NotificationRuleDraft[]
): NotificationRuleDraft[] =>
rules.sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1))
1 change: 1 addition & 0 deletions ui/src/variables/selectors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const getAllVariables = (
return prev
}, [])
.filter(v => !!v)
.sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1))
return vars
}

Expand Down