This Gist was automatically created by Carbide, a free online programming environment.
Last active
March 1, 2018 04:17
-
-
Save carbide-public/2b1fc6cf4e0f3098cc5c58fbd1f214bb to your computer and use it in GitHub Desktop.
xx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ROUTES = { | |
ROOT: '/', | |
DASHBOARD: '/dashboard', | |
WIZARD: '/wizard', | |
WIZARD_STEPS: { | |
GENERIC: '/wizard/:step', | |
CREATE: '/wizard/create', | |
SETUP: '/wizard/setup', | |
PROTECT: '/wizard/protect', | |
CONNECT: '/wizard/connect', | |
}, | |
STATUS: '/status', | |
INCIDENTS: '/incidents', | |
PREPARING: '/preparing', | |
UPDATES: '/updates', | |
DEFAULT: '/', | |
DEV: '/dev', | |
ERROR: '/error', | |
MAINTENANCE: '/maintenance', | |
}; | |
const servingRoutes = [ROUTES.DASHBOARD, ROUTES.STATUS, ROUTES.UPDATES, ROUTES.INCIDENTS]; | |
const INVALID_ROUTES = { | |
NO_SITE: servingRoutes, | |
SERVING: ROUTES.WIZARD_STEPS, | |
PROVISIONING: servingRoutes, | |
}; | |
const VALID_ROUTES = { | |
PREPARING: { | |
DEFAULT: ROUTES.PREPARING, | |
}, | |
SERVING: { | |
DEFAULT: ROUTES.DASHBOARD, | |
STATUS: ROUTES.STATUS, | |
UPDATES: ROUTES.UPDATES, | |
INCIDENTS: ROUTES.INCIDENTS, | |
}, | |
UPDATING_FAILURE: { | |
}, | |
}; | |
const SITE_STATUS = { | |
NO_SITE: 'NO_SITE', | |
PROVISIONING: 'PROVISIONING', | |
SERVING: 'SERVING', | |
}; | |
const contains = function (obj, path) { | |
return Object.keys(obj).indexOf(path) > -1; | |
}; | |
/* | status | if path is root | has access to | | |
* | :--------------- | :---------- | :------------------ | | |
* | EMPTY (No Site) | /wizard/create | /wizard/create | | |
* | SERVING | /dashboard | /dashboard, /status, /update, /incidents, /settings | | |
* | PREPARING | /preparing | /preparing, /settings | | |
* | MAINTENANCE | /maintenance | /maintenance */ | |
const goTo = (status, path) => { | |
let newPath = path; | |
switch (status) { | |
case SITE_STATUS.NO_SITE: | |
if (path === ROUTES.ROOT || path === ROUTES.WIZARD_STEPS.PROTECT || servingRoutes.includes(path)) { | |
newPath = ROUTES.WIZARD_STEPS.CREATE; | |
} | |
break; | |
case SITE_STATUS.PROVISIONING: | |
if (contains(INVALID_ROUTES.PROVISIONING, path)) { | |
} | |
break; | |
case SITE_STATUS.SERVING: | |
if (path === ROUTES.ROOT || path.startsWith(ROUTES.WIZARD)) { | |
newPath = ROUTES.DASHBOARD | |
} | |
break; | |
default: | |
break; | |
} | |
return newPath; | |
}; | |
let a = [ | |
{ | |
"state":SITE_STATUS.NO_SITE, | |
"path":'/dashboard', | |
"shouldBe":"/dashboard", | |
"result":goTo(SITE_STATUS.NO_SITE,'/dashboard') | |
}, | |
{ | |
"state":SITE_STATUS.NO_SITE, | |
"path":'/dashboard', | |
"shouldBe":"/wizard/create", | |
"result":goTo(SITE_STATUS.NO_SITE,'/status') | |
}, | |
{ | |
"state":SITE_STATUS.NO_SITE, | |
"path":'/dashboard', | |
"shouldBe":"/dashboard", | |
"result":goTo(SITE_STATUS.NO_SITE,'/dashboard') | |
}, | |
]; | |
goTo(SITE_STATUS.NO_SITE,'/dashboard') | |
goTo(SITE_STATUS.NO_SITE,'/status') | |
goTo(SITE_STATUS.NO_SITE,'/') | |
goTo(SITE_STATUS.NO_SITE,'/dashboard/setup') | |
goTo(SITE_STATUS.SERVING,'/') | |
goTo(SITE_STATUS.SERVING,'/dashboard') | |
a | |
export default a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
let okBack = (shouldBe, result) => { | |
return shouldBe === result ? 'PaleGreen' : 'Crimson' | |
} | |
class TruthTable extends React.Component { | |
static title = "TruthTable"; | |
static match(value, ast){ | |
return value | |
&& Array.isArray(value); | |
} | |
render(){ | |
const rows = this.props.value; | |
const renderedRows = rows.map((row) => <tr><td>{row.state}</td><td>{row.path}</td><td style={{backgroundColor:okBack(row.shouldBe,row.result)}}>{row.shouldBe}</td><td>{row.result}</td></tr>) | |
return <table> | |
<tr><td style={{borderBottom:'1px solid black',fontWeight:'700'}}>State</td><td style={{borderBottom:'1px solid black',fontWeight:'700'}}>Path</td><td style={{borderBottom:'1px solid black',fontWeight:'700'}}>Should Be</td><td style={{borderBottom:'1px solid black',fontWeight:'700'}}>Result</td></tr> | |
{renderedRows} | |
</table> | |
} | |
} | |
export function __unload(){ ///This cleans everything up so we can run this cell multiple times. | |
var index = doc.kernel.widgets.indexOf(TruthTable) | |
doc.kernel.splice(index, 1) | |
} | |
doc.kernel.widgets.unshift(TruthTable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment