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

Update Identifier -> string. #540

Merged
merged 6 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Update Identifier -> string.
  • Loading branch information
yildirayunlu committed Jun 2, 2021
commit a52ffdd816eddf04d54cd06dee4e4d662594e7dd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Let'say we have a `categories` resource

```tsx
type CategoryMutationResult = {
id: string | number;
id: string;
title: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Let'say we have a `categories` resource

```tsx
type CategoryMutationResult = {
id: string | number;
id: string;
title: string;
}

Expand Down
10 changes: 5 additions & 5 deletions documentation/docs/guides-and-concepts/hooks/data/useDelete.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Variables passed to `mutate` must have the type of

```tsx
{
id: string | number;
id: string;
}
```
:::
Expand Down Expand Up @@ -146,9 +146,9 @@ After 7.5 seconds the mutation will be executed. The mutation can be cancelled w

### Return value

| Description | Type |
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Result of the `react-query`'s useMutation | [`UseMutationResult<`<br/>`{ data: TData },`<br/>`TError,`<br/>` { id: Identifier; },`<br/>` DeleteContext>`](https://react-query.tanstack.com/reference/useMutation) |
| Description | Type |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Result of the `react-query`'s useMutation | [`UseMutationResult<`<br/>`{ data: TData },`<br/>`TError,`<br/>` { id: string; },`<br/>` DeleteContext>`](https://react-query.tanstack.com/reference/useMutation) |

>`*` [Refer to documentation for `Identifier` &#8594](#) and [`DeleteContext` &#8594](#)
>`*` [Refer to documentation for [`DeleteContext` &#8594](#)

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Values passed to `mutate` must have the type of

```tsx
{
ids: (string | number)[];
ids: (string)[];
}
```
:::
Expand Down Expand Up @@ -150,11 +150,11 @@ After 7.5 seconds the mutation will be executed. The mutation can be cancelled w

### Return value

| Description | Type |
| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Result of the `react-query`'s useMutation | [`UseMutationResult<`<br/>`{ data: TData },`<br/>`TError,`<br/>` { ids: Identifier[]; },`<br/>` DeleteContext>`](https://react-query.tanstack.com/reference/useMutation)* |
| Description | Type |
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Result of the `react-query`'s useMutation | [`UseMutationResult<`<br/>`{ data: TData },`<br/>`TError,`<br/>` { ids: string[]; },`<br/>` DeleteContext>`](https://react-query.tanstack.com/reference/useMutation)* |

>`*` Refer to documentation for `Identifier` &#8594](#) and [`DeleteContext` &#8594](#)
>`*` Refer to documentation for [`DeleteContext` &#8594](#)


<!-- >`TData` and `TError` are type parameters that `useDeleteMany` accepts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Let'say we have a `categories` resource

```tsx
type CategoryMutationResult = {
id: string | number;
id: string;
title: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Values passed to `mutate` must have the type of

```tsx
{
ids: (string | number)[];
ids: (string)[];
values: TVariables = {};
}
```
Expand Down Expand Up @@ -159,8 +159,8 @@ After 7.5 seconds the mutation will be executed. The mutation can be cancelled w

### Return value

| Description | Type |
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Result of the `react-query`'s useMutation | [`UseMutationResult<`<br/>`{ data: TData },`<br/>`TError,`<br/>` { ids: Identifier[]; values: TVariables; },`<br/>` UpdateContext>`](https://react-query.tanstack.com/reference/useMutation)* |
| Description | Type |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Result of the `react-query`'s useMutation | [`UseMutationResult<`<br/>`{ data: TData },`<br/>`TError,`<br/>` { ids: string[]; values: TVariables; },`<br/>` UpdateContext>`](https://react-query.tanstack.com/reference/useMutation)* |

>`*` [Refer to documentation for `UpdateContext` &#8594](#) and [`Identifier` &#8594](#)
>`*` [Refer to documentation for `UpdateContext` &#8594](#).
10 changes: 6 additions & 4 deletions example/src/components/pages/category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export const CategoryList: React.FC<IResourceComponentsProps> = (props) => {
dataIndex="actions"
key="actions"
render={(
_text: string | number,
_text: string,
record: {
id: string | number;
id: string;
},
): React.ReactNode => {
if (isEditing(record.id)) {
Expand All @@ -153,12 +153,14 @@ export const CategoryList: React.FC<IResourceComponentsProps> = (props) => {
return (
<Space>
<EditButton
{...editButtonProps(record.id)}
{...editButtonProps(
record.id.toString(),
)}
size="small"
/>
<DeleteButton
size="small"
recordItemId={record.id}
recordItemId={record.id.toString()}
/>
</Space>
);
Expand Down
4 changes: 2 additions & 2 deletions example/src/components/pages/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export const LandingList: React.FC<IResourceComponentsProps> = (props) => {
dataIndex="actions"
key="actions"
render={(
_text: string | number,
_text: string,
record: {
id: string | number;
id: string;
},
): React.ReactNode => (
<Space>
Expand Down
6 changes: 3 additions & 3 deletions example/src/components/pages/post-light.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ export const PostLightList: React.FC<IResourceComponentsProps> = (props) => {
dataIndex="actions"
key="actions"
render={(
_text: string | number,
_text: string,
record: {
id: string | number;
id: string;
},
): React.ReactNode => (
<Space>
Expand All @@ -136,7 +136,7 @@ export const PostLightList: React.FC<IResourceComponentsProps> = (props) => {
/>
<CloneButton
onClick={() => {
createModalShow(record.id);
createModalShow(record.id.toString());
}}
/>
</Space>
Expand Down
4 changes: 2 additions & 2 deletions example/src/components/pages/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ export const PostList: React.FC<IResourceComponentsProps> = (props) => {
dataIndex="actions"
key="actions"
render={(
_text: string | number,
_text: string,
record: {
id: string | number;
id: string;
},
): React.ReactNode => (
<Space>
Expand Down
4 changes: 2 additions & 2 deletions example/src/components/pages/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ export const TagList: React.FC<IResourceComponentsProps> = (props) => {
dataIndex="actions"
key="actions"
render={(
_text: string | number,
_text: string,
record: {
id: string | number;
id: string;
},
): React.ReactNode => (
<Space>
Expand Down
4 changes: 2 additions & 2 deletions example/src/components/pages/tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export const TagsList: React.FC<IResourceComponentsProps> = (props) => {
dataIndex="actions"
key="actions"
render={(
_text: string | number,
_text: string,
record: {
id: string | number;
id: string;
},
): React.ReactNode => (
<Space>
Expand Down
2 changes: 1 addition & 1 deletion example/src/components/pages/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const UserList: React.FC<IResourceComponentsProps> = (props) => {
dataIndex="actions"
key="actions"
render={(
_text: string | number,
_text: string,
record: {
id: string;
},
Expand Down
6 changes: 2 additions & 4 deletions examples/useDeleteMany/src/pages/posts/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export const PostList: React.FC<IResourceComponentsProps> = (props) => {
enabled: categoryIds.length > 0,
});

const [selectedRowKeys, setSelectedRowKeys] = React.useState<
(string | number)[]
>([]);
const [selectedRowKeys, setSelectedRowKeys] = React.useState<string[]>([]);

const {
mutate,
Expand All @@ -46,7 +44,7 @@ export const PostList: React.FC<IResourceComponentsProps> = (props) => {
}
}, [isSuccess]);

const onSelectChange = (selectedRowKeys: (string | number)[]) => {
const onSelectChange = (selectedRowKeys: string[]) => {
setSelectedRowKeys(selectedRowKeys);
};

Expand Down
6 changes: 2 additions & 4 deletions examples/useUpdateMany/src/pages/posts/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export const PostList: React.FC<IResourceComponentsProps> = (props) => {
enabled: categoryIds.length > 0,
});

const [selectedRowKeys, setSelectedRowKeys] = React.useState<
(string | number)[]
>([]);
const [selectedRowKeys, setSelectedRowKeys] = React.useState<string[]>([]);

const {
mutate,
Expand All @@ -49,7 +47,7 @@ export const PostList: React.FC<IResourceComponentsProps> = (props) => {
}
}, [isSuccess]);

const onSelectChange = (selectedRowKeys: (string | number)[]) => {
const onSelectChange = (selectedRowKeys: string[]) => {
setSelectedRowKeys(selectedRowKeys);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/buttons/clone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ResourceRouterParams } from "../../../interfaces";

type CloneButtonProps = ButtonProps & {
resourceName?: string;
recordItemId?: string | number;
recordItemId?: string;
};

export const CloneButton: FC<CloneButtonProps> = ({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/buttons/delete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

export type DeleteButtonProps = ButtonProps & {
resourceName?: string;
recordItemId?: string | number;
recordItemId?: string;
onSuccess?: (value: DeleteOneResponse) => void;
mutationMode?: MutationMode;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/buttons/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ResourceRouterParams } from "../../../interfaces";

type EditButtonProps = ButtonProps & {
resourceName?: string;
recordItemId?: string | number;
recordItemId?: string;
};

export const EditButton: FC<EditButtonProps> = ({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/buttons/refresh/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ResourceRouterParams } from "../../../interfaces";

type RefreshButtonProps = ButtonProps & {
resourceName?: string;
recordItemId?: string | number;
recordItemId?: string;
};

export const RefreshButton: FC<RefreshButtonProps> = ({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/buttons/show/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ResourceRouterParams } from "../../../interfaces";

type ShowButtonProps = ButtonProps & {
resourceName?: string;
recordItemId?: string | number;
recordItemId?: string;
};

export const ShowButton: FC<ShowButtonProps> = ({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/crud/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface EditProps {
actionButtons?: React.ReactNode;
saveButtonProps?: ButtonProps;
mutationMode?: MutationMode;
recordItemId?: string | number;
recordItemId?: string;
pageHeaderProps?: PageHeaderProps;
canDelete?: boolean;
deleteButtonProps?: DeleteButtonProps;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/crud/show/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ShowProps {
isLoading?: boolean;
pageHeaderProps?: PageHeaderProps;
resource?: string;
recordItemId?: string | number;
recordItemId?: string;
}

export const Show: React.FC<ShowProps> = ({
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/contexts/data/IDataContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseRecord, Identifier } from "../../interfaces";
import { BaseRecord } from "../../interfaces";

export interface Pagination {
current?: number;
Expand Down Expand Up @@ -108,11 +108,11 @@ export interface IDataContext {
) => Promise<GetListResponse<TData>>;
getMany: <TData extends BaseRecord = BaseRecord>(
resource: string,
ids: Identifier[],
ids: string[],
) => Promise<GetManyResponse<TData>>;
getOne: <TData extends BaseRecord = BaseRecord>(
resource: string,
id: Identifier,
id: string,
) => Promise<GetOneResponse<TData>>;
create: <TData extends BaseRecord = BaseRecord, TVariables = {}>(
resource: string,
Expand All @@ -124,21 +124,21 @@ export interface IDataContext {
) => Promise<CreateManyResponse<TData>>;
update: <TData extends BaseRecord = BaseRecord, TVariables = {}>(
resource: string,
id: Identifier,
id: string,
params: TVariables,
) => Promise<UpdateResponse<TData>>;
updateMany: <TData extends BaseRecord = BaseRecord, TVariables = {}>(
resource: string,
ids: Identifier[],
ids: string[],
params: TVariables,
) => Promise<UpdateManyResponse<TData>>;
deleteOne: <TData extends BaseRecord = BaseRecord>(
resource: string,
id: Identifier,
id: string,
) => Promise<DeleteOneResponse<TData>>;
deleteMany: <TData extends BaseRecord = BaseRecord>(
resource: string,
ids: Identifier[],
ids: string[],
) => Promise<DeleteManyResponse<TData>>;
getApiUrl: () => string;
// TODO: Should be optional
Expand Down
10 changes: 3 additions & 7 deletions packages/core/src/hooks/data/useDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
ContextQuery,
HttpError,
GetListResponse,
Identifier,
} from "../../interfaces";

type UseDeleteReturnType<
Expand All @@ -30,7 +29,7 @@ type UseDeleteReturnType<
> = UseMutationResult<
DeleteOneResponse<TData>,
TError,
{ id: Identifier },
{ id: string },
DeleteContext
>;

Expand Down Expand Up @@ -64,7 +63,7 @@ export const useDelete = <
DeleteOneResponse<TData>,
TError,
{
id: Identifier;
id: string;
},
DeleteContext
>(
Expand Down Expand Up @@ -139,10 +138,7 @@ export const useDelete = <
...previousQuery,
data: (data ?? []).filter(
(record: TData) =>
!(
record.id!.toString() ===
deleteParams.id?.toString()
),
!(record.id === deleteParams.id),
),
total: total - 1,
});
Expand Down
Loading