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

Webhook trigger update by column #832

Merged

Conversation

CamilleLegeron
Copy link
Collaborator

@CamilleLegeron CamilleLegeron commented Jan 25, 2024

Context

#763

Done

Screencast from 06-02-2024 11:44:39.webm
Screencast from 06-02-2024 11:46:48.webm

I used a string for columnIds because it seems to be difficult to show only the list corresponding to the selected tableId to the user. If we change the list shown to the user we change it for all instance of webhooks, that it's not acceptable.

@CamilleLegeron
Copy link
Collaborator Author

The last error seams to have no link to my feature ..

@CamilleLegeron CamilleLegeron marked this pull request as ready for review February 6, 2024 15:29
@alexmojaki alexmojaki requested review from paulfitz and JakubSerafin and removed request for alexmojaki February 7, 2024 16:31
@alexmojaki
Copy link
Contributor

Thanks @CamilleLegeron for the contribution! I'm afraid I'm not working at GristLabs any more though, so I've requested review from others.

@CamilleLegeron CamilleLegeron requested review from paulfitz and removed request for paulfitz February 8, 2024 08:48
Copy link
Collaborator

@fflorent fflorent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments I hope that may help :)

app/server/lib/DocApi.ts Outdated Show resolved Hide resolved
sandbox/grist/migrations.py Outdated Show resolved Hide resolved
app/server/lib/DocApi.ts Outdated Show resolved Hide resolved
app/server/lib/DocApi.ts Outdated Show resolved Hide resolved
@@ -10,6 +10,7 @@ export interface WebhookFields {
url: string;
eventTypes: Array<"add"|"update">;
tableId: string;
columnIds: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may run yarn build:prod to update the Triggers-ti.ts file (whose classes are used as body validator for the APIs):

$ yarn build:prod
yarn run v1.22.21
$ buildtools/build.sh
+ tsc --build
+ buildtools/update_type_info.sh app
Updating app/common/Triggers-ti.ts from app/common/Triggers.ts
Updating app/plugin/CustomSectionAPI-ti.ts from app/plugin/CustomSectionAPI.ts
Updating app/plugin/GristData-ti.ts from app/plugin/GristData.ts
...

Copy link
Collaborator

@fflorent fflorent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have few more comments :)

app/common/schema.ts Outdated Show resolved Hide resolved

const webhook = await autoSubscribe('200', docId, {
columnIds: 'A', eventTypes: ['add', 'update']
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be hard to add another test with a second column in columnIds?
This would allow to check whether the ; works as expected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your right, I will do it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

test/server/lib/DocApi.ts Outdated Show resolved Hide resolved
@CamilleLegeron
Copy link
Collaborator Author

Hi, I just put a new notification for you paulfitz in case you haven't seen this PR. Sorry if your are too busy, in that case I can ask other dev in gristlabs to review this PR.

@paulfitz paulfitz removed the request for review from JakubSerafin March 20, 2024 13:49
Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @CamilleLegeron !

test/server/lib/DocApi.ts Outdated Show resolved Hide resolved
};

// subscribe
const webhook = await subscribe('foo', docId, origFields);
const { data } = await axios.post(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change just to use newer /webhooks instead of older /_subscribe endpoint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good to test the newer endpoint but I don't remember if in this case something went wrong with the older
Do you want me to create a specific subscribe function with the new endpoint call and rename the old one with oldEndpointsubscribe or something like that

throw new ApiError(`Cannot find columns "${columnIds}" because table is not known`, 404);
}
// columnIds have to be of shape "columnId; columnId; columnId"
fields.columnRefList = [GristObjCode.List, ...columnIds.split(";")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here, we are in the back-end, defining the behavior of a REST API endpoint. Sending ;-separated columns seems pretty inconsistent with how lists are handled elsewhere in the API. I can understand doing that in the minimalist front-end UI, just because of lack of time to do something pretty (the same trade-off we made for isReadyColumn), but is there a way to isolate that to the front end? Once the back-end does something, changing it is hard since someone may rely on it.

It will be sad if we eventually add a pretty UI for this and it ends up having the convert a nice structured list of column ids into a semicolon separated string to send to the back end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

columnIds is a little vague, and a bit inconsistent with isReadyColumn which doesn't specify the Id part. Maybe something like watchedColumns?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if column ids are stored as strings, would need some thinking about updating them when columns are renamed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This remark is a very good point, I isolated this logical in the frontend.
The watchedColIds is stored in the db as watchedColRefList so if the column is renamed it's works well

sandbox/grist/schema.py Outdated Show resolved Hide resolved
app/client/ui/WebhookPage.ts Outdated Show resolved Hide resolved
@paulfitz
Copy link
Member

The test failure looks relevant:

(1) DocApi should work directly with a docworker Webhooks /webhooks endpoint should call to a webhook only when columns updated are in watchedColIds if not empty
AssertionError: expected false to be true
    ...
    at assertSuccessCalled (test/server/lib/DocApi.ts:4448:18)
    at Context.<anonymous> (test/server/lib/DocApi.ts:4490:15)

@CamilleLegeron
Copy link
Collaborator Author

The test failure looks relevant:

(1) DocApi should work directly with a docworker Webhooks /webhooks endpoint should call to a webhook only when columns updated are in watchedColIds if not empty
AssertionError: expected false to be true
    ...
    at assertSuccessCalled (test/server/lib/DocApi.ts:4448:18)
    at Context.<anonymous> (test/server/lib/DocApi.ts:4490:15)

Well ... I don't understand why this error happen, reinitializing the migration it works well

Copy link
Collaborator

@fflorent fflorent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for me modulo my comment related to the options column.

@CamilleLegeron
Copy link
Collaborator Author

@paulfitz, send you this notification in case you haven't seen I worked on this PR :)

Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this @CamilleLegeron !

@paulfitz paulfitz merged commit 76ef4d5 into gristlabs:main Apr 12, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants