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

Add local config files #180

Merged
merged 23 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

Topics discussed:

* Configs
* OAuth ID
* Repository layout
* The library renders within an iframe
* Color palette and themes

## Configs
Config files are loaded based on the environment from the `src/config` directory. If you need to override
some of the values you can create a `development.local.json` that will be ignored by git.
See [src/config/README.md](./src/config/README.md) for more info.

## OAuth ID

The standalone target uses the `oauth_client_id` at [targets/standalone/config/index.js](./targets/standalone/config/index.js) to authenticate requests to WordPress.com.
Expand Down
10 changes: 10 additions & 0 deletions src/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Config files

Based on the value of `process.env.NODE_ENV` either `development.json` or `production.json` will be
loaded.

If you need to use override some configuration fields while developing you can create a `development.local.json`
file in this folder, which will be ignored by git and will get precedence over the values in `development.json`

If there is a `development.local.json` file it will get merged with the JSON object from `development.json`
overriding the values for the fields they share.
9 changes: 9 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @format */
/**
* External dependencies
*/
import merge from 'lodash/merge';

/**
* Internal dependencies
Expand All @@ -8,6 +12,11 @@ import createConfig from 'src/lib/create-config';
let configFile;
if ( 'development' === process.env.NODE_ENV ) {
configFile = require( 'src/config/development.json' );
try {
// check if we have local git ignored config and use it to override the development.json
const localConfig = require( 'src/config/development.local.json' );
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

merge( configFile, localConfig );
} catch ( e ) {}
} else {
configFile = require( 'src/config/production.json' );
}
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ const createIframe = ( props, assetsLoadedHook = () => {} ) => {
const styleHC = document.createElement( 'link' );
styleHC.setAttribute( 'rel', 'stylesheet' );
styleHC.setAttribute( 'type', 'text/css' );
styleHC.setAttribute( 'href', 'https://widgets.wp.com/happychat/happychat.css' );

// while developing load local css
if ( process.env.NODE_ENV === 'development' ) {
styleHC.setAttribute( 'href', 'happychat.css' );
} else {
styleHC.setAttribute( 'href', 'https://widgets.wp.com/happychat/happychat.css' );
}

// TODO: rework this to use skills and have local themes loaded
const styleHCPromise = new Promise( resolve => ( styleHC.onload = () => resolve() ) );

const styleHCTheme = document.createElement( 'link' );
Expand Down
66 changes: 66 additions & 0 deletions targets/standalone/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Happychat Embedded</title>
<style>
body {
margin-left: 12%;
margin-right: 12%;
}
</style>
</head>
<body>
<div id="support"></div>
<script type="text/javascript" src="./happychat.js" charset="utf-8"></script>
<script type="text/javascript">
Happychat.open( {
accessToken: window.HappychatAccessTokenPromise,
nodeId: 'support',
groups: ['woo'],
entryOptions: {
primaryOptions: [
{ 'value': 'before-buy', 'label': 'Before you buy', },
{ 'value': 'account', 'label': 'Help with my account', },
{ 'value': 'broken', 'label': 'Something is broken', canChat: false },
],
secondaryOptions: [
{ 'value': 'config', 'label': 'Help configuring', canChat: false, primary: [ 'account' ], },
{ 'value': 'order', 'label': 'Help with an order', primary: [ 'account' ], },
{ 'value': 'themes', 'label': 'Themes', canChat: false, primary: [ 'before-buy', 'broken' ], },
{ 'value': 'plugins', 'label': 'Plugins', primary: [ 'before-buy', 'broken' ], },
],
itemList: [
{ value: '2010', label: '2010 theme', primary: [ 'before-buy' ], secondary: [ 'themes' ] },
{ value: '2011', label: '2011 theme', primary: [ 'before-buy' ], secondary: [ 'themes' ] },
{ value: 'jp', label: 'Jetpack', secondary: [ 'plugins' ] },
{ value: 'wc', label: 'WooCommerce', secondary: [ 'plugins' ] },
],
fallbackTicket: {
headers: {
'X-Test-Header': 'test header',
'X-Test-Header-2': 'test 2'
},
pathToCreate: '/create-ticket',
pathToShow: '/show-ticket/<ticket-id>',
}
}
} );

// test events API
var reportChatStatus= function(chatStatus){
console.log('chatStatus is ', chatStatus);
}
Happychat.on('chatStatus', reportChatStatus);
var reportAvailability = function(availability){
console.log('availibility is ', availability);
}
Happychat.on('availability', reportAvailability);
window.unload = function() {
console.log('unload');
Happychat.of('availability', reportAvailability);
Happychat.of('chatStatus', reportChatStatus);
}
</script>
</body>
</html>