Skip to content

Instantly share code, notes, and snippets.

@rahulpilani
Created July 24, 2017 00:16
Show Gist options
  • Save rahulpilani/dc9d489fec7cd1376e5ec9e334569963 to your computer and use it in GitHub Desktop.
Save rahulpilani/dc9d489fec7cd1376e5ec9e334569963 to your computer and use it in GitHub Desktop.
exports.decorateTerm = (Term, { React, notify }) => {
// Define and return our higher order component.
return class extends React.Component {
constructor (props, context) {
super(props, context);
this._div = null;
this._onTerminal = this._onTerminal.bind(this);
}
render () {
// Return the default Term component with our custom onTerminal closure
// setting up and managing the particle effects.
if (this.props.prod) {
this._div.style.background = '#733737';
}
// console.log('render', this._div);
return React.createElement(Term, Object.assign({}, this.props, {onTerminal: this._onTerminal}));
}
}
};
exports.middleware = (store) => (next) => (action) => {
// the redux `action` object contains a loose `type` string, the
// 'SESSION_SET_XTERM_TITLE' type identifier corresponds to an action in which
// the terminal wants to update the xterm title.
if ('SESSION_SET_XTERM_TITLE' === action.type) {
// 'SESSION_SET_XTERM_TITLE' actions hold the output title data in the `title` key.
const { uid, title } = action;
if (title.search(/aws\.prod/) > 0) {
store.dispatch({
type: 'ENVIRONMENT_CHANGE',
env: 'PROD',
uid: uid
});
} else {
store.dispatch({
type: 'ENVIRONMENT_CHANGE',
env: 'TEST',
uid: uid
});
}
}
next(action);
};
// Our extension's custom ui state reducer. Here we can listen for our 'WOW_MODE_TOGGLE' action
// and modify the state accordingly.
exports.reduceTermGroups = (state, action) => {
switch (action.type) {
case 'ENVIRONMENT_CHANGE':
const { env, uid } = action;
var termGroup = null;
for (var currentKey in state.termGroups) {
const t = state.termGroups[currentKey];
if (t.sessionUid === uid) {
termGroup = t;
}
}
if (termGroup != null) {
const isProd = env === 'PROD';
const s = state.setIn(['termGroups', termGroup.uid, 'prod'], isProd);
return s;
}
}
return state;
};
exports.mapTermsState = (state, map) => {
for (let termGroup of map.termGroups) {
termGroup['prod'] = state.termGroups.termGroups[termGroup.uid].prod
// console.log("mapTermsState", termGroup, state.termGroups.termGroups[termGroup.uid].prod)
}
return map;
};
const isProd = title => {
return title.search(/aws\.prod/) > 0;
}
exports.getTermGroupProps = (uid, parentProps, props) => {
var t = null;
for (let termGroup of parentProps.termGroups) {
if (termGroup.uid === props.termGroup.uid) {
t = termGroup;
}
}
// console.log("getTermGroupProps", t, props.termGroup)
return Object.assign(props, {
prod: t ? t.prod : false
});
}
exports.getTermProps = (uid, parentProps, props) => {
var css = "";
// console.log('getTermProps', parentProps, props);
if (parentProps.prod) {
css = `.term_term {
background: '#733737';
}`
console.log("CSS: ", css);
}
var p = Object.assign(props, {
prod: parentProps.prod,
customCSS: `
${props.customCSS || ''}
${css || ''}
`
});
// console.log("PROPS: ", p);
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment