<commit_before>import * as React from 'react';
import JSONForm, { Schema } from 'jsoninput';
import { Toolbar } from '../../Components/Toolbar';
import { noOverflow, expandHeight, defaultMargin, MediumPadding, defaultMarginBottom } from '../../css/classes';
import './FormView';
import { wwarn } from '../../Helper/wegaslog';
import { ConfirmButton } from '../../Components/Inputs/Buttons/ConfirmButton';
import { deepDifferent } from '../../Components/Hooks/storeHookFactory';
import { isActionAllowed } from '../../Components/PageComponents/tools/options';
import { IconButton } from '../../Components/Inputs/Buttons/IconButton';
import { DropMenu } from '../../Components/DropMenu';
import { css } from 'emotion';
import { ActionsProps } from '../../data/Reducer/globalState';
import { IconComp } from './Views/FontAwesome';
import { languagesCTX } from '../../Components/Contexts/LanguagesProvider';
import { internalTranslate } from '../../i18n/internalTranslator';
import { commonTranslations } from '../../i18n/common/common';

const closeButtonStyle = css({
color: "black",
});

const toolboxButtonStyle = css({
margin: '0 5px',
height: '35px',
padding: '0 6px'
});

interface EditorProps<T> extends DisabledReadonly {
  entity?: T;
  update?: (variable: T) => void;
  actions: ActionsProps<T>[];
  path?: (string | number)[];
  config?: Schema;
  onChange?: (newEntity: T) => void;
  label?: React.ReactNode;
}

export type IForm = typeof Form;

export function Form<T>({
  actions,
  config,
  entity,
  onChange,
  path,
  update,
  disabled,
  readOnly,
  label,
}: EditorProps<T>) {
  const oldReceivedEntity = React.useRef(entity);
  const form = React.useRef<JSONForm>(null);
  const [val, setVal] = React.useState(entity);
  const toolbox : ActionsProps<T>[] = [];
  const { lang } = React.useContext(languagesCTX);
  const i18nValues = internalTranslate(commonTranslations, lang);

  if (
    deepDifferent(entity, oldReceivedEntity.current) &&
    deepDifferent(entity, val)
  ) {
    oldReceivedEntity.current = entity;
    setVal(entity);
  }

  return (
    <Toolbar className={MediumPadding}>
      <Toolbar.Header>
        {isActionAllowed({
          disabled,
          readOnly,
        }) && (
          <>
            {update && (
              <IconButton
                icon="save"
                chipStyle
                tooltip={i18nValues.save}
                disabled={!deepDifferent(val, entity)}
                onClick={() => {
                  if (form.current != null) {
                    const validation = form.current.validate();
                    if (validation.length) {
                      wwarn(val, JSON.stringify(validation, null, 2));
                    } else if (val != null) {
                      update(val);
                    }
                  }<commit_msg>toolbox fixed position fix #1709<commit_after>import * as React from 'react';
import JSONForm, { Schema } from 'jsoninput';
import { Toolbar } from '../../Components/Toolbar';
import { noOverflow, expandHeight, defaultMargin, defaultMarginBottom, defaultPaddingBottom, defaultPaddingLeft, defaultPaddingRight, toolboxHeaderStyle } from '../../css/classes';
import './FormView';
import { wwarn } from '../../Helper/wegaslog';
import { ConfirmButton } from '../../Components/Inputs/Buttons/ConfirmButton';
import { deepDifferent } from '../../Components/Hooks/storeHookFactory';
import { isActionAllowed } from '../../Components/PageComponents/tools/options';
import { IconButton } from '../../Components/Inputs/Buttons/IconButton';
import { DropMenu } from '../../Components/DropMenu';
import { css, cx } from 'emotion';
import { ActionsProps } from '../../data/Reducer/globalState';
import { IconComp } from './Views/FontAwesome';
import { languagesCTX } from '../../Components/Contexts/LanguagesProvider';
import { internalTranslate } from '../../i18n/internalTranslator';
import { commonTranslations } from '../../i18n/common/common';

const closeButtonStyle = css({
color: "black",
});

const toolboxContainerStyle= css({
  position: 'sticky',
  top: 0,
  zIndex: 10,
  padding: '1em 0',
  backgroundColor: 'white',
});
const toolboxButtonStyle = css({
margin: '0 5px',
height: '35px',
padding: '0 6px'
});

interface EditorProps<T> extends DisabledReadonly {
  entity?: T;
  update?: (variable: T) => void;
  actions: ActionsProps<T>[];
  path?: (string | number)[];
  config?: Schema;
  onChange?: (newEntity: T) => void;
  label?: React.ReactNode;
}

export type IForm = typeof Form;

export function Form<T>({
  actions,
  config,
  entity,
  onChange,
  path,
  update,
  disabled,
  readOnly,
  label,
}: EditorProps<T>) {
  const oldReceivedEntity = React.useRef(entity);
  const form = React.useRef<JSONForm>(null);
  const [val, setVal] = React.useState(entity);
  const toolbox : ActionsProps<T>[] = [];
  const { lang } = React.useContext(languagesCTX);
  const i18nValues = internalTranslate(commonTranslations, lang);

  if (
    deepDifferent(entity, oldReceivedEntity.current) &&
    deepDifferent(entity, val)
  ) {
    oldReceivedEntity.current = entity;
    setVal(entity);
  }

  return (
    <Toolbar className={cx(defaultPaddingBottom, defaultPaddingLeft, defaultPaddingRight)}>
      <Toolbar.Header className={cx(toolboxContainerStyle, toolboxHeaderStyle)}>
        {isActionAllowed({
          disabled,
          readOnly,
        }) && (
          <>
            {update && (
              <IconButton
                icon="save"
                chipStyle
                tooltip={i18nValues.save}
                disabled={!deepDifferent(val, entity)}
                onClick={() => {
                  if (form.current != null) {
                    const validation = form.current.validate();
                    if (validation.length) {
                      wwarn(val, JSON.stringify(validation, null, 2));
                    } else if (val != null) {
                      update(val);
                    }
                  }
{'fraction_non_alphanumeric': 0.1476969292389853, 'fraction_numerical': 0.0065086782376502, 'mean_word_length': 2.7739294710327456, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5449157', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1695, 'n_words': 404}