IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3KB

  1. import { h, Component } from 'preact';
  2. import WBIdTools from 'wb-id-tools';
  3. import urlForObject from 'url-for-object';
  4. import makeArvadosRequest from 'make-arvados-request';
  5. import arvadosObjectName from 'arvados-object-name';
  6. import WBLazyInlineName from 'wb-lazy-inline-name';
  7. function detectIds(value, app) {
  8. const matches = WBIdTools.detectIdentifiers(value);
  9. matches.sort((a, b) => (a.index - b.index));
  10. const res = [];
  11. let ofs = 0;
  12. for (let i = 0; i < matches.length; i++) {
  13. const { index } = matches[i];
  14. const id = matches[i][0];
  15. const typeName = WBIdTools.typeName(id);
  16. const url = (typeName === 'group' ? '/browse/' + id :
  17. typeName === 'collection' ? '/collection-browse/' + id :
  18. urlForObject({ uuid: id }));
  19. res.push(value.substring(ofs, index));
  20. res.push(h(WBLazyInlineName, { identifier: id, app }, id));
  21. ofs = index + id.length;
  22. }
  23. res.push(value.substring(ofs));
  24. return res;
  25. }
  26. class WBJsonViewer extends Component {
  27. render({ value, stringify, app, pretty }) {
  28. if (stringify)
  29. value = pretty ? JSON.stringify(value, null, 2) : JSON.stringify(value);
  30. return (
  31. <div class="wb-json-viewer">{ detectIds(value, app) }</div>
  32. );
  33. }
  34. }
  35. WBJsonViewer.defaultProps = {
  36. stringify: true,
  37. pretty: true
  38. };
  39. export default WBJsonViewer;