-
Notifications
You must be signed in to change notification settings - Fork 688
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
feat: store params in url with qs #1475
feat: store params in url with qs #1475
Conversation
54ac06a
to
3e6be00
Compare
9afff6f
to
8aab44a
Compare
@@ -1,8 +1,12 @@ | |||
import { Box, Button, DrawerContent, DrawerFooter, Icon } from '@adminjs/design-system' | |||
import identity from 'lodash/identity.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
several warnings such as:
'identity' is defined but never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (parsedQuery) { | ||
const resourceProperties = pick(parsedQuery, Object.keys(resource.properties)) | ||
if (Object.keys(resourceProperties).length) { | ||
setRecord({ ...record, params: { ...record.params, ...resourceProperties } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if we add for example:
?gender=abcd&isActive=false
?
If gender
is male
/female
/other
enum, will it set abcd
?
If isActive
is a boolean, will it correctly parse true
/false
strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked with enums and booleans and there are results
for enums:
Enums value in URL has to be exactly like availableValues e.g.
export enum CountryEnum {
Poland = 'PL',
Germany = 'DE',
}
should look like ?country=PL
(case sensitive). Otherwise, the value would not be filled in the new item form.
for booleans
Booleans are correctly parsed by qs parse
for dates
Dates can be passed the same as values for the date time picker e.g. ?dateOfBirth=2023-04-21
or ?dateOfBirth=2023/04/21
@@ -0,0 +1,90 @@ | |||
import { Box, Button, DEFAULT_DRAWER_WIDTH, H3, Icon } from '@adminjs/design-system' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Icon' is defined but never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -2,6 +2,7 @@ import React, { useState } from 'react' | |||
import { connect } from 'react-redux' | |||
import { useParams } from 'react-router' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line or group Box with library imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -0,0 +1,70 @@ | |||
/* eslint-disable no-unused-vars */ | |||
import isEmpty from 'lodash/isEmpty.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add src/frontend/hooks/index.js
and export all hooks from it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
c77e043
to
6395efc
Compare
6395efc
to
0b1814f
Compare
2908d5c
to
54b6db1
Compare
54b6db1
to
b6ca2ad
Compare
* chore: moved toggle filter drawer to redux store * chore: unified stored list params in url * chore: pre-fill new item with params from url * chore: add redirectUrl to query params * chore: removed filter button from resource action --------- Co-authored-by: Rafal Dziegielewski <[email protected]>
* chore: moved toggle filter drawer to redux store * chore: unified stored list params in url * chore: pre-fill new item with params from url * chore: add redirectUrl to query params * chore: removed filter button from resource action --------- Co-authored-by: Rafal Dziegielewski <[email protected]>
Replaced custom filter query params with https://www.npmjs.com/package/qs.
Allow developers to add queryParams in the action button like in exmaple below.
Note: If passing queryParams to
new
action form will be preffield with url values i.e. using the example above form will have a filled email field with[email protected]
and checked isActive.Query params are stored in URL and can be accessible by using
useQueryParams
. There are separate params form lists likesortBy
,page
,direction
orfilters
and also reference totab
orredirectUrl
. To store params in urlstoreParams
should be called with new params like:Parsed params from
useQueryParams
are all passed params parsed byqs
.For more information about
stringify
andparse
functions please see qs configuration https://github.com/ljharb/qs.