-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-trash-bin): add trash bin to app-headless-cms (#4059)
- Loading branch information
Showing
219 changed files
with
4,292 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
import { Property, useIdGenerator } from "@webiny/react-properties"; | ||
|
||
export interface SortingConfig { | ||
field: string; | ||
order: "asc" | "desc"; | ||
} | ||
|
||
export interface SortingProps { | ||
name: string; | ||
field: string; | ||
order?: "asc" | "desc"; | ||
} | ||
|
||
export const Sorting = ({ name, field, order = "desc" }: SortingProps) => { | ||
const getId = useIdGenerator("tableSorting"); | ||
|
||
return ( | ||
<Property id="table" name={"table"}> | ||
<Property id={getId(name)} name={"sorting"} array={true}> | ||
<Property id={getId(name, "name")} name={"name"} value={name} /> | ||
<Property id={getId(name, "field")} name={"field"} value={field} /> | ||
<Property id={getId(name, "order")} name={"order"} value={order} /> | ||
</Property> | ||
</Property> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { Column, ColumnConfig } from "./Column"; | ||
|
||
import { Sorting, SortingConfig } from "./Sorting"; | ||
export interface TableConfig { | ||
columns: ColumnConfig[]; | ||
sorting: SortingConfig[]; | ||
} | ||
|
||
export const Table = { | ||
Column | ||
Column, | ||
Sorting | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...src/admin/components/ContentEntries/TrashBin/adapters/TrashBinDeleteItemGraphQLGateway.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ApolloClient } from "apollo-client"; | ||
import { ITrashBinDeleteItemGateway } from "@webiny/app-trash-bin"; | ||
import { CmsModel } from "@webiny/app-headless-cms-common/types"; | ||
import { | ||
CmsEntryDeleteMutationResponse, | ||
CmsEntryDeleteMutationVariables, | ||
createDeleteMutation | ||
} from "@webiny/app-headless-cms-common"; | ||
|
||
export class TrashBinDeleteItemGraphQLGateway implements ITrashBinDeleteItemGateway { | ||
private client: ApolloClient<any>; | ||
private model: CmsModel; | ||
|
||
constructor(client: ApolloClient<any>, model: CmsModel) { | ||
this.client = client; | ||
this.model = model; | ||
} | ||
|
||
async execute(id: string) { | ||
const { data: response } = await this.client.mutate< | ||
CmsEntryDeleteMutationResponse, | ||
CmsEntryDeleteMutationVariables | ||
>({ | ||
mutation: createDeleteMutation(this.model), | ||
variables: { | ||
revision: id, | ||
permanently: true | ||
} | ||
}); | ||
|
||
if (!response) { | ||
throw new Error("Network error while deleting entry."); | ||
} | ||
|
||
const { data, error } = response.content; | ||
|
||
if (!data) { | ||
throw new Error(error?.message || "Could not delete the entry."); | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.