Skip to content

Commit 2772446

Browse files
committed
Create+Delete item
1 parent 917d3b0 commit 2772446

File tree

2 files changed

+24
-40
lines changed

2 files changed

+24
-40
lines changed

components/webflow/actions/create-collection-item/create-collection-item.mjs renamed to components/webflow_v2/actions/create-collection-item/create-collection-item.mjs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
1-
import webflow from "../../webflow.app.mjs";
1+
import app from "../../webflow_v2.app.mjs";
22

33
export default {
4-
key: "webflow-create-collection-item",
4+
key: "webflow_v2-create-collection-item",
55
name: "Create Collection Item",
66
description: "Create new collection item. [See the docs here](https://developers.webflow.com/#create-new-collection-item)",
7-
version: "0.1.7",
7+
version: "0.0.{{ts}}",
88
type: "action",
99
props: {
10-
webflow,
10+
app,
1111
siteId: {
1212
propDefinition: [
13-
webflow,
13+
app,
1414
"sites",
1515
],
1616
},
1717
collectionId: {
1818
propDefinition: [
19-
webflow,
19+
app,
2020
"collections",
2121
(c) => ({
2222
siteId: c.siteId,
2323
}),
2424
],
2525
reloadProps: true,
2626
},
27-
live: {
28-
label: "Live",
29-
description: "Indicate if the item should be published to the live site",
30-
type: "boolean",
31-
default: false,
32-
},
3327
},
3428
async additionalProps() {
3529
const props = {};
3630
if (!this.collectionId) {
3731
return props;
3832
}
39-
const { fields } = await this.webflow.getCollection(this.collectionId);
33+
const { fields } = await this.app.getCollection(this.collectionId);
4034
for (const field of fields) {
41-
if (field.editable && field.slug !== "_archived" && field.slug !== "_draft") {
35+
if (field.editable && field.slug !== "isArchived" && field.slug !== "isDraft") {
4236
props[field.slug] = {
4337
type: "string",
4438
label: field.name,
@@ -55,29 +49,23 @@ export default {
5549
},
5650
async run({ $ }) {
5751
const {
58-
webflow,
52+
app,
5953
// eslint-disable-next-line no-unused-vars
6054
siteId,
61-
// eslint-disable-next-line no-unused-vars
6255
collectionId,
63-
live,
6456
...fields
6557
} = this;
6658

67-
const webflowClient = webflow._createApiClient();
68-
69-
const response = await webflowClient.createItem({
70-
collectionId: this.collectionId,
71-
fields: {
59+
const response = await app.createCollectionItem({
60+
collectionId,
61+
fieldData: {
7262
...fields,
73-
_archived: false,
74-
_draft: false,
63+
isArchived: false,
64+
isDraft: false,
7565
},
76-
}, {
77-
live,
7866
});
7967

80-
$.export("$summary", `Successfully created collection item ${fields.name}`);
68+
$.export("$summary", `Successfully created collection item ${fields.name ?? ""}`);
8169

8270
return response;
8371
},

components/webflow/actions/delete-collection-item/delete-collection-item.mjs renamed to components/webflow_v2/actions/delete-collection-item/delete-collection-item.mjs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import webflow from "../../webflow.app.mjs";
1+
import app from "../../webflow_v2.app.mjs";
22

33
export default {
4-
key: "webflow-delete-collection-item",
4+
key: "webflow_v2-delete-collection-item",
55
name: "Delete Collection Item",
66
description: "Delete Item of a Collection. [See the docs here](https://developers.webflow.com/#remove-collection-item)",
7-
version: "0.0.5",
7+
version: "0.0.{{ts}}",
88
type: "action",
99
props: {
10-
webflow,
10+
app,
1111
siteId: {
1212
propDefinition: [
13-
webflow,
13+
app,
1414
"sites",
1515
],
1616
},
1717
collectionId: {
1818
propDefinition: [
19-
webflow,
19+
app,
2020
"collections",
2121
(c) => ({
2222
siteId: c.siteId,
@@ -25,7 +25,7 @@ export default {
2525
},
2626
itemId: {
2727
propDefinition: [
28-
webflow,
28+
app,
2929
"items",
3030
(c) => ({
3131
collectionId: c.collectionId,
@@ -34,12 +34,8 @@ export default {
3434
},
3535
},
3636
async run({ $ }) {
37-
const webflow = this.webflow._createApiClient();
38-
39-
const response = await webflow.removeItem({
40-
collectionId: this.collectionId,
41-
itemId: this.itemId,
42-
});
37+
const { collectionId, itemId } = this;
38+
const response = await this.app.deleteCollectionItem(collectionId, itemId);
4339

4440
$.export("$summary", "Successfully deleted item");
4541

0 commit comments

Comments
 (0)