Skip to content

Commit

Permalink
Removed all occurences of qs.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhudec committed Apr 18, 2024
1 parent f0a6d72 commit 005b56f
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 111 deletions.
5 changes: 2 additions & 3 deletions src/client/components/ActivityFeed/CollectionList/state.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buildSelectedFilters } from './filters'
import { SORT_OPTIONS } from './constants'
import { transformWasPolicyfeedBackProvidedToApi } from './transformers'
import { parseQueryString } from '../../../utils'
import { locationToQSParamsWithPage } from '../../../utils/url'

export const TASK_GET_COMPANY_ACTIVITIES_LIST =
'TASK_GET_COMPANY_ACTIVITIES_LIST'
Expand All @@ -26,8 +26,7 @@ export const TASK_GET_INTERACTIONS_COMPANY_NAME =
export const ID = 'companyActivitiesList'

export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)
const { currentAdviserId } = state
const { metadata, selectedAdvisers, selectedCompanies, createdByOthers } =
state[ID]
Expand Down
7 changes: 3 additions & 4 deletions src/client/components/ContactForm/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import qs from 'qs'
import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import _ from 'lodash'
Expand All @@ -9,6 +8,7 @@ import Label from '@govuk-react/label'

import multiInstance from '../../utils/multiinstance'
import { CONTACT_FORM__SUBMIT } from '../../actions'
import { getQueryParamsFromLocation } from '../../utils/url'

import Form from '../Form'
import {
Expand Down Expand Up @@ -153,9 +153,8 @@ const _ContactForm = ({
<Main>
<State>
{({ referrerUrl, router }) => {
const { origin_url, origin_search } = qs.parse(
router.location.search
)
const { origin_url, origin_search } =
getQueryParamsFromLocation(router.location)
const redirectTo = ({ name, id }) => {
return origin_url
? appendParamsToUrl(origin_url, origin_search, id, name)
Expand Down
3 changes: 2 additions & 1 deletion src/client/components/Resource/Paginated.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import qs from 'qs'

import styled from 'styled-components'

import { getQueryParamsFromLocation } from '../../utils/url'
import multiInstance from '../../utils/multiinstance'
import Task from '../Task'
import LoadingBox from '../Task/LoadingBox'
Expand Down Expand Up @@ -94,7 +95,7 @@ const PaginatedResource = multiInstance({
}) => (
<Route>
{({ location }) => {
const qsParams = qs.parse(location.search.slice(1))
const qsParams = getQueryParamsFromLocation(location)
const routePage = parseInt(qsParams.page, 10) || 1
const totalPages = result ? Math.ceil(result.count / pageSize) : 0
const hasZeroResults = result?.count === 0
Expand Down
5 changes: 2 additions & 3 deletions src/client/modules/Companies/CollectionList/state.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buildSelectedFilters } from './filters'
import { COMPANY_STATUS_OPTIONS, SORT_OPTIONS } from './constants'
import { transformArchivedToApi, transformPostcodeToApi } from './transformers'
import { parseQueryString } from '../../../utils'
import { locationToQSParamsWithPage } from '../../../utils/url'

export const TASK_GET_COMPANIES_LIST = 'TASK_GET_COMPANIES_LIST'
export const TASK_GET_COMPANIES_METADATA = 'TASK_GET_COMPANIES_METADATA'
Expand All @@ -14,8 +14,7 @@ export const ID = 'companiesList'
* Convert both location and redux state to props
*/
export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)
const archived = transformArchivedToApi(queryParams.archived)
const ukPostcode = transformPostcodeToApi(queryParams.uk_postcode)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { transformPostcodeToApi } from '../../CollectionList/transformers'
import { buildSelectedFilters } from './filters'
import { SORT_OPTIONS } from '../../CollectionList/constants'
import { parseQueryString } from '../../../../utils'
import { locationToQSParamsWithPage } from '../../../../utils/url'

export const ID = 'linkGlobalHQ'
export const SET_GLOBAL_HQ_ID = 'setGlobalHQ'
Expand All @@ -12,8 +12,7 @@ export const TASK_SET_GLOBAL_HQ = 'TASK_SET_GLOBAL_HQ'
export const TASK_REMOVE_GLOBAL_HQ = 'TASK_REMOVE_GLOBAL_HQ'

export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)
const ukPostcode = transformPostcodeToApi(queryParams.uk_postcode)

const { metadata } = state[ID]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { transformPostcodeToApi } from '../../CollectionList/transformers'
import { buildSelectedFilters } from './filters'
import { SORT_OPTIONS } from '../../CollectionList/constants'
import { parseQueryString } from '../../../../utils'
import { locationToQSParamsWithPage } from '../../../../utils/url'

export const ID = 'linkSubsidiary'

export const TASK_GET_SUBSIDIARY_LIST = 'TASK_GET_SUBSIDIARY_LIST'

export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)
const ukPostcode = transformPostcodeToApi(queryParams.uk_postcode)

const { metadata } = state[ID]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SORT_OPTIONS } from '../../../Contacts/CollectionList/constants'
import { parseQueryString } from '../../../../utils'
import { locationToQSParamsWithPage } from '../../../../utils/url'

export const OVERVIEW_COMPANY_PROJECTS_LIST_ID = 'overviewCompanyProjectsList'
export const TASK_GET_PROJECT_WON_COUNT = 'TASK_GET_PROJECT_WON_COUNT'
Expand All @@ -8,8 +8,7 @@ export const OVERVIEW_COMPANY_EXPORT_WINS_LIST_ID =
export const TASK_GET_LATEST_EXPORT_WINS = 'TASK_GET_LATEST_EXPORT_WINS'

export const companyProjectsState2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)

return {
...state[OVERVIEW_COMPANY_PROJECTS_LIST_ID],
Expand All @@ -21,8 +20,7 @@ export const companyProjectsState2props = ({ router, ...state }) => {
}

export const exportWinsState2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)

return {
...state[OVERVIEW_COMPANY_EXPORT_WINS_LIST_ID],
Expand Down
17 changes: 3 additions & 14 deletions src/client/modules/Contacts/CollectionList/state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { omitBy, isEmpty } from 'lodash'
import qs from 'qs'

import { locationToQSParamsWithPage } from '../../../utils/url'
import { buildSelectedFilters } from './filters'
import { transformArchivedToApi } from './transformers'
import { STATUS_OPTIONS, SORT_OPTIONS } from './constants'
Expand All @@ -11,17 +9,8 @@ export const COMPANY_CONTACTS_LIST_ID = 'companyContactsList'
export const TASK_GET_CONTACTS_LIST = 'TASK_GET_CONTACTS_LIST'
export const TASK_GET_CONTACTS_METADATA = 'TASK_GET_CONTACTS_METADATA'

const getQueryParams = (router) => {
const queryString = router.location.search.slice(1)
const queryParams = omitBy({ ...qs.parse(queryString) }, isEmpty)
return {
...queryParams,
page: parseInt(queryParams.page || 1, 10),
}
}

export const contactsState2props = ({ router, ...state }) => {
const queryParams = getQueryParams(router)
const queryParams = locationToQSParamsWithPage(router.location)
const metadata = state[CONTACTS_LIST_ID].metadata
const selectedFilters = buildSelectedFilters(queryParams, metadata)
const archived = transformArchivedToApi(queryParams.archived)
Expand All @@ -42,7 +31,7 @@ export const contactsState2props = ({ router, ...state }) => {
}

export const companyContactsState2props = ({ router, ...state }) => {
const queryParams = getQueryParams(router)
const queryParams = locationToQSParamsWithPage(router.location)
const archived = transformArchivedToApi(queryParams.archived)

return {
Expand Down
6 changes: 3 additions & 3 deletions src/client/modules/Contacts/ContactActivity/state.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import qs from 'qs'
import { getQueryParamsFromLocation } from '../../../utils/url'

export const TASK_GET_CONTACT_ACTIVITIES = 'TASK_GET_CONTACT_ACTIVITIES'

export const ID = 'contactActivity'

export const state2props = ({ ...state }) => {
const selectedSortBy = qs.parse(location.search.slice(1)).sortby || 'newest'
const page = qs.parse(location.search.slice(1)).page || '1'
const selectedSortBy = getQueryParamsFromLocation(location).sortby || 'newest'
const page = getQueryParamsFromLocation(location).page || '1'

return {
...state[ID],
Expand Down
15 changes: 2 additions & 13 deletions src/client/modules/Events/AttendeeSearch/state.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { omitBy, isEmpty } from 'lodash'
import qs from 'qs'

import { locationToQSParamsWithPage } from '../../../utils/url'
import { SORT_OPTIONS } from '../../Contacts/CollectionList/constants'
import { buildSelectedFilters } from './filters'

export const TASK_SEARCH_ATTENDEE = 'TASK_SEARCH_ATTENDEE'
export const TASK_GET_ATTENDEE_METADATA = 'TASK_GET_ATTENDEE_METADATA'
export const SEARCH_ATTENDEE_ID = 'findAttendees'

const getQueryParams = (router) => {
const queryString = router.location.search.slice(1)
const queryParams = omitBy({ ...qs.parse(queryString) }, isEmpty)
return {
...queryParams,
page: parseInt(queryParams.page || 1, 10),
}
}

export const state2props = ({ router, ...state }) => {
const queryParams = getQueryParams(router)
const queryParams = locationToQSParamsWithPage(router.location)
const metadata = state[SEARCH_ATTENDEE_ID].metadata
const selectedFilters = buildSelectedFilters(queryParams, metadata)

Expand Down
5 changes: 2 additions & 3 deletions src/client/modules/Events/CollectionList/state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buildSelectedFilters } from './filters'
import { SORT_OPTIONS } from './constants'
import { parseQueryString } from '../../../utils'
import { locationToQSParamsWithPage } from '../../../utils/url'

export const TASK_GET_EVENTS_LIST = 'TASK_GET_EVENTS_LIST'
export const TASK_GET_EVENTS_METADATA = 'TASK_GET_EVENTS_METADATA'
Expand All @@ -14,8 +14,7 @@ export const ID = 'eventsList'
* Convert both location and redux state to props
*/
export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)

const { metadata, selectedOrganisers } = state[ID]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import qs from 'qs'

import { EVENT_ATTENDEES_MAPPING } from '../../../../apps/companies/apps/activity-feed/constants'
import { parseQueryString } from '../../../utils'
import { locationToQSParamsWithPage } from '../../../utils/url'

export const TASK_GET_EVENT_AVENTRI_REGISTRATION_STATUS_ATTENDEES =
'TASK_GET_EVENT_AVENTRI_REGISTRATION_STATUS_ATTENDEES'
Expand All @@ -15,12 +13,9 @@ export const mapUrlSlugToRegistrationStatus = (urlSlug) => {
return Array.isArray(status) ? status[0] : null
}

export const state2props = (state, router) => {
const { match, location } = router
const queryString = location.search.slice(1)
const queryParams = parseQueryString(queryString)
const selectedSortBy =
qs.parse(location.search.slice(1)).sortby || 'first_name:asc'
export const state2props = (state, { match, location }) => {
const queryParams = locationToQSParamsWithPage(location)
const selectedSortBy = queryParams.sortby || 'first_name:asc'

const registrationStatus = mapUrlSlugToRegistrationStatus(match.params.status)

Expand Down
5 changes: 2 additions & 3 deletions src/client/modules/Interactions/CollectionList/state.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buildSelectedFilters } from './filters'
import { SORT_OPTIONS } from './constants'
import { transformWasPolicyfeedBackProvidedToApi } from './transformers'
import { parseQueryString } from '../../../utils'
import { locationToQSParamsWithPage } from '../../../utils/url'

export const TASK_GET_INTERACTIONS_LIST = 'TASK_GET_INTERACTIONS_LIST'
export const TASK_GET_INTERACTIONS_ADVISER_NAME =
Expand All @@ -14,8 +14,7 @@ export const TASK_GET_INTERACTIONS_COMPANY_NAME =
export const ID = 'interactionsList'

export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)
const { currentAdviserId } = state
const { metadata, selectedAdvisers, selectedTeams, selectedCompanies } =
state[ID]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import qs from 'qs'

import { getQueryParamsFromLocation } from '../../../../utils/url'
import { sortOptions } from './metadata'

export const TASK_GET_OPPORTUNITIES_LIST = 'TASK_GET_OPPORTUNITIES_LIST'
Expand All @@ -19,7 +18,7 @@ const collectionListPayload = (paramProps) => {

export const state2props = ({ router, ...state }) => {
const { metadata } = state.opportunitiesList
const queryProps = qs.parse(router.location.search.slice(1))
const queryProps = getQueryParamsFromLocation(router.location)
const filteredQueryProps = collectionListPayload(queryProps)

return {
Expand Down
5 changes: 3 additions & 2 deletions src/client/modules/Investments/Profiles/state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import qs from 'qs'
import { omit } from 'lodash'

import { getQueryParamsFromLocation } from '../../../utils/url'

export const TASK_GET_PROFILES_LIST = 'TASK_GET_PROFILES_LIST'

export const ID = 'profilesList'
Expand All @@ -26,5 +27,5 @@ const collectionListPayload = ({

export const state2props = ({ router, ...state }) => ({
...state[ID],
payload: collectionListPayload(qs.parse(router.location.search.slice(1))),
payload: collectionListPayload(getQueryParamsFromLocation(router.location)),
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseQueryString } from '../../../../../utils'
import { locationToQSParamsWithPage } from '../../../../../utils/url'
import {
generateFinancialYearLabel,
getFinancialYearStart,
Expand All @@ -12,9 +12,7 @@ export const TASK_GET_NON_FDI_PROJECTS_LIST = 'TASK_GET_NON_FDI_PROJECTS_LIST'
export const NON_FDI_LIST_ID = 'nonFdiProjectsList'

export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)

const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)
const { metadata } = state[NON_FDI_LIST_ID]
const financialYearStart = getFinancialYearStart(new Date())
const financialYearOptions = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseQueryString } from '../../../../../utils'
import { locationToQSParamsWithPage } from '../../../../../utils/url'
import { transformPostcodeToApi } from '../../../../Companies/CollectionList/transformers'
import {
COMPANY_STATUS_OPTIONS,
Expand All @@ -12,8 +12,7 @@ export const TASK_UPDATE_RECIPIENT_COMPANY = 'TASK_UPDATE_RECIPIENT_COMPANY'
export const RECIPIENT_COMPANY_LIST_ID = 'recipientCompanyList'

export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)
const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)
const ukPostcode = transformPostcodeToApi(queryParams.uk_postcode)

const { metadata } = state[RECIPIENT_COMPANY_LIST_ID]
Expand Down
6 changes: 2 additions & 4 deletions src/client/modules/Investments/Projects/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
getFinancialYearStart,
generateFinancialYearLabel,
} from '../../../utils/date'
import { parseQueryString } from '../../../utils'
import { locationToQSParamsWithPage } from '../../../utils/url'
import { buildSelectedFilters } from './filters'
import {
SORT_OPTIONS,
Expand Down Expand Up @@ -31,9 +31,7 @@ export const ID = 'propositionComplete'
export const TASK_PROPOSITION_COMPLETE = 'TASK_PROPOSITION_COMPLETE'

export const state2props = ({ router, ...state }) => {
const queryString = router.location.search.slice(1)

const queryParams = parseQueryString(queryString)
const queryParams = locationToQSParamsWithPage(router.location)
const { metadata, selectedAdvisers, results } = state[INVESTMENT_PROJECTS_ID]
const financialYearStart = getFinancialYearStart(new Date())
const financialYearOptions = [
Expand Down
Loading

0 comments on commit 005b56f

Please sign in to comment.