@irontec/ivoz-ui 1.7.13 → 1.7.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,8 @@ interface ConfirmDialogProps {
4
4
  open: boolean;
5
5
  doubleCheck?: boolean;
6
6
  doubleCheckExpectedStr?: string;
7
- handleClose: (event: unknown) => void;
8
- handleApply: (event: unknown) => void;
7
+ handleClose: () => void;
8
+ handleApply: (event: React.MouseEvent) => void;
9
9
  }
10
10
  export default function ConfirmDialog(props: ConfirmDialogProps): JSX.Element;
11
11
  export {};
@@ -1,20 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
3
- import Dialog from '@mui/material/Dialog';
4
- import DialogActions from '@mui/material/DialogActions';
5
- import DialogContent from '@mui/material/DialogContent';
6
- import DialogContentText from '@mui/material/DialogContentText';
7
- import DialogTitle from '@mui/material/DialogTitle';
8
- import Slide from '@mui/material/Slide';
9
- import { forwardRef, useCallback, useState, } from 'react';
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useState } from 'react';
10
3
  import { StyledSearchTextField } from '../../services/form/Field/TextField/TextField.styles';
11
4
  import _ from '../../services/translations/translate';
12
- import { OutlinedButton, SolidButton } from './Button/Button.styles';
13
5
  import { StyledDialogContentText } from './ConfirmDialog.styles';
14
- const Transition = forwardRef(function (props, ref) {
15
- return _jsx(Slide, Object.assign({}, props, { direction: 'up', ref: ref }));
16
- });
17
- Transition.displayName = 'ConfirmDialogTransition';
6
+ import Modal from './Modal/Modal';
18
7
  export default function ConfirmDialog(props) {
19
8
  const { text, open, doubleCheck, doubleCheckExpectedStr, handleClose, handleApply, } = props;
20
9
  const [inputVal, setInputVal] = useState('');
@@ -22,9 +11,21 @@ export default function ConfirmDialog(props) {
22
11
  const val = event.target.value;
23
12
  setInputVal(val || '');
24
13
  }, []);
25
- const handleKeyDown = (event) => {
26
- event.stopPropagation();
27
- };
28
- const sumbitEnabled = !doubleCheck || inputVal == doubleCheckExpectedStr;
29
- return (_jsxs(Dialog, Object.assign({ open: open, TransitionComponent: Transition, keepMounted: true, onClose: handleClose, "aria-labelledby": 'alert-dialog-slide-title', "aria-describedby": 'alert-dialog-slide-description', onKeyDown: handleKeyDown }, { children: [_jsx(CloseRoundedIcon, { className: 'close-icon', onClick: handleClose }), _jsx("img", { src: 'assets/img/delete-dialog.svg', className: 'modal-icon' }), _jsx(DialogTitle, Object.assign({ id: 'alert-dialog-slide-title' }, { children: _('Remove element') })), _jsxs(DialogContent, { children: [_jsx(DialogContentText, Object.assign({ id: 'alert-dialog-slide-description' }, { children: text })), doubleCheck && (_jsx(StyledDialogContentText, Object.assign({ id: 'alert-dialog-double-check-description' }, { children: _('Please type the item name, as shown in bold font above, to continue') }))), doubleCheck && (_jsx(StyledSearchTextField, { type: 'text', hasChanged: false, defaultValue: inputVal, onChange: onChangeHandler }))] }), _jsxs(DialogActions, { children: [_jsx(OutlinedButton, Object.assign({ onClick: handleClose, sx: { flexGrow: '1' }, color: 'error' }, { children: _('No, keep it') })), _jsx(SolidButton, Object.assign({ disabled: !sumbitEnabled, onClick: handleApply, sx: { flexGrow: '1' }, color: 'error' }, { children: _('Yes, delete it') }))] })] })));
14
+ const submitEnabled = !doubleCheck || inputVal == doubleCheckExpectedStr;
15
+ const customButtons = [
16
+ {
17
+ label: _('No, keep it'),
18
+ onClick: () => handleClose(),
19
+ variant: 'outlined',
20
+ autoFocus: false,
21
+ },
22
+ {
23
+ label: _('Yes, delete it'),
24
+ onClick: (event) => handleApply(event),
25
+ variant: 'solid',
26
+ autoFocus: true,
27
+ disabled: !submitEnabled,
28
+ },
29
+ ];
30
+ return (_jsx(Modal, Object.assign({ title: _('Remove element'), description: text, open: open, onClose: handleClose, buttons: customButtons, icon: 'assets/img/delete-dialog.svg', keepMounted: true }, { children: doubleCheck && (_jsxs(_Fragment, { children: [_jsx(StyledDialogContentText, Object.assign({ id: 'alert-dialog-double-check-description' }, { children: _('Please type the item name, as shown in bold font above, to continue') })), _jsx(StyledSearchTextField, { type: 'text', hasChanged: false, defaultValue: inputVal, onChange: onChangeHandler })] })) })));
30
31
  }
@@ -1,27 +1,13 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState, useEffect, forwardRef, } from 'react';
3
- import Dialog from '@mui/material/Dialog';
4
- import DialogTitle from '@mui/material/DialogTitle';
5
- import DialogContent from '@mui/material/DialogContent';
6
- import DialogActions from '@mui/material/DialogActions';
7
- import Button from '@mui/material/Button';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState, useEffect } from 'react';
3
+ import { Box } from '@mui/material';
8
4
  import LinearProgress from '@mui/material/LinearProgress';
9
- import { DialogContentText, Slide } from '@mui/material';
10
- import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
11
5
  import _ from '../../services/translations/translate';
12
- const Transition = forwardRef(function (props, ref) {
13
- return _jsx(Slide, Object.assign({}, props, { direction: 'up', ref: ref }));
14
- });
15
- Transition.displayName = 'ConfirmDialogTransition';
6
+ import Modal from './Modal/Modal';
16
7
  export const ConfirmEditionDialog = (props) => {
17
8
  const { open, handleClose, text, handleSave, formEvent } = props;
18
9
  const TOTAL_TIME = 100;
19
10
  const [progress, setProgress] = useState(TOTAL_TIME);
20
- const handleKeyDown = (event) => {
21
- if (event.key === 'Tab') {
22
- event.stopPropagation();
23
- }
24
- };
25
11
  useEffect(() => {
26
12
  let timer = null;
27
13
  if (open) {
@@ -41,11 +27,27 @@ export const ConfirmEditionDialog = (props) => {
41
27
  }
42
28
  };
43
29
  }, [open]);
44
- return (_jsxs(Dialog, Object.assign({ open: open, TransitionComponent: Transition, keepMounted: true, onClose: handleClose, onKeyDown: handleKeyDown, "aria-labelledby": 'alert-dialog-slide-title', "aria-describedby": 'alert-dialog-slide-description' }, { children: [_jsx(CloseRoundedIcon, { className: 'close-icon', onClick: handleClose }), _jsx("img", { src: 'assets/img/warning-dialog.svg', className: 'modal-icon' }), _jsx(DialogTitle, Object.assign({ id: 'alert-dialog-slide-title' }, { children: _('Save element') })), _jsxs(DialogContent, { children: [_jsx(DialogContentText, Object.assign({ id: 'alert-dialog-slide-description' }, { children: text })), _jsx(LinearProgress, { variant: 'determinate', value: progress })] }), _jsxs(DialogActions, { children: [_jsx(Button, Object.assign({ onClick: () => {
45
- handleClose();
46
- } }, { children: "Cancel" })), _jsx(Button, Object.assign({ hidden: progress !== 0, onClick: () => {
47
- if (formEvent) {
48
- handleSave(formEvent);
49
- }
50
- }, disabled: progress !== 0 }, { children: "Apply" }))] })] })));
30
+ const customButtons = [
31
+ {
32
+ label: _('Cancel'),
33
+ onClick: () => handleClose(),
34
+ variant: 'outlined',
35
+ autoFocus: false,
36
+ },
37
+ ...(progress === 0
38
+ ? [
39
+ {
40
+ label: _('Apply'),
41
+ onClick: () => {
42
+ if (formEvent) {
43
+ handleSave(formEvent);
44
+ }
45
+ },
46
+ variant: 'solid',
47
+ autoFocus: true,
48
+ },
49
+ ]
50
+ : []),
51
+ ];
52
+ return (_jsx(Modal, Object.assign({ title: _('Save element'), description: text, open: open, onClose: handleClose, buttons: customButtons, keepMounted: true }, { children: _jsx(Box, Object.assign({ sx: { width: '100%', mt: 2 } }, { children: _jsx(LinearProgress, { variant: 'determinate', value: progress }) })) })));
51
53
  };
@@ -0,0 +1,22 @@
1
+ /// <reference types="react" />
2
+ import { SxProps, Theme } from '@mui/material';
3
+ interface Button {
4
+ label: React.ReactNode;
5
+ onClick: (event: React.MouseEvent) => void;
6
+ autoFocus?: boolean;
7
+ variant?: 'outlined' | 'solid';
8
+ disabled?: boolean;
9
+ }
10
+ interface ModalContentProps {
11
+ title: React.ReactNode;
12
+ description?: React.ReactNode;
13
+ children: React.ReactNode;
14
+ sx?: SxProps<Theme>;
15
+ open: boolean;
16
+ onClose: () => void;
17
+ buttons?: Button[];
18
+ icon?: string;
19
+ keepMounted?: boolean;
20
+ }
21
+ export default function Modal(props: ModalContentProps): JSX.Element;
22
+ export {};
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { StyledDialogContentBody, StyledDialogContent, StyledDialogActions, } from './Modal.styles';
3
+ import { OutlinedButton, SolidButton } from '../Button/Button.styles';
4
+ import { forwardRef } from 'react';
5
+ import Slide from '@mui/material/Slide';
6
+ import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
7
+ import { Box, Dialog, DialogContentText, DialogTitle, IconButton, } from '@mui/material';
8
+ const Transition = forwardRef(function Transition(props, ref) {
9
+ return _jsx(Slide, Object.assign({}, props, { direction: 'up', ref: ref }));
10
+ });
11
+ export default function Modal(props) {
12
+ const { title, description, children, sx, open, onClose, buttons, icon, keepMounted = false, } = props;
13
+ const handleKeyDown = (event) => {
14
+ event.stopPropagation();
15
+ };
16
+ const renderButton = (button, index) => {
17
+ var _a;
18
+ const ButtonTypeComponent = button.variant === 'outlined' ? OutlinedButton : SolidButton;
19
+ return (_jsx(ButtonTypeComponent, Object.assign({ onClick: button.onClick, autoFocus: button.autoFocus, disabled: (_a = button.disabled) !== null && _a !== void 0 ? _a : false, sx: { flex: 1 } }, { children: button.label }), index));
20
+ };
21
+ return (_jsxs(Dialog, Object.assign({ open: open, onClose: onClose, TransitionComponent: Transition, "aria-labelledby": 'alert-dialog-slide-title', "aria-describedby": 'alert-dialog-slide-description', onKeyDown: handleKeyDown, keepMounted: keepMounted }, { children: [_jsx(Box, Object.assign({ sx: { position: 'absolute', right: 8, top: 8 } }, { children: _jsx(IconButton, Object.assign({ onClick: onClose }, { children: _jsx(CloseRoundedIcon, {}) })) })), icon && _jsx("img", { src: icon, className: 'modal-icon', alt: 'dialog icon' }), _jsx(DialogTitle, Object.assign({ id: 'alert-dialog-slide-title' }, { children: title })), _jsxs(StyledDialogContent, { children: [description && (_jsx(DialogContentText, Object.assign({ id: 'alert-dialog-slide-description' }, { children: description }))), _jsx(StyledDialogContentBody, Object.assign({ sx: sx }, { children: children }))] }), buttons && (_jsx(StyledDialogActions, Object.assign({ style: { padding: 0 } }, { children: buttons === null || buttons === void 0 ? void 0 : buttons.map(renderButton) })))] })));
22
+ }
@@ -0,0 +1,32 @@
1
+ /// <reference types="react" />
2
+ import { SxProps, Theme } from '@mui/material';
3
+ declare type StyledDialogContentBodyProps = {
4
+ sx?: SxProps<Theme>;
5
+ };
6
+ export declare const StyledDialogContentBody: import("@mui/styles").StyledComponent<Omit<import("@mui/system").SystemProps<Theme> & {
7
+ children?: import("react").ReactNode;
8
+ component?: import("react").ElementType<any> | undefined;
9
+ ref?: import("react").Ref<unknown> | undefined;
10
+ sx?: SxProps<Theme> | undefined;
11
+ } & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("react").HTMLAttributes<HTMLDivElement> | "key"> & {
12
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
13
+ }, "children" | "ref" | "sx" | "component" | ("color" | "p" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxShadow" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "zIndex" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint")>, "classes" | "className"> & import("@mui/styles").StyledComponentProps<"root"> & Omit<Pick<import("@mui/system").SystemProps<Theme> & {
14
+ children?: import("react").ReactNode;
15
+ component?: import("react").ElementType<any> | undefined;
16
+ ref?: import("react").Ref<unknown> | undefined;
17
+ sx?: SxProps<Theme> | undefined;
18
+ } & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("react").HTMLAttributes<HTMLDivElement> | "key"> & {
19
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
20
+ }, "children" | "ref" | "sx" | "component" | ("color" | "p" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxShadow" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "zIndex" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint")>, "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "children" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "sx" | "key" | "component" | ("color" | "p" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxShadow" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "zIndex" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint")>, "className" | "theme"> & {
21
+ className?: string | undefined;
22
+ theme?: StyledDialogContentBodyProps | undefined;
23
+ }>;
24
+ export declare const StyledDialogContent: import("@mui/styles").StyledComponent<Omit<import("@mui/material").DialogContentProps, "classes" | "className"> & import("@mui/styles").StyledComponentProps<"root"> & Omit<Pick<import("@mui/material").DialogContentProps, "classes" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "children" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "sx" | "dividers">, "className" | "theme"> & {
25
+ className?: string | undefined;
26
+ theme?: import("@mui/styles").DefaultTheme | undefined;
27
+ }>;
28
+ export declare const StyledDialogActions: import("@mui/styles").StyledComponent<Omit<import("@mui/material").DialogActionsProps, "classes" | "className"> & import("@mui/styles").StyledComponentProps<"root"> & Omit<Pick<import("@mui/material").DialogActionsProps, "classes" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "children" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "sx" | "disableSpacing">, "className" | "theme"> & {
29
+ className?: string | undefined;
30
+ theme?: import("@mui/styles").DefaultTheme | undefined;
31
+ }>;
32
+ export {};
@@ -0,0 +1,17 @@
1
+ import { Box, DialogContent, DialogActions, } from '@mui/material';
2
+ import { styled } from '@mui/styles';
3
+ export const StyledDialogContentBody = styled(Box)(({ sx }) => {
4
+ const resolvedStyles = Object.assign({ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 'var(--spacing-md)' }, sx);
5
+ return resolvedStyles;
6
+ });
7
+ export const StyledDialogContent = styled(DialogContent)(() => {
8
+ return {
9
+ minWidth: '350px',
10
+ };
11
+ });
12
+ export const StyledDialogActions = styled(DialogActions)(() => {
13
+ return {
14
+ padding: 0,
15
+ marginTop: '10px',
16
+ };
17
+ });
@@ -1,6 +1,7 @@
1
1
  import EntityService from '../../services/entity/EntityService';
2
2
  import { CancelToken } from 'axios';
3
3
  import { EntityList } from 'router/parseRoutes';
4
+ import { SelectOptionsType } from 'entities/EntityInterface';
4
5
  declare type AutoSelectOptionsArgs = {
5
6
  cancelToken?: CancelToken;
6
7
  entities?: EntityList;
@@ -9,4 +10,9 @@ declare type AutoSelectOptionsArgs = {
9
10
  response: Record<string, Array<unknown>> | any;
10
11
  };
11
12
  export declare const autoSelectOptions: (props: AutoSelectOptionsArgs) => Array<Promise<unknown>>;
13
+ declare type AutoSelectOptionHandlersArgs = {
14
+ entityService: EntityService;
15
+ skip?: string[];
16
+ };
17
+ export declare const autoSelectOptionHandlers: (props: AutoSelectOptionHandlersArgs) => Promise<Record<string, SelectOptionsType>>;
12
18
  export default autoSelectOptions;
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { StoreContainer } from '../../store';
2
11
  export const autoSelectOptions = (props) => {
3
12
  const { cancelToken, response, entityService } = props;
@@ -51,4 +60,46 @@ export const autoSelectOptions = (props) => {
51
60
  }
52
61
  return promises;
53
62
  };
63
+ export const autoSelectOptionHandlers = (props) => __awaiter(void 0, void 0, void 0, function* () {
64
+ const { entityService } = props;
65
+ const entities = StoreContainer.store.getState().entities.entities;
66
+ const handlers = {};
67
+ if (!entities) {
68
+ return handlers;
69
+ }
70
+ const skip = props.skip || [];
71
+ const fkProperties = entityService === null || entityService === void 0 ? void 0 : entityService.getFkProperties();
72
+ const promises = [];
73
+ for (const idx in fkProperties) {
74
+ if (skip.includes(idx)) {
75
+ continue;
76
+ }
77
+ const cleanRef = fkProperties[idx].$ref.replace('#/definitions/', '');
78
+ const entity = entities[cleanRef];
79
+ if (!entity) {
80
+ if (cleanRef && cleanRef.indexOf('_') < 0) {
81
+ console.log('autoSelectOptionsHandlers', `${cleanRef} not found`);
82
+ }
83
+ continue;
84
+ }
85
+ if (!entity.selectOptions) {
86
+ if (cleanRef && cleanRef.indexOf('_') < 0) {
87
+ console.log('autoSelectOptionsHandlers', `${cleanRef} selectOption is not defined`);
88
+ }
89
+ continue;
90
+ }
91
+ if (!entity.dynamicSelectOptions) {
92
+ continue;
93
+ }
94
+ const selectOptionsLoader = entity.selectOptions;
95
+ if (!selectOptionsLoader) {
96
+ continue;
97
+ }
98
+ promises.push(selectOptionsLoader().then((handler) => {
99
+ handlers[cleanRef] = handler;
100
+ }));
101
+ }
102
+ yield Promise.all(promises);
103
+ return handlers;
104
+ });
54
105
  export default autoSelectOptions;
@@ -0,0 +1,3 @@
1
+ import { DynamicAutocompleteGetterType } from '../EntityInterface';
2
+ declare const dynamicAutocompleteGetters: DynamicAutocompleteGetterType;
3
+ export default dynamicAutocompleteGetters;
@@ -0,0 +1,19 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { autoSelectOptionHandlers } from './AutoSelectOptions';
11
+ const dynamicAutocompleteGetters = (props) => __awaiter(void 0, void 0, void 0, function* () {
12
+ const { entityService } = props;
13
+ const getters = yield autoSelectOptionHandlers({
14
+ entityService,
15
+ skip: [],
16
+ });
17
+ return getters;
18
+ });
19
+ export default dynamicAutocompleteGetters;
@@ -1,9 +1,9 @@
1
1
  import { CancelToken } from 'axios';
2
2
  import * as React from 'react';
3
3
  import { EntityValues } from '../services/entity/EntityService';
4
- import { ChildDecoratorProps, ChildDecoratorType, EntityAclType, FetchFksCallback, OrderDirection, calculateAclType } from './EntityInterface';
4
+ import { ChildDecoratorProps, ChildDecoratorType, DynamicAutocompleteGetterTypeArgs, EntityAclType, FetchFksCallback, OrderDirection, calculateAclType } from './EntityInterface';
5
5
  import autoForeignKeyResolver from './DefaultEntityBehavior/AutoForeignKeyResolver';
6
- import autoSelectOptions from './DefaultEntityBehavior/AutoSelectOptions';
6
+ import autoSelectOptions, { autoSelectOptionHandlers } from './DefaultEntityBehavior/AutoSelectOptions';
7
7
  import filterFieldsetGroups, { FieldsetGroups } from './DefaultEntityBehavior/FilterFieldsetGroups';
8
8
  import foreignKeyGetter from './DefaultEntityBehavior/ForeignKeyGetter';
9
9
  import foreignKeyResolver from './DefaultEntityBehavior/ForeignKeyResolver';
@@ -34,6 +34,7 @@ declare const DefaultEntityBehavior: {
34
34
  unmarshaller: (row: MarshallerValues, properties: import("..").PartialPropertyList) => MarshallerValues;
35
35
  foreignKeyResolver: () => Promise<import("./EntityInterface").foreignKeyResolverType>;
36
36
  foreignKeyGetter: () => Promise<import("./EntityInterface").ForeignKeyGetterType>;
37
+ dynamicAutocompleteGetters: (props: DynamicAutocompleteGetterTypeArgs) => Promise<Record<string, import("./EntityInterface").SelectOptionsType<any>>>;
37
38
  columns: never[];
38
39
  properties: {};
39
40
  acl: EntityAclType;
@@ -51,5 +52,5 @@ declare const DefaultEntityBehavior: {
51
52
  defaultOrderDirection: OrderDirection;
52
53
  };
53
54
  export default DefaultEntityBehavior;
54
- export { Form, ListDecorator, View, autoForeignKeyResolver, autoSelectOptions, filterFieldsetGroups, foreignKeyGetter, foreignKeyResolver, marshaller, unmarshaller, validator, };
55
+ export { Form, ListDecorator, View, autoForeignKeyResolver, autoSelectOptions, autoSelectOptionHandlers, filterFieldsetGroups, foreignKeyGetter, foreignKeyResolver, marshaller, unmarshaller, validator, };
55
56
  export type { EntityFormProps, EntityFormType, FieldsetGroups, FkChoices, MarshallerValues, NullablePropertyFkChoices, PropertyFkChoices, };
@@ -12,7 +12,7 @@ import { OrderDirection, } from './EntityInterface';
12
12
  import { fetchAllPages } from '../helpers/fechAllPages';
13
13
  import { isEntityItem } from '../router';
14
14
  import autoForeignKeyResolver from './DefaultEntityBehavior/AutoForeignKeyResolver';
15
- import autoSelectOptions from './DefaultEntityBehavior/AutoSelectOptions';
15
+ import autoSelectOptions, { autoSelectOptionHandlers, } from './DefaultEntityBehavior/AutoSelectOptions';
16
16
  import filterFieldsetGroups from './DefaultEntityBehavior/FilterFieldsetGroups';
17
17
  import foreignKeyGetter from './DefaultEntityBehavior/ForeignKeyGetter';
18
18
  import foreignKeyResolver from './DefaultEntityBehavior/ForeignKeyResolver';
@@ -74,6 +74,10 @@ const DefaultEntityBehavior = {
74
74
  const module = yield import('./DefaultEntityBehavior/ForeignKeyGetter');
75
75
  return module.default;
76
76
  }),
77
+ dynamicAutocompleteGetters: (props) => __awaiter(void 0, void 0, void 0, function* () {
78
+ const module = yield import('./DefaultEntityBehavior/DynamicAutocompleteGetter');
79
+ return module.default(props);
80
+ }),
77
81
  columns,
78
82
  properties,
79
83
  acl,
@@ -99,4 +103,4 @@ const DefaultEntityBehavior = {
99
103
  defaultOrderDirection: OrderDirection.asc,
100
104
  };
101
105
  export default DefaultEntityBehavior;
102
- export { Form, ListDecorator, View, autoForeignKeyResolver, autoSelectOptions, filterFieldsetGroups, foreignKeyGetter, foreignKeyResolver, marshaller, unmarshaller, validator, };
106
+ export { Form, ListDecorator, View, autoForeignKeyResolver, autoSelectOptions, autoSelectOptionHandlers, filterFieldsetGroups, foreignKeyGetter, foreignKeyResolver, marshaller, unmarshaller, validator, };
@@ -47,10 +47,15 @@ export declare type SelectOptionsArgs = {
47
47
  callback: FetchFksCallback;
48
48
  cancelToken?: CancelToken;
49
49
  };
50
+ export declare type DynamicAutocompleteGetterTypeArgs = {
51
+ entityService: EntityService;
52
+ skip?: Array<string>;
53
+ };
50
54
  export declare type DynamicSelectOptionsArgs = {
51
55
  searchTerm?: string;
52
56
  id?: string;
53
57
  };
58
+ export declare type DynamicAutocompleteGetterType = (props: DynamicAutocompleteGetterTypeArgs) => Promise<Record<string, SelectOptionsType>>;
54
59
  export declare type SelectOptionsType<T = any> = (props: SelectOptionsArgs, customProps?: T) => Promise<unknown>;
55
60
  export declare type EntityAclType = {
56
61
  iden?: string;
@@ -94,6 +99,7 @@ export default interface EntityInterface {
94
99
  foreignKeyResolver: () => Promise<foreignKeyResolverType>;
95
100
  foreignKeyGetter: () => Promise<ForeignKeyGetterType>;
96
101
  selectOptions?: () => Promise<SelectOptionsType>;
102
+ dynamicAutocompleteGetters: DynamicAutocompleteGetterType;
97
103
  dynamicSelectOptions?: boolean;
98
104
  Form: () => Promise<React.FunctionComponent<EntityFormProps>>;
99
105
  View: () => Promise<ViewType>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@irontec/ivoz-ui",
3
- "version": "1.7.13",
3
+ "version": "1.7.14",
4
4
  "description": "UI library used in ivozprovider",
5
5
  "license": "GPL-3.0",
6
6
  "main": "index.js",
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { IvozStoreState } from 'store';
3
3
  import { SearchFilterType } from '../../components/List/Filter/icons/FilterIconFactory';
4
- import EntityInterface, { EntityAclType, ForeignKeyGetterType, OrderDirection } from '../../entities/EntityInterface';
4
+ import EntityInterface, { DynamicAutocompleteGetterTypeArgs, EntityAclType, ForeignKeyGetterType, OrderDirection, SelectOptionsType } from '../../entities/EntityInterface';
5
5
  import { ActionModelSpec, ActionsSpec, PropertyList, fkPropertyList, visualToggleList } from '../../services/api/ParsedApiSpecInterface';
6
6
  export declare type VisualToggleStates = {
7
7
  [key: string]: boolean;
@@ -42,6 +42,7 @@ export default class EntityService<T extends IvozStoreState = IvozStoreState> {
42
42
  getOrderDirection(): OrderDirection;
43
43
  getAcls(parentRow?: EntityValues): EntityAclType;
44
44
  getForeignKeyGetter(): ForeignKeyGetterType;
45
+ getDynamicAutocompleteGetters(props: DynamicAutocompleteGetterTypeArgs): Promise<Record<string, SelectOptionsType>>;
45
46
  getListDecorator(): import("../../entities/EntityInterface").ListDecoratorType;
46
47
  getPropertyFilters(propertyName: string, path?: string): Array<SearchFilterType>;
47
48
  private getIden;
@@ -347,6 +347,9 @@ export default class EntityService {
347
347
  getForeignKeyGetter() {
348
348
  return this.entityDefinition.foreignKeyGetter;
349
349
  }
350
+ getDynamicAutocompleteGetters(props) {
351
+ return this.entityDefinition.dynamicAutocompleteGetters(props);
352
+ }
350
353
  getListDecorator() {
351
354
  return this.entityDefinition.ListDecorator;
352
355
  }
@@ -1,9 +1,11 @@
1
1
  import { InputProps } from '@mui/material';
2
2
  import React, { JSXElementConstructor, ReactElement } from 'react';
3
+ import { DropdownChoices } from '../Dropdown';
3
4
  import { SelectOptionsType } from 'entities/EntityInterface';
4
5
  import { FormOnChangeEvent } from 'entities/DefaultEntityBehavior/Form/Form';
5
6
  export interface DynamicAutocompleteProps {
6
- selectOptions: (() => Promise<SelectOptionsType>) | undefined;
7
+ choices: DropdownChoices;
8
+ selectOptions?: SelectOptionsType;
7
9
  nullOption?: string | React.ReactElement<any>;
8
10
  className?: string;
9
11
  name: string;
@@ -7,7 +7,7 @@ import { StyledAutocompleteTextField } from '../TextField';
7
7
  import SearchIcon from '@mui/icons-material/Search';
8
8
  const DynamicAutocomplete = (props) => {
9
9
  var _a;
10
- const { nullOption, name, label, required, multiple, disabled, onBlur, error, errorMsg, helperText, hasChanged, value, selectOptions, onChange, } = props;
10
+ const { nullOption, name, label, required, multiple, disabled, onBlur, error, errorMsg, helperText, hasChanged, value, choices, selectOptions, onChange, } = props;
11
11
  const { t } = useTranslation();
12
12
  let className = props.className;
13
13
  if (hasChanged) {
@@ -16,15 +16,50 @@ const DynamicAutocomplete = (props) => {
16
16
  if (multiple) {
17
17
  className += ' multiselect';
18
18
  }
19
- const nullOptionObject = nullOption
20
- ? { id: '__null__', label: nullOption }
21
- : null;
22
- const [arrayChoices, setArrayChoices] = useState(nullOptionObject ? [nullOptionObject] : []);
19
+ const nullOptionObject = {
20
+ id: '__null__',
21
+ label: nullOption !== null && nullOption !== void 0 ? nullOption : '',
22
+ };
23
+ const [arrayChoices, setArrayChoices] = useState([]);
23
24
  const [searchTerm, setSearchTerm] = useState('');
24
25
  const [loading, setLoading] = useState(false);
25
- const [open, setOpen] = useState(false);
26
26
  const [currentOption, setCurrentOption] = useState(nullOptionObject);
27
27
  const debounceTimeoutRef = useRef();
28
+ useEffect(() => {
29
+ if (Array.isArray(choices)) {
30
+ setArrayChoices(choices);
31
+ return;
32
+ }
33
+ const arrayValue = [];
34
+ for (const idx in choices) {
35
+ arrayValue.push({ id: idx, label: choices[idx] });
36
+ }
37
+ setArrayChoices(arrayValue);
38
+ }, [choices]);
39
+ useEffect(() => {
40
+ const nullValue = !value || value === '__null__';
41
+ if (nullValue) {
42
+ return;
43
+ }
44
+ if (!choices) {
45
+ return;
46
+ }
47
+ const choicesIncludesValue = Array.isArray(choices)
48
+ ? choices.some((item) => item.id === value)
49
+ : choices && value in choices;
50
+ if (choicesIncludesValue) {
51
+ return;
52
+ }
53
+ selectOptions === null || selectOptions === void 0 ? void 0 : selectOptions({
54
+ callback: (options) => {
55
+ const option = options[0];
56
+ arrayChoices.push(option);
57
+ setArrayChoices(arrayChoices);
58
+ },
59
+ }, {
60
+ id: value,
61
+ });
62
+ }, []);
28
63
  const setOptions = useCallback((options) => {
29
64
  const isCurrentOptionIncluded = options.some((option) => option.id == (currentOption === null || currentOption === void 0 ? void 0 : currentOption.id));
30
65
  if (!isCurrentOptionIncluded &&
@@ -35,59 +70,45 @@ const DynamicAutocomplete = (props) => {
35
70
  if (nullOptionObject) {
36
71
  options.unshift(nullOptionObject);
37
72
  }
38
- console.log('setOptions', options);
39
73
  setArrayChoices(options);
40
74
  }, [nullOptionObject, currentOption]);
41
- useEffect(() => {
42
- const hasOptions = arrayChoices.some((option) => option.id !== '__null__');
43
- if (hasOptions) {
44
- return;
75
+ const clearSearch = useCallback(() => {
76
+ if (debounceTimeoutRef.current) {
77
+ clearTimeout(debounceTimeoutRef.current);
45
78
  }
46
- const searchParams = {};
47
- if (value) {
48
- searchParams.id = value;
79
+ setLoading(false);
80
+ }, []);
81
+ const loadOptions = useCallback((searchValue) => {
82
+ if (!selectOptions) {
83
+ console.error('selectOptions is not defined');
84
+ return;
49
85
  }
50
- selectOptions === null || selectOptions === void 0 ? void 0 : selectOptions().then((selectOptions) => {
86
+ setLoading(true);
87
+ debounceTimeoutRef.current = setTimeout(() => {
51
88
  selectOptions({
52
89
  callback: (options) => {
53
- if (options.length > 0) {
54
- setOptions(options);
55
- }
90
+ setLoading(false);
91
+ setOptions(options);
56
92
  },
57
- }, searchParams);
58
- });
59
- }, []);
93
+ }, {
94
+ searchTerm: searchValue,
95
+ });
96
+ }, 500);
97
+ }, [searchTerm, selectOptions]);
60
98
  useEffect(() => {
61
- if (!selectOptions) {
62
- return;
63
- }
64
- if (debounceTimeoutRef.current) {
65
- clearTimeout(debounceTimeoutRef.current);
66
- }
99
+ clearSearch();
67
100
  const searchTermMatchNullOption = getOptionLabel(nullOptionObject) === searchTerm;
68
101
  if (searchTermMatchNullOption) {
69
102
  return;
70
103
  }
71
- const isSearchTermIncluded = arrayChoices === null || arrayChoices === void 0 ? void 0 : arrayChoices.some((option) => getOptionLabel(option).includes(searchTerm));
104
+ const isSearchTermIncluded = searchTerm !== '' &&
105
+ (arrayChoices === null || arrayChoices === void 0 ? void 0 : arrayChoices.some((option) => getOptionLabel(option).includes(searchTerm)));
72
106
  if (isSearchTermIncluded) {
73
107
  return;
74
108
  }
75
- setLoading(true);
76
- debounceTimeoutRef.current = setTimeout(() => {
77
- selectOptions().then((selectOptions) => {
78
- selectOptions({
79
- callback: (options) => {
80
- setLoading(false);
81
- setOptions(options);
82
- },
83
- }, {
84
- searchTerm: searchTerm,
85
- });
86
- });
87
- }, 500);
109
+ loadOptions(searchTerm);
88
110
  }, [searchTerm, selectOptions]);
89
111
  const handleInputChange = useCallback((e, value, reason) => {
90
- console.log('inputChange', arrayChoices);
91
112
  if (reason === 'clear') {
92
113
  setSearchTerm('');
93
114
  return;
@@ -188,7 +209,9 @@ const DynamicAutocomplete = (props) => {
188
209
  const disableClearable = arrayChoices.find((item) => item.id === '__null__')
189
210
  ? false
190
211
  : true;
191
- const safeValue = value.length !== '' ? value : null;
192
- return (_jsx(MuiAutocomplete, { className: 'dynamic-autocomplete' + className, value: safeValue, multiple: multiple, disabled: disabled, disableClearable: disableClearable, onChange: onChangeWrapper, onBlur: onBlur, onInputChange: handleInputChange, onClose: () => setOpen(false), onOpen: () => setOpen(true), options: arrayChoices !== null && arrayChoices !== void 0 ? arrayChoices : [], getOptionLabel: getOptionLabel, isOptionEqualToValue: isOptionEqualToValue, loading: loading, placeholder: props.placeholder, renderInput: renderInput, PaperComponent: CustomOption, renderOption: (props, option) => (_jsx(Box, Object.assign({ component: 'li', className: 'autocomplete-option', "data-value": option.id }, props, { children: option.label }))) }));
212
+ const safeValue = arrayChoices.find((item) => item.id === value)
213
+ ? value
214
+ : null;
215
+ return (_jsx(MuiAutocomplete, { className: 'dynamic-autocomplete' + className, value: safeValue, multiple: multiple, disabled: disabled, disableClearable: disableClearable, onChange: onChangeWrapper, onBlur: onBlur, onInputChange: handleInputChange, options: arrayChoices !== null && arrayChoices !== void 0 ? arrayChoices : [], getOptionLabel: getOptionLabel, isOptionEqualToValue: isOptionEqualToValue, loading: loading, placeholder: props.placeholder, renderInput: renderInput, PaperComponent: CustomOption, renderOption: (props, option) => (_jsx(Box, Object.assign({ component: 'li', className: 'autocomplete-option', "data-value": option.id }, props, { children: option.label }))) }));
193
216
  };
194
217
  export default DynamicAutocomplete;
@@ -1,22 +1,22 @@
1
1
  /// <reference types="react" />
2
2
  import { PropertySpec } from '../../../api';
3
3
  import { ScalarEntityValue } from '../../../entity';
4
- import { NullableFormFieldFactoryChoices } from '../FormFieldFactory';
5
- import { SelectOptionsType } from 'entities/EntityInterface';
6
4
  import { FormOnChangeEvent } from 'entities/DefaultEntityBehavior/Form/Form';
5
+ import EntityService from 'services/entity/EntityService';
6
+ import { NullableFormFieldFactoryChoices } from 'services/form';
7
7
  declare type DynamicAutocompleteFactoryPropsType = {
8
8
  fld: string;
9
9
  property: PropertySpec;
10
10
  disabled: boolean;
11
11
  multiSelect: boolean;
12
12
  value: ScalarEntityValue | Array<ScalarEntityValue>;
13
+ choices: NullableFormFieldFactoryChoices;
13
14
  hasChanged: boolean;
14
15
  error: React.ReactNode;
15
16
  touched: boolean | undefined;
16
17
  changeHandler: (event: FormOnChangeEvent) => void;
17
- choices: NullableFormFieldFactoryChoices;
18
18
  handleBlur: (event: React.FocusEvent) => void;
19
- selectOptions: (() => Promise<SelectOptionsType>) | undefined;
19
+ entityService: EntityService;
20
20
  };
21
21
  export declare const DynamicAutocompleteFactory: (props: DynamicAutocompleteFactoryPropsType) => JSX.Element;
22
22
  export {};
@@ -1,6 +1,43 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isPropertyFk } from '../../../api';
2
3
  import { DynamicAutocomplete } from '../../Field/DynamicAutocomplete';
4
+ import { Skeleton } from '@mui/material';
5
+ import { useEffect, useState } from 'react';
3
6
  export const DynamicAutocompleteFactory = (props) => {
4
- const { selectOptions, fld, disabled, multiSelect, value, hasChanged, error, touched, property, changeHandler, handleBlur, } = props;
5
- return (_jsx(DynamicAutocomplete, { name: fld, label: property.label, value: value, multiple: multiSelect, nullOption: property.null, required: property.required, disabled: disabled, onBlur: handleBlur, error: touched && Boolean(error), errorMsg: touched && error, helperText: property.helpText, hasChanged: hasChanged, onChange: changeHandler, selectOptions: selectOptions }));
7
+ const { entityService, fld, disabled, multiSelect, value, hasChanged, error, touched, property, changeHandler, handleBlur, } = props;
8
+ let { choices } = props;
9
+ const [selectOptionsLoader, setSelectOptionsLoader] = useState(undefined);
10
+ const cleanRef = isPropertyFk(property)
11
+ ? property.$ref.replace('#/definitions/', '')
12
+ : '';
13
+ useEffect(() => {
14
+ if (!cleanRef) {
15
+ return;
16
+ }
17
+ const selectOptionsGetter = entityService.getDynamicAutocompleteGetters({
18
+ entityService,
19
+ skip: [],
20
+ });
21
+ selectOptionsGetter.then((getters) => {
22
+ const selectOptions = getters[cleanRef];
23
+ if (selectOptions) {
24
+ setSelectOptionsLoader({ selectOptions: selectOptions });
25
+ }
26
+ });
27
+ }, [cleanRef, entityService]);
28
+ if (!selectOptionsLoader || !choices) {
29
+ return (_jsxs(_Fragment, { children: [_jsx(Skeleton, { width: '50%' }), _jsx(Skeleton, { variant: 'rectangular', height: 42 })] }));
30
+ }
31
+ if (property.null) {
32
+ if (Array.isArray(choices)) {
33
+ const nullAlreadyAssigned = choices.find((item) => item.id == '__null__');
34
+ if (!nullAlreadyAssigned) {
35
+ choices = [{ label: property.null, id: '__null__' }, ...choices];
36
+ }
37
+ }
38
+ else {
39
+ choices = Object.assign({ __null__: property.null }, choices);
40
+ }
41
+ }
42
+ return (_jsx(DynamicAutocomplete, { name: fld, label: property.label, value: value, choices: choices, multiple: multiSelect, nullOption: property.null, required: property.required, disabled: disabled, onBlur: handleBlur, error: touched && Boolean(error), errorMsg: touched && error, helperText: property.helpText, hasChanged: hasChanged, onChange: changeHandler, selectOptions: selectOptionsLoader.selectOptions }));
6
43
  };
@@ -13,6 +13,7 @@ export default class FormFieldFactory {
13
13
  private divRef?;
14
14
  constructor(entityService: EntityService, formik: useFormikType, changeHandler: (event: FormOnChangeEvent) => void, handleBlur: (event: React.FocusEvent) => void, divRef?: React.RefObject<HTMLDivElement> | undefined);
15
15
  private getDynamicSelectOptions;
16
+ private isDynamicAutocomplete;
16
17
  getFormField(fld: string, choices: NullableFormFieldFactoryChoices, readOnly?: boolean): JSX.Element | null;
17
18
  createByPropertySpec(fld: string, property: PropertySpec, choices: NullableFormFieldFactoryChoices, readOnly?: boolean): JSX.Element | null;
18
19
  getProperty(fld: string): PropertySpec | null;
@@ -25,6 +25,18 @@ export default class FormFieldFactory {
25
25
  }
26
26
  return entities[entityName].selectOptions;
27
27
  }
28
+ isDynamicAutocomplete(property) {
29
+ var _a;
30
+ if (!isPropertyFk(property)) {
31
+ return false;
32
+ }
33
+ const entities = StoreContainer.store.getState().entities.entities;
34
+ const cleanRef = property.$ref.replace('#/definitions/', '');
35
+ if (!((_a = entities[cleanRef]) === null || _a === void 0 ? void 0 : _a.dynamicSelectOptions)) {
36
+ return false;
37
+ }
38
+ return true;
39
+ }
28
40
  getFormField(fld, choices, readOnly = false) {
29
41
  const property = this.getProperty(fld);
30
42
  if (!property) {
@@ -47,9 +59,8 @@ export default class FormFieldFactory {
47
59
  .component;
48
60
  return (_jsx(PropertyComponent, { _context: CustomFunctionComponentContext.write, _columnName: fld, readOnly: readOnly, formik: this.formik, values: this.formik.values, choices: choices, property: property, disabled: disabled, changeHandler: this.changeHandler, onBlur: this.handleBlur, formFieldFactory: this }));
49
61
  }
50
- const dynamicSelectOptions = this.getDynamicSelectOptions(property);
51
- if (dynamicSelectOptions) {
52
- return (_jsx(DynamicAutocompleteFactory, { fld: fld, property: property, disabled: disabled, multiSelect: multiSelect, value: value, hasChanged: hasChanged, error: error, touched: touched, selectOptions: dynamicSelectOptions, choices: choices, changeHandler: this.changeHandler, handleBlur: this.handleBlur }));
62
+ if (this.isDynamicAutocomplete(property)) {
63
+ return (_jsx(DynamicAutocompleteFactory, { fld: fld, property: property, disabled: disabled, multiSelect: multiSelect, value: value, hasChanged: hasChanged, error: error, touched: touched, choices: choices, changeHandler: this.changeHandler, handleBlur: this.handleBlur, entityService: this.entityService }));
53
64
  }
54
65
  if (isPropertyFk(property) || multiSelect) {
55
66
  return (_jsx(AutocompleteFactory, { fld: fld, property: property, disabled: disabled, multiSelect: multiSelect, value: value, hasChanged: hasChanged, error: error, touched: touched, choices: choices, changeHandler: this.changeHandler, handleBlur: this.handleBlur }));