|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import { h, Component } from 'preact';
- import makeArvadosRequest from 'make-arvados-request';
- import urlForObject from 'url-for-object';
- import arvadosObjectName from 'arvados-object-name';
- import arvadosTypeName from 'arvados-type-name';
-
- class WBNameAndUuid extends Component {
- componentDidMount() {
- let { uuid, app } = this.props;
- let { arvHost, arvToken } = app.state;
-
- if (!uuid)
- return;
-
- let prom = new Promise(accept => accept());
-
- if (/[0-9a-f]{32}\+[0-9]+/g.exec(uuid)) {
- let filters = [
- ['portable_data_hash', '=', uuid]
- ];
- prom = prom.then(() => makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/collections?filters=' +
- encodeURIComponent(JSON.stringify(filters))));
- prom = prom.then(xhr => {
- if (xhr.response.items.length === 0) {
- this.setState({
- 'item': {
- 'uuid': uuid,
- 'name': 'Collection with portable data hash ' + uuid
- }
- });
- return;
- }
- let item = xhr.response.items[0];
- if (xhr.response.items.length > 1)
- item.name += ' +' + (xhr.response.items.length - 1) + ' others';
- this.setState({ item });
- });
-
- } else if (/[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/.exec(uuid)) {
- let typeName = arvadosTypeName(uuid);
- let prom = makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/' + typeName + 's/' + uuid );
- prom = prom.then(xhr => this.setState({
- 'item': xhr.response
- }));
- prom = prom.catch(xhr => this.setState({
- 'error': 'Unable to retrieve: ' + xhr.status + ' (' + xhr.statusText + ')'
- }));
-
- } else {
- this.setState({
- 'item': {
- 'uuid': uuid
- }
- });
- }
- }
-
- render({ uuid }, { error, item }) {
- if (!uuid)
- return (
- <div><i>{ String(uuid) }</i></div>
- );
-
- return (
- <div>
- <div>
- { error ? error : (item ? (
- <a href={ urlForObject(item) }>{ arvadosObjectName(item) }</a>
- ) : 'Loading...') }
- </div>
- <div>
- { uuid }
- </div>
- </div>
- );
- }
- }
-
- export default WBNameAndUuid;
|