# frontend-analytics

## Workstation SPA
`frontend-analytics` is part of the workstation single page application. Read up on the framework and tooling by visiting the [frontend-workstation](https://github.com/theorchard/frontend-workstation) repo.

## Setup / Installing
Make sure your environment is up to date:
- node >= `8.11.1` (doesn't work with node 14, probably it would be better to stick with 10)
- yarn >= `1.15.2`


Make sure you have configured the private npm registry used by `workstation-cli`. **Read the documentation on how to configure it.**
https://github.com/theorchard/frontend-cli/blob/b035b7ce3e9c24cf63788cb5bd04b9826a2ce52f/docs/usage.md


Initialize environment configuration:

```shell
cp .env.shadow .env
```

Install dependencies

```shell
yarn
```

## Apollo setup
To generate typescript definitions you need to install and setup the apollo client.

First create a local apollo config file.
```shell
cp apollo.config.js.shadow apollo.config.js
```
`Fill in your GRASS_TOKEN in your new apollo.config.js file.`

Then install apollo
```shell
yarn global add apollo
```

Then you can update/generate the types with:
```shell
yarn generate
```

### IDE extensions:
- [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=apollographql.vscode-apollo)

## Running

_**Note**: You will need to be on the VPN (or in the NYC office) to be able to access Orchard services._

Run the local development server:

```shell
yarn start
```

## Features control and flags
For controlling user features during development, add the `USER_FEATURES` or/and `USER_RESTRICTIONS` variables to your .env file.

```bash
#.env file
USER_FEATURES={'analytics_comparison': 'enabled'}
USER_RESTRICTIONS=["Vendor Restricted Feature"]
```

## Localization
For loading the module in different locales, add the `POEDITOR_PROJECT_ID` and `POEDITOR_API_TOKEN` variables to your .env file.

```bash
#.env file
POEDITOR_PROJECT_ID=212659
POEDITOR_API_TOKEN=xxxxxx
```

Then you can start development in e.g. german.
```bash
yarn start -l de
```

## Testing

Run the linter and the tests:

```shell
yarn test
```

Run the linter independently:

```shell
yarn lint
```

Run the unit tests independently:

```shell
yarn test:unit
```

Run the unit tests in watch mode:

```shell
yarn test:unit --watch [pattern]
```
