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

[Features] useRouteQuery transform data (get/set) #3929

Open
4 tasks done
kieuminhcanh opened this issue Apr 18, 2024 · 0 comments
Open
4 tasks done

[Features] useRouteQuery transform data (get/set) #3929

kieuminhcanh opened this issue Apr 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@kieuminhcanh
Copy link

Clear and concise description of the problem

Clear and concise description of the problem

Some time I would like to transform data before use. In my case. There are two case to use.

// orders?page=2&orderBy=no:asc&orderBy=status:desc

const filters = reactive({
  page: useRouteQuery('page', '1', {
    transform: ({
      get: (value) => parseInt(value),
      set: (value) => value.toString()
    })
  }),
  orderBy: useRouteQuery('orderBy', [], {
    transform: ({
      get: (value) => value.map((v) => v.split(':'))
        .map(([key, order]) => ({
          key: key.toLowerCase(),
          order: order.toLowerCase(),
        })),
      set: (value) => value.map(({ key, order }) => `${key}:${order}`)
    })
  })
})

From orders?page=2&orderBy=no:asc&orderBy=status:desc
We will have

filters.page = 2
filters.orderBy = [{ key: 'no', order: 'asc' }, { key: 'status', order: 'desc' }]

Otherways

filters.page = 2
filters.orderBy = [{ key: 'no', order: 'desc' }, { key: 'time', order: 'desc' }]
// =>> orders?page=2&orderBy=no:desc&orderBy=time:desc

Suggested solution

Add transform (get/set) function in ReactiveRouteOptions

Alternative

No response

Additional context

No response

Validations

@kieuminhcanh kieuminhcanh added the enhancement New feature or request label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant