Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4597 from kishanprmr/webflow
feat(webflow): fix show collection fields in all items actions
- Loading branch information
Showing
16 changed files
with
861 additions
and
838 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-webflow", | ||
"version": "0.1.4" | ||
"version": "0.1.5" | ||
} |
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
104 changes: 55 additions & 49 deletions
104
packages/pieces/community/webflow/src/lib/actions/create-collection-item.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 |
---|---|---|
@@ -1,56 +1,62 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { | ||
HttpRequest, | ||
HttpMethod, | ||
httpClient, | ||
AuthenticationType, | ||
} from '@activepieces/pieces-common'; | ||
import { createAction, DynamicPropsValue, Property } from '@activepieces/pieces-framework'; | ||
|
||
import { webflowAuth } from '../..'; | ||
import { webflowCommon } from '../common/common'; | ||
import { webflowProps } from '../common/props'; | ||
import { WebflowApiClient } from '../common/client'; | ||
|
||
export const webflowCreateCollectionItem = createAction({ | ||
auth: webflowAuth, | ||
name: 'create_collection_item', | ||
description: 'Create collection item', | ||
displayName: 'Create an item in a collection', | ||
props: { | ||
site_id: webflowCommon.sitesDropdown, | ||
collection_id: webflowCommon.collectionsDropdown, | ||
values: webflowCommon.collectionFieldProperties, | ||
is_archived: Property.Checkbox({ | ||
displayName: 'Is Archived', | ||
description: 'Whether the item is archived or not', | ||
required: false, | ||
}), | ||
is_draft: Property.Checkbox({ | ||
displayName: 'Is Draft', | ||
description: 'Whether the item is a draft or not', | ||
required: false, | ||
}), | ||
}, | ||
export const webflowCreateCollectionItemAction = createAction({ | ||
auth: webflowAuth, | ||
name: 'create_collection_item', | ||
displayName: 'Create Collection Item', | ||
description: 'Creates new collection item.', | ||
props: { | ||
site_id: webflowProps.site_id, | ||
collection_id: webflowProps.collection_id, | ||
collection_fields: webflowProps.collection_fields, | ||
is_archived: Property.Checkbox({ | ||
displayName: 'Is Archived', | ||
description: 'Whether the item is archived or not', | ||
required: false, | ||
}), | ||
is_draft: Property.Checkbox({ | ||
displayName: 'Is Draft', | ||
description: 'Whether the item is a draft or not', | ||
required: false, | ||
}), | ||
}, | ||
async run(context) { | ||
const collectionId = context.propsValue.collection_id; | ||
const isArchived = context.propsValue.is_archived; | ||
const isDraft = context.propsValue.is_draft; | ||
const collectionInputFields = context.propsValue.collection_fields; | ||
|
||
async run(configValue) { | ||
const accessToken = configValue.auth['access_token']; | ||
const collectionId = configValue.propsValue['collection_id']; | ||
const isArchived = configValue.propsValue['is_archived']; | ||
const isDraft = configValue.propsValue['is_draft']; | ||
const client = new WebflowApiClient(context.auth.access_token); | ||
const { fields: CollectionFields } = await client.getCollection(collectionId); | ||
|
||
const request: HttpRequest = { | ||
method: HttpMethod.POST, | ||
url: `https://api.webflow.com/collections/${collectionId}/items`, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: accessToken, | ||
}, | ||
body: { | ||
fields: configValue.propsValue['values'], | ||
isArchived, | ||
isDraft, | ||
}, | ||
}; | ||
const formattedCollectionFields: DynamicPropsValue = {}; | ||
for (const field of CollectionFields) { | ||
const fieldValue = collectionInputFields[field.slug]; | ||
|
||
const res = await httpClient.sendRequest<never>(request); | ||
if (fieldValue !== undefined && fieldValue !== '') { | ||
switch (field.type) { | ||
case 'ImageRef': | ||
case 'FileRef': | ||
formattedCollectionFields[field.slug] = { url: fieldValue }; | ||
break; | ||
case 'Set': | ||
formattedCollectionFields[field.slug] = fieldValue.map((url: string) => ({ url: url })); | ||
break; | ||
case 'Number': | ||
formattedCollectionFields[field.slug] = Number(fieldValue); | ||
break; | ||
default: | ||
formattedCollectionFields[field.slug] = fieldValue; | ||
} | ||
} | ||
} | ||
|
||
return res.body; | ||
}, | ||
return await client.createCollectionItem(collectionId, { | ||
fields: { ...formattedCollectionFields, _archived: isArchived, _draft: isDraft }, | ||
}); | ||
}, | ||
}); |
52 changes: 19 additions & 33 deletions
52
packages/pieces/community/webflow/src/lib/actions/delete-collection-item.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 |
---|---|---|
@@ -1,40 +1,26 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { | ||
HttpRequest, | ||
HttpMethod, | ||
httpClient, | ||
AuthenticationType, | ||
} from '@activepieces/pieces-common'; | ||
import { createAction } from '@activepieces/pieces-framework'; | ||
|
||
import { webflowAuth } from '../..'; | ||
import { webflowCommon } from '../common/common'; | ||
import { webflowProps } from '../common/props'; | ||
import { WebflowApiClient } from '../common/client'; | ||
|
||
export const webflowDeleteCollectionItem = createAction({ | ||
auth: webflowAuth, | ||
name: 'delete_collection_item', | ||
description: 'Delete collection item', | ||
displayName: 'Delete an item in a collection', | ||
props: { | ||
site_id: webflowCommon.sitesDropdown, | ||
collection_id: webflowCommon.collectionsDropdown, | ||
collection_item_id: webflowCommon.collectionItemsDropdown, | ||
}, | ||
|
||
async run(configValue) { | ||
const accessToken = configValue.auth['access_token']; | ||
const collectionId = configValue.propsValue['collection_id']; | ||
const collectionItemId = configValue.propsValue['collection_item_id']; | ||
auth: webflowAuth, | ||
name: 'delete_collection_item', | ||
description: 'Delete collection item', | ||
displayName: 'Delete an item in a collection', | ||
props: { | ||
site_id: webflowProps.site_id, | ||
collection_id: webflowProps.collection_id, | ||
collection_item_id: webflowProps.collection_item_id, | ||
}, | ||
|
||
const request: HttpRequest = { | ||
method: HttpMethod.DELETE, | ||
url: `https://api.webflow.com/collections/${collectionId}/items/${collectionItemId}`, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: accessToken, | ||
}, | ||
}; | ||
async run(context) { | ||
const collectionId = context.propsValue.collection_id; | ||
const collectionItemId = context.propsValue.collection_item_id; | ||
|
||
const res = await httpClient.sendRequest<never>(request); | ||
const client = new WebflowApiClient(context.auth.access_token); | ||
|
||
return res.body; | ||
}, | ||
return await client.deleteCollectionItem(collectionId, collectionItemId); | ||
}, | ||
}); |
Oops, something went wrong.