Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.tsx 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import CopyToClipboard from '@/components/copy-to-clipboard';
  2. import { Sheet, SheetContent, SheetHeader } from '@/components/ui/sheet';
  3. import { useDebugSingle } from '@/hooks/flow-hooks';
  4. import { useFetchInputForm } from '@/hooks/use-agent-request';
  5. import { IModalProps } from '@/interfaces/common';
  6. import { isEmpty } from 'lodash';
  7. import { X } from 'lucide-react';
  8. import { useCallback, useMemo } from 'react';
  9. import { useTranslation } from 'react-i18next';
  10. import JsonView from 'react18-json-view';
  11. import 'react18-json-view/src/style.css';
  12. import DebugContent from '../../debug-content';
  13. import { buildBeginInputListFromObject } from '../../form/begin-form/utils';
  14. interface IProps {
  15. componentId?: string;
  16. }
  17. const SingleDebugSheet = ({
  18. componentId,
  19. visible,
  20. hideModal,
  21. }: IModalProps<any> & IProps) => {
  22. const { t } = useTranslation();
  23. const inputForm = useFetchInputForm(componentId);
  24. const { debugSingle, data, loading } = useDebugSingle();
  25. const list = useMemo(() => {
  26. return buildBeginInputListFromObject(inputForm);
  27. }, [inputForm]);
  28. const onOk = useCallback(
  29. (nextValues: any[]) => {
  30. if (componentId) {
  31. debugSingle({ component_id: componentId, params: nextValues });
  32. }
  33. },
  34. [componentId, debugSingle],
  35. );
  36. const content = JSON.stringify(data, null, 2);
  37. return (
  38. <Sheet open={visible} modal={false}>
  39. <SheetContent className="top-20 p-0" closeIcon={false}>
  40. <SheetHeader className="py-2 px-5">
  41. <div className="flex justify-between ">
  42. {t('flow.testRun')}
  43. <X onClick={hideModal} className="cursor-pointer" />
  44. </div>
  45. </SheetHeader>
  46. <section className="overflow-y-auto pt-4 px-5">
  47. <DebugContent
  48. parameters={list}
  49. ok={onOk}
  50. isNext={false}
  51. loading={loading}
  52. submitButtonDisabled={list.length === 0}
  53. ></DebugContent>
  54. {!isEmpty(data) ? (
  55. <div className="mt-4 rounded-md bg-slate-200 border border-neutral-200">
  56. <div className="flex justify-between p-2">
  57. <span>JSON</span>
  58. <CopyToClipboard text={content}></CopyToClipboard>
  59. </div>
  60. <JsonView
  61. src={data}
  62. displaySize
  63. collapseStringsAfterLength={100000000000}
  64. className="w-full h-[800px] break-words overflow-auto p-2 bg-slate-100"
  65. />
  66. </div>
  67. ) : null}
  68. </section>
  69. </SheetContent>
  70. </Sheet>
  71. );
  72. };
  73. export default SingleDebugSheet;