All files / src/form/fields CodeEditorDetail.tsx

16.66% Statements 2/12
0% Branches 0/6
0% Functions 0/3
18.18% Lines 2/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32      66x   66x                                                    
import React, { ReactElement, Suspense } from "react";
import { DetailPanelProps } from "@props/RecordProps";
 
const CodeEditor = React.lazy(() => import('./CodeEditor'));
 
const CodeEditorDetail = (props: DetailPanelProps): ReactElement => {
  const { column, readonly, record, form, zIndex, onValuesChange, fieldValue } = props;
  const { key, updatable, extInfo } = column;
  const value = fieldValue ?? record?.[key];
  const combUpdatable = ((updatable !== false && record?.id != null) && !readonly) || (record?.id == null);
  return (<Suspense fallback={<div />}>
    <CodeEditor
      value={value}
      onChange={(val) => {
        const changedValue = {[key]: val};
        const newValue = {...record, ...changedValue};
        form.setFieldsValue(changedValue);
        onValuesChange?.(changedValue, newValue);
      }}
      name={key}
      updatable={combUpdatable}
      style={{ width: "99%", margin: "auto" }}
      mode={extInfo?.codeLanguage}
      zIndex={zIndex}
      record={record}
    />
  </Suspense>
  );
};
 
export default CodeEditorDetail;