enuchi / React-Google-Apps-Script

This is your boilerplate project for developing React apps inside Google Sheets, Docs, Forms and Slides projects. It's perfect for personal projects and for publishing complex add-ons in the Google Workspace Marketplace.
MIT License
1.34k stars 178 forks source link

Client-side functions limitation #104

Closed gabrielrezk closed 3 years ago

gabrielrezk commented 3 years ago

Hi, I am getting started with this boilerplate, trying to migrate a working sheets add-on. And I think I found a limitation.

In our current add-on we used to call the following function to open a modal: Ui.showModelessDialog (https://developers.google.com/apps-script/reference/base/ui#showModelessDialog(Object,String)).

Also, to close it, we call the client-side function google.script.host.close. But using the boilerplate I found that the google variable is not accessible.

Is there a way to call such client-side functions? Thanks in advance, and awesome work!

Update: The problem only occurs when running the project locally. This happens because the iframe that loads the project from the development server doesn't have access to this variable.

enuchi commented 3 years ago

Hi @gabrielrezk, correct, this won't work locally, but will work fine in production. It's possible to make this work locally, but just haven't implemented it since it doesn't seem that critical and it will work fine in production. Do you want to work on this feature? Can point you in the right direction if you're interested.

gabrielrezk commented 3 years ago

Thanks for your reply @enuchi.

Right, as it works in production it isn't a big deal. But it'd be nice to have it so I might take a look at it at some point.

Do you have something in mind?

enuchi commented 3 years ago

Yep, you'd have to make several changes:

It would be very similar to what I've implemented to call server-side functions in local development, but a bit easier because you don't have to listen for a response in the other direction (google.script.host.close() doesn't return anything). Still quite a bit of work though... 😄

enuchi commented 3 years ago

Linking to another issue where this came up: https://github.com/enuchi/React-Google-Apps-Script/issues/60.

There is probably a neat way to do this so other client-side google functions aside can be used in local development @gabrielrezk. Keep me posted if you look into this.

gabrielrezk commented 3 years ago

Great @enuchi! Thanks for your input, I'll keep you posted.

marek-baranowski commented 2 years ago

Hello, Is there some nicer way of using google.script.host.close(); in development than hacking like this? :) https://gist.github.com/tanaikech/c1b5fb20342dae623139ca0f48c8c12c

enuchi commented 2 years ago

In production you just call google.script.host.close() on the client. If you wanted to get it to work in development you'd have to follow the steps I listed above.

marek-baranowski commented 2 years ago

Yes it does work when deployed, just that breaks that great dev flow a little :) the missinghost and url does complicate stuff a little... would appreciate a piece of code that would make it a bit more clear so I could take it from there and implement the missing parts.