Open mariusandra opened 4 years ago
To simplify cases like this, it would be nice to have a better way to convert the values to an URL, no matter which action was triggered.
This code:
const buildURL = (selectedDateURLparam: string, sessionRecordingId: SessionRecordingId | null): [string, Params] => { const today = moment().startOf('day').format('YYYY-MM-DD') const params: Params = {} const { properties } = router.values.searchParams // eslint-disable-line if (selectedDateURLparam !== today) { params.date = selectedDateURLparam } if (properties) { params.properties = properties } if (sessionRecordingId) { params.sessionRecordingId = sessionRecordingId } return [router.values.location.pathname, params] } kea({ ... actionToUrl: ({ values }) => ({ setFilters: () => buildURL(values.selectedDateURLparam, values.sessionRecordingId), loadSessionPlayer: () => buildURL(values.selectedDateURLparam, values.sessionRecordingId), closeSessionPlayer: () => buildURL(values.selectedDateURLparam, values.sessionRecordingId), }) })
... could become:
kea({ ... valuesToUrl: ({ values }) => { const { selectedDateURLparam, sessionRecordingId } = values const today = moment().startOf('day').format('YYYY-MM-DD') const params: Params = {} const { properties } = router.values.searchParams // eslint-disable-line if (selectedDateURLparam !== today) { params.date = selectedDateURLparam } if (properties) { params.properties = properties } if (sessionRecordingId) { params.sessionRecordingId = sessionRecordingId } return [router.values.location.pathname, params] } })
or something like that.
Some questions with this:
valuesToUrl: ({ values }) => { }
valuesToUrl: (values) => { }
valuesToUrl: ({ selectedDateURLparam, sessionRecordingId }) => { }
To simplify cases like this, it would be nice to have a better way to convert the values to an URL, no matter which action was triggered.
This code:
... could become:
or something like that.
Some questions with this:
valuesToUrl: ({ values }) => { }
orvaluesToUrl: (values) => { }
akavaluesToUrl: ({ selectedDateURLparam, sessionRecordingId }) => { }