This repository demonstrates a bare bones Looker extension using Typescript.
It uses React and Typescript for writing your extension, the React Extension SDK for interacting with Looker, Looker Components for UI, and Webpack for building your code.
-
Clone or download a copy of this template to your development machine, if you haven't already cloned the entire repo.
# cd ~/ Optional, your user directory is usually a good place to git clone to. git clone [email protected]:looker-open-source/extension-examples.git
-
Navigate (
cd
) to the template directory on your systemcd extension-examples/react/typescript/helloworld-ts
-
Install the dependencies with
npm
.npm install
You may need to update your Node version or use a Node version manager to change your Node version.
-
Start the development server
npm run develop
The extension is now running and serving the JavaScript locally at https://localhost:8080/bundle.js.
-
Log in to Looker and create a new project.
This is found under Develop => Manage LookML Projects => New LookML Project.
Select "Blank Project" as your "Starting Point". This will create a new project with no files.
- The extension folder has a
manifest.lkml
file.
Either drag & upload this file into your Looker project, or create a
manifest.lkml
with the same content. Change theid
,label
, orurl
as needed.project_name: "helloworld-ts" application: helloworld-ts { label: "Helloworld (TypeScript)" url: "https://localhost:8080/bundle.js" entitlements: { core_api_methods: ["me"] } }
- The extension folder has a
- Create a
model
LookML file in your project. The name doesn't matter but the convention is to name it the same as the project— in this case, helloworld-js.
- Add a connection in this model.
- Configure the model you created so that it has access to the selected connection. We do this because Looker permissions data access via models— In order to grant / limit access to an extension, it must be associated with a model.
- Connect the project to Git. This can be done in multiple ways:
- Create a new repository on GitHub or a similar service, and follow the instructions to connect your project to Git
- A simpler but less powerful approach is to set up git with the "Bare" repository option which does not require connecting to an external Git Service.
-
Commit the changes and deploy them to production through the Project UI.
-
Reload the page and click the
Browse
dropdown menu. You will see the extension in the list.
- The extension will load the JavaScript from the
url
provided in theapplication
definition. By default, this is https://localhost:8080/bundle.js. If you change the port your server runs on in the package.json, you will need to also update it in the manifest.lkml. - Refreshing the extension page will bring in any new code changes from the extension template, although some changes will hot reload.
Entitlements are defined in the project manifest file for the extension.
Resources required by the extension (Looker API methods for example) must be defined in entitlements. This extension uses the me
api method, as such it is defined in the entitlements.
[//] TODO: List entitlement options.
The process above describes how to run the extension for development. Once you're done developing and ready to deploy, the production version of the extension may be deployed as follows:
-
In the extension project directory build the extension by running
npm run build
. -
Drag and drop the generated
dist/bundle.js
file into the Looker project interface -
Modify the
manifest.lkml
to usefile
instead ofurl
:project_name: "helloworld-ts" application: helloworld-ts { label: "Helloworld (TypeScript)" url: "https://localhost:8080/bundle.js" file: "bundle.js" entitlements: { core_api_methods: ["me"] } }
- Webpack's module splitting is not currently supported.
- This template uses Looker's component library and styled components. Neither of these libraries are required, and you may remove and replace them with a component library of your own choice or simply build your UI from scratch.