-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Multiple operations on webhooks #7807
Conversation
); | ||
} else { | ||
this.logger.debug( | ||
`CallWebhookJobsJob on eventName '${eventName}' did not trigger any webhooks.`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont really need this log right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think we can remove those 'not trigger any ...' logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ehconitin thanks for your PR. The code looks good to me but I think we must take care of the data migrations. I suggest a 2 steps migration strategy:
First PR
- leave
operation
column like it exists now and create a new columnoperations
- create the command to copy data from
operation
tooperations
with arrays of lenght 1 - duplicate
operation
updates into theoperations
column
Second PR
- update the frontend and backend so it uses
operations
instead ofoperation
- add the frontend code that enable
operations
arrays of length > 1 - remove the
operation
column
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
); | ||
} else { | ||
this.logger.debug( | ||
`CallWebhookJobsJob on eventName '${eventName}' did not trigger any webhooks.`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think we can remove those 'not trigger any ...' logs
@WorkspaceField({ | ||
standardId: WEBHOOK_STANDARD_FIELD_IDS.operation, | ||
type: FieldMetadataType.TEXT, | ||
type: FieldMetadataType.ARRAY, | ||
label: 'Operation', | ||
description: 'Webhook operation', | ||
icon: 'IconCheckbox', | ||
}) | ||
operation: string; | ||
operations: string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should proceed with a 2 steps strategy to migrate data properly:
First PR
- leave
operation
column like it exists now and create a new columnoperations
- create the command to copy data from
operation
tooperations
with arrays of lenght 1 - duplicate
operation
updates into theoperations
column
Second PR
- update the frontend and backend so it uses
operations
instead ofoperation
- add the frontend code that enable
operations
arrays of length > 1 - remove the
operation
column
@Bonapara @martmull update - just saw #7807 (comment) webhook_new.mp4 |
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
@ehconitin |
Yep! missed your comment explaining this behavior in the above comments! Understood! Thanks |
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Show resolved
Hide resolved
{ value: '*', label: 'All Actions', Icon: IconNorthStar }, | ||
{ value: 'create', label: 'Create', Icon: IconPlus }, | ||
{ value: 'update', label: 'Update', Icon: IconRefresh }, | ||
{ value: 'delete', label: 'Delete', Icon: IconTrash }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charlesBochet @Bonapara should we add destroy
there?
@ehconitin you can add it if needed
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
All requested changes from the review have been addressed! TODO:
|
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Show resolved
Hide resolved
...-front/src/pages/settings/developers/webhooks/components/SettingsDevelopersWebhookDetail.tsx
Outdated
Show resolved
Hide resolved
- Mark operation as deprecated - Add operations migration command - Avoid breaking changes - Fix ellipsis display - Improve empty operation apearance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR implements multiple operations for webhooks, addressing issue #7792. The changes include updating both frontend and backend components to support an array of operations instead of a single operation.
- Added 'operations' field to WebhookWorkspaceEntity and deprecated 'operation' field
- Updated SettingsDevelopersWebhookDetail component to handle multiple operations
- Implemented CopyWebhookOperationIntoOperationsCommand for data migration
- Modified CallWebhookJobsJob to query and process multiple operations
- Added new icons (IconHandClick and IconNorthStar) to support the UI changes
14 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings | Greptile
const baseOperations = data?.operations | ||
? data.operations.map((op: string) => { | ||
const [object, action] = op.split('.'); | ||
return { object, action }; | ||
}) | ||
: data?.operation | ||
? [ | ||
{ | ||
object: data.operation.split('.')[0], | ||
action: data.operation.split('.')[1], | ||
}, | ||
] | ||
: []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: This logic might be better placed in a separate function for clarity
const baseOperations = data?.operations | |
? data.operations.map((op: string) => { | |
const [object, action] = op.split('.'); | |
return { object, action }; | |
}) | |
: data?.operation | |
? [ | |
{ | |
object: data.operation.split('.')[0], | |
action: data.operation.split('.')[1], | |
}, | |
] | |
: []; | |
const mapOperations = (data) => { | |
return data?.operations | |
? data.operations.map((op: string) => { | |
const [object, action] = op.split('.'); | |
return { object, action }; | |
}) | |
: data?.operation | |
? [ | |
{ | |
object: data.operation.split('.')[0], | |
action: data.operation.split('.')[1], | |
}, | |
] | |
: []; | |
}; | |
const baseOperations = mapOperations(data); |
operation: cleanedOperations?.[0], | ||
operations: cleanedOperations, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Saving both 'operation' and 'operations' might lead to inconsistencies. Consider removing 'operation'
operation: cleanedOperations?.[0], | |
operations: cleanedOperations, | |
await updateOneRecord({ | |
idToUpdate: webhookId, | |
updateOneRecordInput: { | |
operations: cleanedOperations, | |
description: description, | |
}, | |
}); |
if ( | ||
!newOperations.some((op) => op.object === '*' && op.action === '*') && | ||
!newOperations.some((op) => op.object === null || op.action === null) | ||
) { | ||
return [...newOperations, WEBHOOK_EMPTY_OPERATION]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: This logic might add unnecessary empty operations. Consider simplifying
if ( | |
!newOperations.some((op) => op.object === '*' && op.action === '*') && | |
!newOperations.some((op) => op.object === null || op.action === null) | |
) { | |
return [...newOperations, WEBHOOK_EMPTY_OPERATION]; | |
} | |
if (!newOperations.some((op) => op.object === '*' && op.action === '*')) { | |
return [...newOperations, WEBHOOK_EMPTY_OPERATION]; | |
} |
const [formValues, setFormValues] = useState<{ | ||
targetUrl: string; | ||
operation: string; | ||
operations: string[]; | ||
}>({ | ||
targetUrl: '', | ||
operation: '*.*', | ||
operations: ['*.*'], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Consider removing the 'operation' field from the state as it's being replaced by 'operations' array. This will prevent potential inconsistencies.
const [formValues, setFormValues] = useState<{ | |
targetUrl: string; | |
operation: string; | |
operations: string[]; | |
}>({ | |
targetUrl: '', | |
operation: '*.*', | |
operations: ['*.*'], | |
}); | |
const [formValues, setFormValues] = useState<{ | |
targetUrl: string; | |
operations: string[]; | |
}>({ | |
targetUrl: '', | |
operations: ['*.*'], | |
}); |
if ('operation' in webhook) { | ||
await webhookRepository.update(webhook.id, { | ||
operations: [webhook.operation], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Consider handling the case where 'operations' already exists to avoid overwriting existing data
await webhookRepository.update(webhook.id, { | ||
operations: [webhook.operation], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Ensure webhook.operation is not null or undefined before adding to array
'webhook', | ||
); | ||
|
||
const webhooks = await webhookRepository.find(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using pagination for large datasets to avoid potential memory issues
options: BaseCommandOptions, | ||
activeWorkspaceIds: string[], | ||
): Promise<void> { | ||
this.logger.log('Running command to copy operation to operations'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Log the total number of workspaces being processed for better progress tracking
this.logger.log( | ||
chalk.yellow(`Copied webhook operation to operations`), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Log the webhook ID for better traceability
icon: 'IconCheckbox', | ||
defaultValue: ['*.*'], | ||
}) | ||
operations: string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: operations field should have a more specific type than string[], e.g., string[] as WebhookOperation[]
operations: string[]; | |
type WebhookOperation = string; // Define a specific type for operations | |
operations: WebhookOperation[]; |
@martmull @ehconitin Let me know when you're finished with this so I can do a final Product / Design review ;) |
Finished |
fixes #7792
WIP :)
webhook.mp4