From 654ad6fdcd26be4e4fef40c6a24b2fdab1923ce2 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Mon, 11 Jun 2018 16:13:45 -0700 Subject: [PATCH] Rename queries to queryParams for clarity --- ui/src/dashboards/actions/index.ts | 101 ++++++++++-------- ui/src/dashboards/containers/DashboardPage.js | 4 +- ui/src/dashboards/reducers/ui.js | 4 +- ui/src/dashboards/utils/tempVars.ts | 34 +++--- ui/src/shared/middleware/queryStringConfig.js | 4 +- ui/src/types/index.ts | 9 +- ui/src/types/tempVars.ts | 2 +- 7 files changed, 87 insertions(+), 71 deletions(-) diff --git a/ui/src/dashboards/actions/index.ts b/ui/src/dashboards/actions/index.ts index e01f5e34f0..800dca2537 100644 --- a/ui/src/dashboards/actions/index.ts +++ b/ui/src/dashboards/actions/index.ts @@ -24,8 +24,8 @@ import {notify} from 'src/shared/actions/notifications' import {errorThrown} from 'src/shared/actions/errors' import { - generateURLQueriesFromTempVars, - findUpdatedTempVarsInURLQuery, + generateURLQueryParamsFromTempVars, + findUpdatedTempVarsInURLQueryParams, findInvalidTempVarsInURLQuery, } from 'src/dashboards/utils/tempVars' import {validTimeRange, validAbsoluteTimeRange} from 'src/dashboards/utils/time' @@ -61,7 +61,7 @@ import { Cell, Source, Template, - URLQueries, + URLQueryParams, } from 'src/types' import {CellType, DashboardName} from 'src/types/dashboard' @@ -314,17 +314,17 @@ interface TemplateVariablesSelectedByNameAction { type: 'TEMPLATE_VARIABLES_SELECTED_BY_NAME' payload: { dashboardID: number - queries: URLQueries + queryParams: URLQueryParams } } export const templateVariablesSelectedByName = ( dashboardID: number, - queries: URLQueries + queryParams: URLQueryParams ): TemplateVariablesSelectedByNameAction => ({ type: 'TEMPLATE_VARIABLES_SELECTED_BY_NAME', payload: { dashboardID, - queries, + queryParams, }, }) @@ -654,17 +654,17 @@ export const hydrateTempVarValuesAsync = ( const removeNullValues = obj => _.pickBy(obj, o => o) -export const syncURLQueryFromQueriesObject = ( +export const syncURLQueryParamsFromQueryParamsObject = ( location: Location, - updatedURLQueries: URLQueries, - deletedURLQueries: URLQueries = {} + updatedURLQueryParams: URLQueryParams, + deletedURLQueryParams: URLQueryParams = {} ) => (dispatch): void => { const updatedLocationQuery = removeNullValues({ ...location.query, - ...updatedURLQueries, + ...updatedURLQueryParams, }) - _.each(deletedURLQueries, (__, k) => { + _.each(deletedURLQueryParams, (__, k) => { delete updatedLocationQuery[k] }) @@ -683,28 +683,30 @@ export const syncURLQueryFromTempVars = ( location: Location, tempVars: Template[], deletedTempVars: Template[] = [], - urlQueriesTimeRanges: URLQueries = {} + urlQueryParamsTimeRanges: URLQueryParams = {} ) => (dispatch): void => { - const updatedURLQueries = generateURLQueriesFromTempVars(tempVars) - const deletedURLQueries = generateURLQueriesFromTempVars(deletedTempVars) + const updatedURLQueryParams = generateURLQueryParamsFromTempVars(tempVars) + const deletedURLQueryParams = generateURLQueryParamsFromTempVars( + deletedTempVars + ) - const updatedURLQueriesWithTimeRange = { - ...updatedURLQueries, - ...urlQueriesTimeRanges, + const updatedURLQueryParamsWithTimeRange = { + ...updatedURLQueryParams, + ...urlQueryParamsTimeRanges, } dispatch( - syncURLQueryFromQueriesObject( + syncURLQueryParamsFromQueryParamsObject( location, - updatedURLQueriesWithTimeRange, - deletedURLQueries + updatedURLQueryParamsWithTimeRange, + deletedURLQueryParams ) ) } -const syncDashboardTempVarsFromURLQueries = ( +const syncDashboardTempVarsFromURLQueryParams = ( dashboardID: number, - urlQueries: URLQueries + urlQueryParams: URLQueryParams ) => (dispatch, getState): void => { const { dashboardUI, @@ -714,30 +716,30 @@ const syncDashboardTempVarsFromURLQueries = ( // viewers are not currently allowed to select temp vars and/or use overrides if (isUsingAuth && !isUserAuthorized(me.role, EDITOR_ROLE)) { - const urlQueryTempVarsWithUpdatedValues = findUpdatedTempVarsInURLQuery( + const urlQueryParamsTempVarsWithUpdatedValues = findUpdatedTempVarsInURLQueryParams( dashboard.templates, - urlQueries + urlQueryParams ) - if (urlQueryTempVarsWithUpdatedValues.length) { + if (urlQueryParamsTempVarsWithUpdatedValues.length) { dispatch(notify(notifyViewerUnauthorizedToSetTempVars())) return } } - const urlQueryTempVarsWithInvalidValues = findInvalidTempVarsInURLQuery( + const urlQueryParamsTempVarsWithInvalidValues = findInvalidTempVarsInURLQuery( dashboard.templates, - urlQueries + urlQueryParams ) - urlQueryTempVarsWithInvalidValues.forEach(invalidURLQuery => { + urlQueryParamsTempVarsWithInvalidValues.forEach(invalidURLQuery => { dispatch(notify(notifyInvalidTempVarValueInURLQuery(invalidURLQuery))) }) - dispatch(templateVariablesSelectedByName(dashboardID, urlQueries)) + dispatch(templateVariablesSelectedByName(dashboardID, urlQueryParams)) } -const syncDashboardTimeRangeFromURLQueries = ( +const syncDashboardTimeRangeFromURLQueryParams = ( dashboardID: number, - urlQueries: URLQueries, + urlQueryParams: URLQueryParams, location: Location ) => (dispatch, getState): void => { const { @@ -747,12 +749,12 @@ const syncDashboardTimeRangeFromURLQueries = ( const dashboard = dashboards.find(d => d.id === dashboardID) const timeRangeFromQueries = { - lower: urlQueries.lower, - upper: urlQueries.upper, + lower: urlQueryParams.lower, + upper: urlQueryParams.upper, } const zoomedTimeRangeFromQueries = { - lower: urlQueries.zoomedLower, - upper: urlQueries.zoomedUpper, + lower: urlQueryParams.zoomedLower, + upper: urlQueryParams.zoomedUpper, } let validatedTimeRange = validTimeRange(timeRangeFromQueries) @@ -774,12 +776,12 @@ const syncDashboardTimeRangeFromURLQueries = ( ) if ( !validatedZoomedTimeRange.lower && - (urlQueries.zoomedLower || urlQueries.zoomedUpper) + (urlQueryParams.zoomedLower || urlQueryParams.zoomedUpper) ) { dispatch(notify(notifyInvalidZoomedTimeRangeValueInURLQuery())) } dispatch(setZoomedTimeRange(validatedZoomedTimeRange)) - const urlQueryTimeRanges = { + const urlQueryParamsTimeRanges = { lower: validatedTimeRange.lower, upper: validatedTimeRange.upper, zoomedLower: validatedZoomedTimeRange.lower, @@ -790,19 +792,23 @@ const syncDashboardTimeRangeFromURLQueries = ( location, dashboard.templates, [], - urlQueryTimeRanges + urlQueryParamsTimeRanges ) ) } -const syncDashboardFromURLQueries = ( +const syncDashboardFromURLQueryParams = ( dashboardID: number, location: Location ) => (dispatch): void => { - const urlQueries = queryString.parse(window.location.search) - dispatch(syncDashboardTempVarsFromURLQueries(dashboardID, urlQueries)) + const urlQueryParams = queryString.parse(window.location.search) + dispatch(syncDashboardTempVarsFromURLQueryParams(dashboardID, urlQueryParams)) dispatch( - syncDashboardTimeRangeFromURLQueries(dashboardID, urlQueries, location) + syncDashboardTimeRangeFromURLQueryParams( + dashboardID, + urlQueryParams, + location + ) ) } @@ -826,7 +832,7 @@ export const getDashboardWithHydratedAndSyncedTempVarsAsync = ( source ) - dispatch(syncDashboardFromURLQueries(+dashboardID, location)) + dispatch(syncDashboardFromURLQueryParams(+dashboardID, location)) } export const setZoomedTimeRangeAsync = ( @@ -834,9 +840,14 @@ export const setZoomedTimeRangeAsync = ( location: Location ) => async (dispatch): Promise => { dispatch(setZoomedTimeRange(zoomedTimeRange)) - const urlQueryZoomedTimeRange = { + const urlQueryParamsZoomedTimeRange = { zoomedLower: zoomedTimeRange.lower, zoomedUpper: zoomedTimeRange.upper, } - dispatch(syncURLQueryFromQueriesObject(location, urlQueryZoomedTimeRange)) + dispatch( + syncURLQueryParamsFromQueryParamsObject( + location, + urlQueryParamsZoomedTimeRange + ) + ) } diff --git a/ui/src/dashboards/containers/DashboardPage.js b/ui/src/dashboards/containers/DashboardPage.js index 22a966f1b4..5cfbaffbcc 100644 --- a/ui/src/dashboards/containers/DashboardPage.js +++ b/ui/src/dashboards/containers/DashboardPage.js @@ -224,7 +224,7 @@ class DashboardPage extends Component { format: FORMAT_INFLUXQL, }) - dashboardActions.syncURLQueryFromQueriesObject(location, { + dashboardActions.syncURLQueryParamsFromQueryParamsObject(location, { lower: timeRange.lower, upper: timeRange.upper, }) @@ -302,7 +302,7 @@ class DashboardPage extends Component { const updatedQueryParam = { [strippedTempVar]: value.value, } - dashboardActions.syncURLQueryFromQueriesObject( + dashboardActions.syncURLQueryParamsFromQueryParamsObject( location, updatedQueryParam ) diff --git a/ui/src/dashboards/reducers/ui.js b/ui/src/dashboards/reducers/ui.js index 6aba350916..dcc585ecd0 100644 --- a/ui/src/dashboards/reducers/ui.js +++ b/ui/src/dashboards/reducers/ui.js @@ -174,12 +174,12 @@ const ui = (state = initialState, action) => { } case 'TEMPLATE_VARIABLES_SELECTED_BY_NAME': { - const {dashboardID, queries} = action.payload + const {dashboardID, queryParams} = action.payload const newDashboards = state.dashboards.map( oldDashboard => oldDashboard.id === dashboardID - ? applyDashboardTempVarOverrides(oldDashboard, queries) + ? applyDashboardTempVarOverrides(oldDashboard, queryParams) : oldDashboard ) diff --git a/ui/src/dashboards/utils/tempVars.ts b/ui/src/dashboards/utils/tempVars.ts index 3d5466ec2f..f7c82c0b74 100644 --- a/ui/src/dashboards/utils/tempVars.ts +++ b/ui/src/dashboards/utils/tempVars.ts @@ -6,7 +6,7 @@ import { Template, TemplateQuery, TemplateValue, - URLQueries, + URLQueryParams, } from 'src/types' import {TemplateUpdate} from 'src/types/tempVars' @@ -82,19 +82,19 @@ export const makeQueryForTemplate = ({ export const stripTempVar = (tempVarName: string): string => tempVarName.substr(1, tempVarName.length - 2) -export const generateURLQueriesFromTempVars = ( +export const generateURLQueryParamsFromTempVars = ( tempVars: Template[] -): URLQueries => { - const urlQueries = {} +): URLQueryParams => { + const urlQueryParams = {} tempVars.forEach(({tempVar, values}) => { const selected = values.find(value => value.selected === true) const strippedTempVar = stripTempVar(tempVar) - urlQueries[strippedTempVar] = selected.value + urlQueryParams[strippedTempVar] = selected.value }) - return urlQueries + return urlQueryParams } export const isValidTempVarOverride = ( @@ -104,7 +104,7 @@ export const isValidTempVarOverride = ( const reconcileTempVarsWithOverrides = ( currentTempVars: Template[], - tempVarOverrides: URLQueries + tempVarOverrides: URLQueryParams ): Template[] => { if (!tempVarOverrides) { return currentTempVars @@ -139,7 +139,7 @@ const reconcileTempVarsWithOverrides = ( export const applyDashboardTempVarOverrides = ( dashboard: Dashboard, - tempVarOverrides: URLQueries + tempVarOverrides: URLQueryParams ): Dashboard => ({ ...dashboard, templates: reconcileTempVarsWithOverrides( @@ -148,12 +148,12 @@ export const applyDashboardTempVarOverrides = ( ), }) -export const findUpdatedTempVarsInURLQuery = ( +export const findUpdatedTempVarsInURLQueryParams = ( tempVars: Template[], - urlQueries: URLQueries + urlQueryParams: URLQueryParams ): TemplateUpdate[] => { - const urlQueryTempVarsWithInvalidValues = _.reduce( - urlQueries, + const urlQueryParamsTempVarsWithInvalidValues = _.reduce( + urlQueryParams, (acc, v, k) => { const matchedTempVar = tempVars.find( ({tempVar}) => stripTempVar(tempVar) === k @@ -171,15 +171,15 @@ export const findUpdatedTempVarsInURLQuery = ( [] ) - return urlQueryTempVarsWithInvalidValues + return urlQueryParamsTempVarsWithInvalidValues } export const findInvalidTempVarsInURLQuery = ( tempVars: Template[], - urlQueries: URLQueries + urlQueryParams: URLQueryParams ): TemplateUpdate[] => { - const urlQueryTempVarsWithInvalidValues = _.reduce( - urlQueries, + const urlQueryParamsTempVarsWithInvalidValues = _.reduce( + urlQueryParams, (acc, v, k) => { const matchedTempVar = tempVars.find( ({tempVar}) => stripTempVar(tempVar) === k @@ -197,7 +197,7 @@ export const findInvalidTempVarsInURLQuery = ( [] ) - return urlQueryTempVarsWithInvalidValues + return urlQueryParamsTempVarsWithInvalidValues } export default generateTemplateVariableQuery diff --git a/ui/src/shared/middleware/queryStringConfig.js b/ui/src/shared/middleware/queryStringConfig.js index 3950ed1699..244e0d2c46 100644 --- a/ui/src/shared/middleware/queryStringConfig.js +++ b/ui/src/shared/middleware/queryStringConfig.js @@ -5,9 +5,9 @@ import {enablePresentationMode} from 'src/shared/actions/app' export const queryStringConfig = () => dispatch => action => { dispatch(action) - const urlQueries = queryString.parse(window.location.search) + const urlQueryParams = queryString.parse(window.location.search) - if (urlQueries.present === 'true') { + if (urlQueryParams.present === 'true') { dispatch(enablePresentationMode()) } } diff --git a/ui/src/types/index.ts b/ui/src/types/index.ts index c7416ec283..fd952c3e38 100644 --- a/ui/src/types/index.ts +++ b/ui/src/types/index.ts @@ -2,7 +2,12 @@ import {LayoutCell, LayoutQuery} from './layouts' import {Service, NewService} from './services' import {AuthLinks, Organization, Role, User, Me} from './auth' import {Cell, CellQuery, Legend, Axes, Dashboard, CellType} from './dashboard' -import {Template, TemplateQuery, TemplateValue, URLQueries} from './tempVars' +import { + Template, + TemplateQuery, + TemplateValue, + URLQueryParams, +} from './tempVars' import { GroupBy, Query, @@ -76,5 +81,5 @@ export { ScriptStatus, SchemaFilter, RemoteDataState, - URLQueries, + URLQueryParams, } diff --git a/ui/src/types/tempVars.ts b/ui/src/types/tempVars.ts index 1308d62366..247d31b653 100644 --- a/ui/src/types/tempVars.ts +++ b/ui/src/types/tempVars.ts @@ -29,6 +29,6 @@ export interface TemplateUpdate { value: string } -export interface URLQueries { +export interface URLQueryParams { [key: string]: string }