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

feat: useSelect's queryResult to query #6180

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/afraid-baboons-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@refinedev/mui": minor
---

feat: [`useAutocomplete`](https://refine.dev/docs/ui-integrations/material-ui/hooks/use-auto-complete/)'s `queryResult` and `defaultValueQueryResult` is deprecated, use `query` and `defaultValueQuery` instead. #6179

```diff
import { useAutocomplete } from '@refinedev/mui';

- const { queryResult, defaultValueQueryResult } = useAutocomplete();
+ const { query, defaultValueQuery } = useAutocomplete();
```

> ✨ You can use `@refinedev/codemod` to automatically migrate your codebase. Simply run the following command in your project's root directory:
>
> ```bash
> npx @refinedev/codemod@latest use-select-query-result
> ```
10 changes: 10 additions & 0 deletions .changeset/bright-dancers-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@refinedev/codemod": minor
---

feat: added `npx @refinedev/codemod@latest use-select-query-result` to automatically refactor `useSelect`'s `queryResult` and `defaultValueQueryResult` to `query` and `defaultValueQuery` #6179

```diff
- const { queryResult, defaultValueQueryResult } = useSelect(); // or useAutocomplete, useCheckboxGroup, useRadioGroup
+ const { query, defaultValueQuery } = useSelect();
```
18 changes: 18 additions & 0 deletions .changeset/cool-cougars-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@refinedev/core": minor
---

feat: [`useSelect`](https://refine.dev/docs/data/hooks/use-select/)'s `queryResult` and `defaultValueQueryResult` is deprecated, use `query` and `defaultValueQuery` instead. #6179

```diff
import { useSelect } from '@refinedev/core';

- const { queryResult, defaultValueQueryResult } = useSelect();
+ const { query, defaultValueQuery } = useSelect();
```

> ✨ You can use `@refinedev/codemod` to automatically migrate your codebase. Simply run the following command in your project's root directory:
>
> ```bash
> npx @refinedev/codemod@latest use-select-query-result
> ```
36 changes: 36 additions & 0 deletions .changeset/gentle-vans-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
"@refinedev/antd": minor
---

feat: [`useSelect`](https://refine.dev/docs/ui-integrations/ant-design/hooks/use-select/)'s `queryResult` and `defaultValueQueryResult` is deprecated, use `query` and `defaultValueQuery` instead. #6179

```diff
import { useSelect } from '@refinedev/antd';

- const { queryResult, defaultValueQueryResult } = useSelect();
+ const { query, defaultValueQuery } = useSelect();
```

feat: [`useCheckboxGroup`](https://refine.dev/docs/ui-integrations/ant-design/hooks/use-checkbox-group/)'s `queryResult` is deprecated, use `query` instead.

```diff
import { useCheckboxGroup } from '@refinedev/antd';

- const { queryResult } = useCheckboxGroup();
+ const { query } = useCheckboxGroup();
```

feat: [`useRadioGroup`](https://refine.dev/docs/ui-integrations/ant-design/hooks/use-radio-group/)'s `queryResult` is deprecated, use `query` instead.

```diff
import { useRadioGroup } from '@refinedev/antd';

- const { queryResult } = useRadioGroup();
+ const { query } = useRadioGroup();
```

> ✨ You can use `@refinedev/codemod` to automatically migrate your codebase. Simply run the following command in your project's root directory:
>
> ```bash
> npx @refinedev/codemod@latest use-select-query-result
> ```
18 changes: 18 additions & 0 deletions .changeset/perfect-monkeys-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@refinedev/mantine": minor
---

feat: [`useSelect`](https://refine.dev/docs/ui-integrations/mantine/hooks/use-select/)'s `queryResult` and `defaultValueQueryResult` is deprecated, use `query` and `defaultValueQuery` instead. #6179

```diff
import { useSelect } from '@refinedev/mantine';

- const { queryResult, defaultValueQueryResult } = useSelect();
+ const { query, defaultValueQuery } = useSelect();
```

> ✨ You can use `@refinedev/codemod` to automatically migrate your codebase. Simply run the following command in your project's root directory:
>
> ```bash
> npx @refinedev/codemod@latest use-select-query-result
> ```
20 changes: 10 additions & 10 deletions documentation/docs/data/hooks/use-select/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,14 @@ useSelect({

### Can I create the options manually?

Sometimes it may not be enough to create `optionLabel` and `optionValue` options. In this case we create options with `queryResult`.
Sometimes it may not be enough to create `optionLabel` and `optionValue` options. In this case we create options with `query`.

```tsx
const { queryResult } = useSelect({
const { query } = useSelect({
resource: "categories",
});

const options = queryResult.data?.data.map((item) => ({
const options = query.data?.data.map((item) => ({
label: item.name,
value: item.id,
}));
Expand Down Expand Up @@ -501,13 +501,13 @@ return (

### Return values

| Property | Description | Type |
| ----------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| options | It returns possible options | `{ label: string; value: string }` |
| queryResult | Result of the query of a record | [`QueryObserverResult<{ data: TData; error: TError }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQueryResult | Result of the query of a `defaultValue` record | [`QueryObserverResult<{ data: TData; error: TError }>`](https://react-query.tanstack.com/reference/useQuery) |
| onSearch | A function to set the search value | `onSearch: (value: string) => void` |
| overtime | Overtime loading props | `{ elapsedTime?: number }` |
| Property | Description | Type |
| ----------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| options | It returns possible options | `{ label: string; value: string }` |
| query | Result of the query of a record | [`QueryObserverResult<{ data: TData; error: TError }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQuery | Result of the query of a `defaultValue` record | [`QueryObserverResult<{ data: TData; error: TError }>`](https://react-query.tanstack.com/reference/useQuery) |
| onSearch | A function to set the search value | `onSearch: (value: string) => void` |
| overtime | Overtime loading props | `{ elapsedTime?: number }` |

## Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,12 @@ useSelect({

### Can I create the options manually?

Sometimes it may not be enough to create `optionLabel` and `optionValue` options. In this case we create options with `queryResult`.
Sometimes it may not be enough to create `optionLabel` and `optionValue` options. In this case we create options with `query`.

```tsx
const { queryResult } = useSelect();
const { query } = useSelect();

const options = queryResult.data?.data.map((item) => ({
const options = query.data?.data.map((item) => ({
label: item.title,
value: item.id,
}));
Expand Down Expand Up @@ -507,8 +507,8 @@ return <Select options={options} />;
| Property | Description | Type |
| -------------------------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------- |
| selectProps | Ant design Select props | [`Select`](https://ant.design/components/select/#API) |
| queryResult | Result of the query of a record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQueryResult | Result of the query of a `defaultValue` record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| query | Result of the query of a record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQuery | Result of the query of a `defaultValue` record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQueryOnSuccess | Default value onSuccess method | `() => void` |
| overtime | Overtime loading props | `{ elapsedTime?: number }` |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,12 @@ useSelect({

### Can I create the options manually?

Sometimes it may not be enough to create `optionLabel` and `optionValue` options. In this case we create options with `queryResult`.
Sometimes it may not be enough to create `optionLabel` and `optionValue` options. In this case we create options with `query`.

```tsx
const { queryResult } = useSelect();
const { query } = useSelect();

const options = queryResult.data?.data.map((item) => ({
const options = query.data?.data.map((item) => ({
label: item.title,
value: item.id,
}));
Expand Down Expand Up @@ -496,8 +496,8 @@ return <Select options={options} />;
| Property | Description | Type |
| -------------------------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------- |
| selectProps | Mantine Select props | [`SelectPropsType`](#selectpropstype) |
| queryResult | Result of the query of a record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQueryResult | Result of the query of a `defaultValue` record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| query | Result of the query of a record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQuery | Result of the query of a `defaultValue` record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQueryOnSuccess | Default value onSuccess method | `() => void` |
| overtime | Overtime loading props | `{ elapsedTime?: number }` |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ In some cases we only have `id`, it may be necessary to show it selected in the

### Can I create the options manually?

You can create a new `options` object with `queryResult`.
You can create a new `options` object with `query`.

```tsx
const { autocompleteProps, queryResult } = useAutocomplete();
const { autocompleteProps, query } = useAutocomplete();

const options = queryResult.data?.data.map((item) => ({
const options = query.data?.data.map((item) => ({
title: item.title,
value: item.id,
}));
Expand Down Expand Up @@ -447,8 +447,8 @@ By default, Refine does the search using the [`useList`](/docs/data/hooks/use-de
| Property | Description | Type |
| -------------------------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------- |
| autocompleteProps | Material UI Autocomplete props | [`AutoCompleteReturnValues`](#autocompletereturnvalues) |
| queryResult | Result of the query of a record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQueryResult | Result of the query of a `defaultValue` record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| query | Result of the query of a record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQuery | Result of the query of a `defaultValue` record | [`QueryObserverResult<{ data: TData }>`](https://react-query.tanstack.com/reference/useQuery) |
| defaultValueQueryOnSuccess | Default value onSuccess method | `() => void` |
| overtime | Overtime loading props | `{ elapsedTime?: number }` |

Expand Down
23 changes: 12 additions & 11 deletions examples/app-crm-minimal/src/routes/companies/edit/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ export const CompanyForm = () => {
});
const { avatarUrl, name } = queryResult?.data?.data || {};

const { selectProps: selectPropsUsers, queryResult: queryResultUsers } =
useSelect<GetFieldsFromList<UsersSelectQuery>>({
resource: "users",
optionLabel: "name",
pagination: {
mode: "off",
},
meta: {
gqlQuery: USERS_SELECT_QUERY,
},
});
const { selectProps: selectPropsUsers, query: queryResultUsers } = useSelect<
GetFieldsFromList<UsersSelectQuery>
>({
resource: "users",
optionLabel: "name",
pagination: {
mode: "off",
},
meta: {
gqlQuery: USERS_SELECT_QUERY,
},
});

return (
<Edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const CompanyCreateModal = () => {
},
});

const { selectProps, queryResult } = useSelect<
const { selectProps, query: queryResult } = useSelect<
GetFieldsFromList<UsersSelectQuery>
>({
resource: "users",
Expand Down
2 changes: 1 addition & 1 deletion examples/app-crm/src/routes/scrumboard/sales/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const SalesCreatePage: FC<PropsWithChildren> = ({ children }) => {
}
}, [searchParams]);

const { selectProps, queryResult } = useSelect<
const { selectProps, query: queryResult } = useSelect<
GetFieldsFromList<SalesCompaniesSelectQuery>
>({
resource: "companies",
Expand Down
18 changes: 8 additions & 10 deletions examples/app-crm/src/routes/scrumboard/sales/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ export const SalesEditPage = () => {
},
});

const {
selectProps: companySelectProps,
queryResult: companySelectQueryResult,
} = useSelect<GetFieldsFromList<SalesCompaniesSelectQuery>>({
resource: "companies",
optionLabel: "name",
meta: {
gqlQuery: SALES_COMPANIES_SELECT_QUERY,
},
});
const { selectProps: companySelectProps, query: companySelectQueryResult } =
useSelect<GetFieldsFromList<SalesCompaniesSelectQuery>>({
resource: "companies",
optionLabel: "name",
meta: {
gqlQuery: SALES_COMPANIES_SELECT_QUERY,
},
});

const { selectProps: stageSelectProps } = useDealStagesSelect();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export const FixedSider: React.FC = () => {
>
<ThemedTitle collapsed={collapsed} />
</div>

<Menu
style={{
marginTop: "8px",
Expand Down
2 changes: 1 addition & 1 deletion examples/data-provider-sanity/src/pages/posts/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const PostList = () => {
},
});

const { selectProps: selectPropsCategory, queryResult: queryResultCategory } =
const { selectProps: selectPropsCategory, query: queryResultCategory } =
useSelect({
resource: "category",
optionLabel: "title",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const ProductListTable = () => {
},
});

const { selectProps: categorySelectProps, queryResult } =
const { selectProps: categorySelectProps, query: queryResult } =
useSelect<ICategory>({
resource: "categories",
optionLabel: "title",
Expand Down
4 changes: 2 additions & 2 deletions examples/finefoods-antd/src/pages/couriers/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ export const CourierList = ({ children }: PropsWithChildren) => {
<FilterDropdown {...props}>
<InputMask mask="(999) 999 99 99">
{/*
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore */}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore */}
{(props: InputProps) => <Input {...props} />}
</InputMask>
</FilterDropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const BasicDataGrid: React.FC = () => {

const {
options,
queryResult: { isLoading },
query: { isLoading },
} = useSelect<ICategory>({
resource: "categories",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const PostList: React.FC = () => {

const {
options,
queryResult: { isLoading },
query: { isLoading },
} = useSelect<ICategory>({
resource: "categories",
hasPagination: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const PostList: React.FC = () => {

const {
options,
queryResult: { isLoading },
query: { isLoading },
} = useSelect<ICategory>({
resource: "categories",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const PostList: React.FC = () => {

const {
options,
queryResult: { isLoading },
query: { isLoading },
} = useSelect<ICategory>({
resource: "categories",
hasPagination: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const PostList: React.FC = () => {

const {
options,
queryResult: { isLoading },
query: { isLoading },
} = useSelect<ICategory>({
resource: "categories",
});
Expand Down
Loading
Loading