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!
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

51 linhas
1.5KB

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