Skip to content

Commit

Permalink
more settings enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
enuchi committed Sep 17, 2018
1 parent 3e2d186 commit ff3f14a
Show file tree
Hide file tree
Showing 24 changed files with 10,800 additions and 422 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .clasp.json
@@ -1,4 +1,4 @@
{
"rootDir": "dist",
"scriptId":"*** scriptId from GAS Script Editor, File -> Project properties ***"
"scriptId":"17yhkDaoyccM467KaeWLmLG3DndMgoeUCawf9SEkMq1-AogZ6l1c9e3Qe"
}
16 changes: 0 additions & 16 deletions .eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
node_modules
node_modules
.clasp.json
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

15 changes: 15 additions & 0 deletions .tern-project
@@ -0,0 +1,15 @@
{
"ecmaVersion": 7,
"libs": [
],
"plugins": {
"complete_strings": {},
"googleappsscript": {},
"es_modules": {},
"node": {},
"doc_comment": {
"fullDocs": true,
"strong": true
}
}
}
80 changes: 67 additions & 13 deletions README.md
@@ -1,33 +1,87 @@
#React + Google Apps Script
## React + Google Apps Script
*Use this repo as your boilerplate React app for use with HTML dialogs in Google Sheets, Docs and Forms.*

Use this repo as your boilerplate React app for use with Google Apps Script html dialogs.
This project uses labnol's excellent [apps-script-starter](https://github.com/labnol/apps-script-starter) as a starting point, adding support for client-side dialogs built with React. It demonstrates how easy it is to build React apps that interact with Google Apps server-side scripts.

It uses labnol's excellent [apps-script-starter](https://github.com/labnol/apps-script-starter) project as a starting point, but adds support for client-side dialogs built with React, and shows how React pages can interact with Google Apps server-side script.

**Installation**
## Installation

Set up the sample project:
```
mkdir my-gas-react-app && cd my-gas-react-app
clone https://github.com/enuchi/React-Google-Apps-Script.git
git clone https://github.com/enuchi/React-Google-Apps-Script.git
npm install
```
Create a new Google Sheets spreadsheet. Open the Script Editor (Tools --> Script Editor) and copy the ScriptId (File --> Project properties).

Add the ScriptId to the .clasp.json file:
```
// .clasp.json
{
"rootDir": "dist",
"scriptId":"...paste scriptId here..."
}
{"rootDir": "dist",
"scriptId":"...paste scriptId here..."}
```
Log into CLASP, which lets you develop Apps Script projects locally, and follow the authorization flow:
Log into CLASP, a tool that lets you develop Apps Script projects locally, and follow the authorization flow:
```
npx clasp login
```
Build and deploy the app!
Modify your server-side and client-side code in the `src` folder using ES6/7 and React. Change the scopes in `appsscript.json`. When you're ready, build the app!
```
npm run build
npm run deploy
```
Webpack will bundle your files in `dist`. Push your files to Google's servers using CLASP:
```
clasp push
```


## The sample app
Insert new sheets and delete sheets through a simple dialog, built with React:

## How it works
Code is written in the `src` directory and bundled into the `dist` directory when `npm run build` is run. CLASP pushes files from `dist` to Script Editor files.

Multiple Webpack entry points are used to generate code that is compatible with the Google Apps Script environment on both server and client. On the server side that means ending up as (basically) ES5. On the client side, the challenge is that GAS does not easily support multiple pages, so a single HTML page is created. This is done with the help of some Webpack plugins that use HTML templates and add the necessary CSS and JavaScript/React assets inline. (You'll see the original output bundle, `main.js`, in the `dist` directory, but it's ignored through .clasp.ignore). The appsscript.json manifest file is simply copied into `dist`.

## Features
- Support for JSX syntax:
```
render() {
return (<div className="formBlock"><span>Add a sheet: </span>
<form onSubmit={(e) => this.handleSubmit(e)}>
<input onChange={this.handleChange} value={this.state.text} />
</form>
</div>);
}
```
- Support for npm packages. Simply install with npm and `import`:
```
import React from "react";
import ReactDOM from "react-dom";
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
```
- `import` CSS from another file:
```
import "./styles.css";
```
- Shows how server calls are made in React using `google.script.run`:
```
componentDidMount() {
google.script.run
.withSuccessHandler((data) => this.setState({names: data}))
.withFailureHandler((error) => alert(error))
.getSheetsData()
}
```

## Extending this app
- You can split up server-side code into multiple files and folders . Simply use `import` and `export`.
- Make sure to expose all public functions (functions called from the client with `google.script.run`) as well as onOpen using e.g.:
```
const onOpen = () => {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Dialog')
.addItem('Add sheets', 'openDialog')
.addToUi();
}
global.onOpen = onOpen
```

0 comments on commit ff3f14a

Please sign in to comment.