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.

72 lines
2.2KB

  1. import { h, Component } from 'preact';
  2. import wbInputSpecInfo from 'wb-input-spec-info';
  3. import WBPathDisplay from 'wb-path-display';
  4. import { parseKeepRef } from 'wb-process-misc';
  5. class WBWorkflowInput extends Component {
  6. render({ app, inputSpec, inputsDict, browseDialogRef }) {
  7. const { isFile, isDirectory, isArray } = wbInputSpecInfo(inputSpec);
  8. if (!isFile && !isDirectory)
  9. return (
  10. <div>
  11. <input class="form-control w-100" type="text" placeholder={ inputSpec.label }
  12. value={ inputsDict[inputSpec.id] }
  13. onchange={ e => (inputsDict[inputSpec.id] = e.target.value) }></input>
  14. <div class="mt-2 text-muted">{ inputSpec.doc }</div>
  15. </div>
  16. );
  17. const button = (
  18. <button class="btn btn-outline-primary"
  19. onclick={ e => {
  20. e.preventDefault();
  21. browseDialogRef.current.show(
  22. [].concat(isFile ? 'file' : []).concat(isDirectory ? 'directory' : []),
  23. isArray,
  24. v => {
  25. inputsDict[inputSpec.id] = JSON.stringify(v);
  26. this.setState({});
  27. });
  28. } }>
  29. Browse...
  30. </button>
  31. );
  32. let value = inputsDict[inputSpec.id];
  33. if (value) {
  34. try {
  35. value = jsyaml.load(value);
  36. } catch (_) {}
  37. }
  38. return (
  39. <div>
  40. <div class="input-group">
  41. <input class="form-control w-100" type="text" placeholder={ inputSpec.label }
  42. value={ inputsDict[inputSpec.id] }
  43. onchange={ e => (inputsDict[inputSpec.id] = e.target.value) }></input>
  44. <div class="input-group-append">
  45. { button }
  46. </div>
  47. </div>
  48. <div class="mt-2 text-muted">{ inputSpec.doc }</div>
  49. { value ?
  50. isArray ? (
  51. <ul class="mb-0">
  52. { value.map(path => (
  53. <li>
  54. <WBPathDisplay app={ app } path={ parseKeepRef(path) } />
  55. </li>
  56. )) }
  57. </ul>
  58. ) : (
  59. <WBPathDisplay app={ app } path={ parseKeepRef(value) } />
  60. ) : null }
  61. </div>
  62. );
  63. }
  64. }
  65. export default WBWorkflowInput;