-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7139d41
commit 6a18b01
Showing
14 changed files
with
236 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
import { FC } from 'react'; | ||
import { ListGroup, ListGroupItem, Button } from 'reactstrap'; | ||
import { ListGroup, ListGroupItem, Button, CustomInput } from 'reactstrap'; | ||
import { jsx } from '@emotion/core'; | ||
import { removePilet } from './commands'; | ||
import { removePilet, togglePilet } from './commands'; | ||
import { useStore } from './store'; | ||
|
||
export interface AvailablePiletsProps {} | ||
|
||
export const AvailablePilets: FC<AvailablePiletsProps> = () => { | ||
const pilets = useStore(m => m.state.pilets); | ||
const pilets = useStore(m => m.state.pilets) ?? []; | ||
|
||
return ( | ||
<ListGroup> | ||
{pilets && | ||
pilets.map(pilet => ( | ||
<ListGroupItem key={pilet.name}> | ||
<Button onClick={() => removePilet(pilet.name)} close /> | ||
{pilet.name} | ||
</ListGroupItem> | ||
))} | ||
{pilets.map(pilet => ( | ||
<ListGroupItem key={pilet.name}> | ||
<Button onClick={() => removePilet(pilet.name)} close /> | ||
<CustomInput | ||
type="switch" | ||
id={`toggle-${pilet.name}`} | ||
label={pilet.name} | ||
checked={!pilet.disabled} | ||
onChange={() => togglePilet(pilet.name)} | ||
/> | ||
</ListGroupItem> | ||
))} | ||
</ListGroup> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { FC, Fragment, useState } from 'react'; | ||
import { | ||
ListGroup, | ||
ListGroupItem, | ||
ListGroupItemHeading, | ||
ListGroupItemText, | ||
Breadcrumb, | ||
BreadcrumbItem, | ||
} from 'reactstrap'; | ||
import { jsx } from '@emotion/core'; | ||
import { useStore } from './store'; | ||
|
||
function display(value: any) { | ||
switch (typeof value) { | ||
case 'boolean': | ||
case 'number': | ||
case 'string': | ||
case 'bigint': | ||
case 'symbol': | ||
return ( | ||
<span> | ||
<b>({typeof value})</b> <code>{value.toString()}</code> | ||
</span> | ||
); | ||
case 'object': | ||
if (Array.isArray(value)) { | ||
return ( | ||
<span> | ||
<b>(Array)</b> <code>[{value.length} entries]</code> | ||
</span> | ||
); | ||
} else if (!value) { | ||
return ( | ||
<span> | ||
<code>null</code> | ||
</span> | ||
); | ||
} else { | ||
return ( | ||
<span> | ||
<b>(Object)</b> <code>[{Object.keys(value).length} keys]</code> | ||
</span> | ||
); | ||
} | ||
case 'undefined': | ||
return ( | ||
<span> | ||
<code>undefined</code> | ||
</span> | ||
); | ||
default: | ||
return ( | ||
<span> | ||
<b>(unknown)</b> <code>{typeof value}</code> | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
function removeIfEmpty(value: any) { | ||
/** | ||
* We have an object (non-null) that has no keys -> potentially should be removed. | ||
*/ | ||
if (typeof value === 'object' && value && Object.keys(value).length === 0) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export interface StateContainerProps {} | ||
|
||
export const StateContainer: FC<StateContainerProps> = () => { | ||
const container = useStore(m => m.state.container); | ||
const [path, setPath] = useState([]); | ||
const current = path.reduce((prev, curr) => prev[curr] ?? {}, container); | ||
|
||
return ( | ||
<Fragment> | ||
<Breadcrumb> | ||
<BreadcrumbItem> | ||
<a | ||
href="#" | ||
onClick={e => { | ||
setPath(path.slice(0, 0)); | ||
e.preventDefault(); | ||
}}> | ||
# | ||
</a> | ||
</BreadcrumbItem> | ||
{path.map((item, i) => ( | ||
<BreadcrumbItem key={`${i}_${item}`}> | ||
<a | ||
href="#" | ||
onClick={e => { | ||
setPath(path.slice(0, i + 1)); | ||
e.preventDefault(); | ||
}}> | ||
{item} | ||
</a> | ||
</BreadcrumbItem> | ||
))} | ||
</Breadcrumb> | ||
<ListGroup> | ||
{Object.keys(current) | ||
.filter(c => removeIfEmpty(current[c])) | ||
.map(c => ( | ||
<ListGroupItem | ||
key={c} | ||
tag="a" | ||
href="#" | ||
action | ||
onClick={e => { | ||
setPath([...path, c]); | ||
e.preventDefault(); | ||
}}> | ||
<ListGroupItemHeading>{c}</ListGroupItemHeading> | ||
<ListGroupItemText>{display(current[c])}</ListGroupItemText> | ||
</ListGroupItem> | ||
))} | ||
</ListGroup> | ||
</Fragment> | ||
); | ||
}; |
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
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
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
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
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
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
Oops, something went wrong.