Formatting.

This commit is contained in:
richburdon 2020-10-30 19:38:32 -04:00
parent 9f10054b64
commit fa983ed53c
4 changed files with 74 additions and 58 deletions

View File

@ -14,8 +14,8 @@ import Panel from '../../../components/Panel';
import Toolbar from '../../../components/Toolbar'; import Toolbar from '../../../components/Toolbar';
import RegistryRecords, { RecordType } from './RegistryRecords'; import RegistryRecords, { RecordType } from './RegistryRecords';
import RegistryLookup, { LookupType } from './RegistryLookup';
import RegistryStatus from './RegistryStatus'; import RegistryStatus from './RegistryStatus';
import RegistryLookup from './RegistryLookup';
const TAB_RECORDS = 'records'; const TAB_RECORDS = 'records';
const TAB_STATUS = 'status'; const TAB_STATUS = 'status';
@ -44,6 +44,7 @@ const Registry = () => {
const classes = useStyles(); const classes = useStyles();
const [tab, setTab] = useState(TAB_RECORDS); const [tab, setTab] = useState(TAB_RECORDS);
const [type, setType] = useState(); const [type, setType] = useState();
const [scope, setScope] = useState(LookupType.default);
return ( return (
<Panel <Panel
@ -57,7 +58,10 @@ const Registry = () => {
</Tabs> </Tabs>
{tab === TAB_RECORDS && ( {tab === TAB_RECORDS && (
<RecordType type={type} onChanged={setType} /> <RecordType type={type} onChange={setType} />
)}
{tab === TAB_LOOKUP && (
<LookupType scope={scope} onChange={setScope} />
)} )}
</Toolbar> </Toolbar>
} }
@ -71,7 +75,7 @@ const Registry = () => {
{tab === TAB_LOOKUP && ( {tab === TAB_LOOKUP && (
<div className={classes.panel}> <div className={classes.panel}>
<RegistryLookup /> <RegistryLookup scope={scope} />
</div> </div>
)} )}

View File

@ -4,11 +4,7 @@
import React, { useContext, useState } from 'react'; import React, { useContext, useState } from 'react';
import Autocomplete from '@material-ui/lab/Autocomplete'; import Autocomplete from '@material-ui/lab/Autocomplete';
import Button from '@material-ui/core/Button';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';
import TextField from '@material-ui/core/TextField'; import TextField from '@material-ui/core/TextField';
import Toolbar from '@material-ui/core/Toolbar';
import { makeStyles } from '@material-ui/core'; import { makeStyles } from '@material-ui/core';
import { useQuery } from '@apollo/react-hooks'; import { useQuery } from '@apollo/react-hooks';
@ -18,6 +14,8 @@ import Json from '../../../components/Json';
import { ConsoleContext, useQueryStatusReducer, useRegistry } from '../../../hooks'; import { ConsoleContext, useQueryStatusReducer, useRegistry } from '../../../hooks';
import WNS_RECORDS from '../../../gql/wns_records.graphql'; import WNS_RECORDS from '../../../gql/wns_records.graphql';
import ButtonGroup from '@material-ui/core/ButtonGroup';
import Button from '@material-ui/core/Button';
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({
root: { root: {
@ -25,22 +23,56 @@ const useStyles = makeStyles(theme => ({
flexDirection: 'column', flexDirection: 'column',
flex: 1 flex: 1
}, },
select: { search: {
width: 160, display: 'flex',
marginRight: theme.spacing(2) padding: '2px 8px'
}, },
button: { button: {
marginLeft: theme.spacing(2) marginLeft: theme.spacing(2)
},
selected: {
color: theme.palette.text.primary
} }
})); }));
const RegistryLookup = () => { const types = [
{ key: 'authority', label: 'Authority' },
{ key: 'wrn', label: 'WRN' }
];
export const LookupType = ({ scope = types[0].key, onChange }) => {
const classes = useStyles();
return (
<ButtonGroup
disableRipple
disableFocusRipple
variant='outlined'
color='primary'
size='small'
aria-label='text primary button group'
>
{types.map(t => (
<Button
key={t.key}
className={t.key === scope && classes.selected}
onClick={() => onChange(t.key)}
>
{t.label}
</Button>
))}
</ButtonGroup>
);
};
LookupType.default = types[0].key;
const RegistryLookup = ({ scope }) => {
const classes = useStyles(); const classes = useStyles();
const { config } = useContext(ConsoleContext); const { config } = useContext(ConsoleContext);
const { registry } = useRegistry(config); const { registry } = useRegistry(config);
const [result, setResult] = useState({}); const [result, setResult] = useState({});
const [inputValue, setInputValue] = useState(''); const [inputValue, setInputValue] = useState('');
const [lookupType, setLookupType] = useState('wrn');
const data = useQueryStatusReducer(useQuery(WNS_RECORDS, { const data = useQueryStatusReducer(useQuery(WNS_RECORDS, {
pollInterval: config.api.intervalQuery pollInterval: config.api.intervalQuery
@ -54,7 +86,7 @@ const RegistryLookup = () => {
const getNames = () => { const getNames = () => {
let ret; let ret;
switch (lookupType) { switch (scope) {
case 'wrn': { case 'wrn': {
ret = []; ret = [];
records.forEach(item => ret.push(...item.names)); records.forEach(item => ret.push(...item.names));
@ -74,42 +106,27 @@ const RegistryLookup = () => {
ret = Array.from(names.values()); ret = Array.from(names.values());
break; break;
} }
default:
throw new Error(`Unrecognized lookup type: ${lookupType}`);
} }
ret.sort(); ret.sort();
return ret; return ret;
}; };
const handleSelect = (evt) => { const handleSubmit = async (newInputValue = inputValue) => {
evt.preventDefault(); if (!newInputValue) {
// TODO(burdon): Change to controlled component.
setLookupType(evt.target.value);
};
const handleSubmit = async (evt) => {
evt.preventDefault();
if (!inputValue) {
setResult(''); setResult('');
return; return;
} }
let result; let result;
switch (lookupType) { switch (scope) {
case 'wrn': case 'wrn':
result = await registry.lookupNames([inputValue], true); result = await registry.lookupNames([newInputValue], true);
break; break;
case 'authority': case 'authority':
result = await registry.lookupAuthorities([inputValue]); result = await registry.lookupAuthorities([newInputValue]);
break; break;
default:
throw new Error(`Unrecognized lookup type: ${lookupType}`);
} }
setResult(result); setResult(result);
@ -117,30 +134,25 @@ const RegistryLookup = () => {
return ( return (
<div className={classes.root}> <div className={classes.root}>
<Toolbar> <div className={classes.search}>
<Select id='lookupType' className={classes.select} name='lookupType' defaultValue='wrn' onChange={handleSelect}>
<MenuItem value='authority'>Authority</MenuItem>
<MenuItem value='wrn'>WRN</MenuItem>
</Select>
<Autocomplete <Autocomplete
options={getNames()} options={getNames()}
autoFocus autoFocus
name='value'
id='value' id='value'
name='value'
fullWidth fullWidth
freeSolo
inputValue={inputValue} inputValue={inputValue}
onInputChange={(event, newInputValue) => {
setInputValue(newInputValue);
}}
renderInput={(params) => <TextField {...params} variant='outlined' />} renderInput={(params) => <TextField {...params} variant='outlined' />}
onInputChange={async (event, newInputValue) => {
setInputValue(newInputValue);
await handleSubmit(newInputValue);
}}
/> />
</div>
<Button className={classes.button} variant='contained' color='primary' onClick={handleSubmit}>Search</Button> <div>
</Toolbar> <Json data={result} />
</div>
<Json data={result} />
</div> </div>
); );
}; };

View File

@ -23,6 +23,12 @@ import PackageLink from '../../../components/PackageLink';
import QueryLink from '../../../components/QueryLink'; import QueryLink from '../../../components/QueryLink';
import AppLink from '../../../components/AppLink'; import AppLink from '../../../components/AppLink';
const useStyles = makeStyles(theme => ({
selected: {
color: theme.palette.text.primary
}
}));
const types = [ const types = [
{ key: null, label: 'ALL' }, { key: null, label: 'ALL' },
{ key: 'wrn:kube', label: 'Kube' }, { key: 'wrn:kube', label: 'Kube' },
@ -33,13 +39,7 @@ const types = [
{ key: 'wrn:type', label: 'Type' } { key: 'wrn:type', label: 'Type' }
]; ];
const useStyles = makeStyles(theme => ({ export const RecordType = ({ type = types[0].key, onChange }) => {
selected: {
color: theme.palette.text.primary
}
}));
export const RecordType = ({ type = types[0].key, onChanged }) => {
const classes = useStyles(); const classes = useStyles();
return ( return (
@ -55,7 +55,7 @@ export const RecordType = ({ type = types[0].key, onChanged }) => {
<Button <Button
key={t.key} key={t.key}
className={t.key === type && classes.selected} className={t.key === type && classes.selected}
onClick={() => onChanged(t.key)} onClick={() => onChange(t.key)}
> >
{t.label} {t.label}
</Button> </Button>

View File

@ -1,7 +1,7 @@
{ {
"build": { "build": {
"name": "@dxos/console-app", "name": "@dxos/console-app",
"buildDate": "2020-10-30T19:35:04.535Z", "buildDate": "2020-10-30T22:38:24.913Z",
"version": "1.1.0-beta.11" "version": "1.1.0-beta.12"
} }
} }