Fixes for package and app links, service type names (likely to change).

This commit is contained in:
Thomas E Lackey 2020-08-18 18:22:50 -05:00
parent ba4de7d1b7
commit 4779ffa804
6 changed files with 43 additions and 48 deletions

View File

@ -8,7 +8,7 @@ import Link from '@material-ui/core/Link';
import { getServiceUrl } from '../util/config';
const getAppUrl = (config, { name, version }) => {
const getAppUrl = (config, { wrn }) => {
const base = getServiceUrl(config, 'app.server');
const pathComponents = [base];
@ -21,11 +21,7 @@ const getAppUrl = (config, { name, version }) => {
pathComponents.push(prefix.substring(1));
}
if (version) {
pathComponents.push(`${name}@${version}`);
} else {
pathComponents.push(name);
}
pathComponents.push(encodeURIComponent(wrn));
return `${pathComponents.join('/')}/`;
};
@ -34,11 +30,10 @@ const getAppUrl = (config, { name, version }) => {
* @param {Object} config
* @param {string} name
* @param {string} [text]
* @param {string} [version]
*/
const AppLink = ({ config, name, version, text }) => {
const fullURL = getAppUrl(config, { name, version });
return <Link href={fullURL} target={name}>{text || name}</Link>;
const AppLink = ({ config, wrn, text }) => {
const fullURL = getAppUrl(config, { wrn });
return <Link href={fullURL} target={wrn}>{text || wrn}</Link>;
};
export default AppLink;

View File

@ -15,19 +15,18 @@ import { getServiceUrl } from '../util/config';
* @param {string} [text]
*/
const PackageLink = ({ config, type, pkg, text }) => {
// TODO(burdon): Pass in expected arg types.
if (typeof pkg === 'string') {
const ipfsUrl = getServiceUrl(config, 'ipfs.gateway', { path: `${pkg}` });
return <Link href={ipfsUrl} key={pkg} target={pkg}>{text || pkg}</Link>;
}
// eslint-disable-next-line default-case
switch (type) {
case 'bot': {
case 'wrn://dxos/type/application/web': {
const cid = pkg['/'];
const ipfsUrl = getServiceUrl(config, 'ipfs.gateway', { path: `${cid}` });
return <Link href={ipfsUrl} key={cid} target={cid}>{text || cid}</Link>;
}
case 'wrn://dxos/type/application/bot': {
const packageLinks = [];
Object.keys(pkg).forEach((platform, i) => {
Object.keys(pkg[platform]).forEach(arch => {
const cid = pkg[platform][arch];
const cid = pkg[platform][arch]['/'];
const ipfsUrl = getServiceUrl(config, 'ipfs.gateway', { path: `${cid}` });
packageLinks.push(
<div>

View File

@ -25,7 +25,7 @@ const AppRecords = () => {
const [sorter, sortBy] = useSorter('createTime', false);
const appResponse = useQueryStatusReducer(useQuery(WNS_RECORDS, {
pollInterval: config.api.intervalQuery,
variables: { attributes: { type: 'app' } }
variables: { attributes: { type: 'wrn://dxos/type/application/web' } }
}));
// TODO(telackey): Does this also need an interval?
@ -42,7 +42,7 @@ const AppRecords = () => {
<Table>
<TableHead>
<TableRow>
<TableCell onClick={sortBy('names[0]')}>Identifier</TableCell>
<TableCell onClick={sortBy('names[0]')}>Registered Names</TableCell>
<TableCell onClick={sortBy('attributes.version')} size='small'>Version</TableCell>
<TableCell onClick={sortBy('attributes.name')}>Name</TableCell>
<TableCell onClick={sortBy('createTime')} size='small'>Created</TableCell>
@ -54,8 +54,8 @@ const AppRecords = () => {
return (
<TableRow key={id} size='small'>
<TableCell monospace>
{names.map(name => <>
<AppLink config={config} name={name} />
{names.map(wrn => <>
<AppLink config={config} wrn={wrn} />
<br />
</>
)}

View File

@ -20,8 +20,7 @@ import Table from '../../../components/Table';
import TableCell from '../../../components/TableCell';
import { BooleanIcon } from '../../../components/BooleanIcon';
const RECORD_TYPE = 'wrn:service';
const SERVICE_TYPE = 'ipfs';
const RECORD_TYPE = 'wrn://dxos/type/service/ipfs';
const useStyles = makeStyles((theme) => ({
tableContainer: {
@ -70,7 +69,7 @@ const IPFSStatus = () => {
const ipfsResponse = useQueryStatusReducer(useQuery(IPFS_STATUS));
const wnsResponse = useQueryStatusReducer(useQuery(WNS_RECORDS, {
variables: { attributes: { type: RECORD_TYPE, service: SERVICE_TYPE } }
variables: { attributes: { type: RECORD_TYPE } }
}));
if (!wnsResponse || !ipfsResponse) {
@ -78,10 +77,10 @@ const IPFSStatus = () => {
}
const ipfsData = JSON.parse(ipfsResponse.ipfs_status.json);
const registeredServers = JSON.parse(wnsResponse.wns_records.json);
const registeredServers = JSON.parse(wnsResponse.wns_records.json).filter(record => get(record, 'attributes.active') !== false);
const displayServers = registeredServers.map((service) => {
const addresses = get(service, 'attributes.ipfs.addresses');
const addresses = get(service, 'attributes.addresses');
let connected = false;
for (const address of addresses) {
const parts = address.split('/');
@ -93,10 +92,9 @@ const IPFSStatus = () => {
}
return {
name: get(service, 'name'),
...service.attributes,
names: get(service, 'names'),
version: get(service, 'version'),
description: get(service, 'attributes.description'),
ipfs: get(service, 'attributes.ipfs'),
connected
};
});
@ -115,19 +113,19 @@ const IPFSStatus = () => {
<Table stickyHeader size='small' className={classes.table}>
<TableHead>
<TableRow>
<TableCell>Identifier</TableCell>
<TableCell>Registered Names</TableCell>
<TableCell size='medium'>Description</TableCell>
<TableCell>Address</TableCell>
<TableCell size='small'>Connected</TableCell>
</TableRow>
</TableHead>
<TableBody>
{displayServers.map(({ name, description, ipfs, connected }) => (
<TableRow key={name}>
<TableCell>{name}</TableCell>
{displayServers.map(({ names, description, addresses, connected }) => (
<TableRow key={names}>
<TableCell>{names.map(name => <>{name}<br /></>)}</TableCell>
<TableCell>{description}</TableCell>
<TableCell>
{ipfs.addresses}
{addresses}
</TableCell>
<TableCell>
<BooleanIcon yes={connected} />

View File

@ -25,13 +25,16 @@ import AppLink from '../../../components/AppLink';
const types = [
{ key: null, label: 'ALL' },
{ key: 'kube', label: 'Kube' },
{ key: 'resource', label: 'Resource' },
{ key: 'service', label: 'Service' },
{ key: 'app', label: 'App' },
{ key: 'bot', label: 'Bot' },
{ key: 'bot-factory', label: 'Bot Factory' },
{ key: 'type', label: 'Type' }
{ key: 'wrn://dxos/type/application/web', label: 'App' },
{ key: 'wrn://dxos/type/application/bot', label: 'Bot' },
{ key: 'wrn://dxos/type/device/kube', label: 'Kube' },
{ key: 'wrn://dxos/type/service/bot-factory', label: 'Bot Factory' },
{ key: 'wrn://dxos/type/service/ipfs', label: 'IPFS' },
{ key: 'wrn://dxos/type/service/ipfs-gateway', label: 'IPFS Gateway' },
{ key: 'wrn://dxos/type/service/signal', label: 'Signal' },
{ key: 'wrn://dxos/type/service/stun', label: 'STUN' },
{ key: 'wrn://dxos/type/service/turn', label: 'TURN' },
{ key: 'type', label: 'Type' },
];
const useStyles = makeStyles(theme => ({
@ -84,7 +87,7 @@ const WNSRecords = ({ type }) => {
<TableHead>
<TableRow>
<TableCell onClick={sortBy('attributes.type')} size='medium'>Type</TableCell>
<TableCell onClick={sortBy('names[0]')}>Identifier</TableCell>
<TableCell onClick={sortBy('names[0]')}>Registered Names</TableCell>
<TableCell onClick={sortBy('attributes.version')} size='small'>Version</TableCell>
<TableCell onClick={sortBy('attributes.name')}>Name</TableCell>
<TableCell onClick={sortBy('createTime')} size='small'>Created</TableCell>
@ -104,11 +107,11 @@ const WNSRecords = ({ type }) => {
pkgLink = (<PackageLink config={config} type={type} pkg={pkg} />);
}
if (type === 'app') {
if (type === 'wrn://dxos/type/application/web') {
appLinks = (
<>
{names.map(name => <>
<AppLink config={config} name={name} />
{names.map(wrn => <>
<AppLink config={config} wrn={wrn} />
<br />
</>
)}

View File

@ -1,7 +1,7 @@
{
"build": {
"name": "@dxos/console-app",
"buildDate": "2020-07-21T20:40:54.153Z",
"version": "1.0.0-beta.22"
"buildDate": "2020-08-18T23:14:12.669Z",
"version": "1.0.0-beta.24"
}
}