fix: Reordered definitions in providers to prevent uninitialized var access (#2108)
This commit is contained in:
parent
330eeaa216
commit
619f361510
@ -45,36 +45,6 @@ const DialogProvider = ({ children, service }) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the implementation of a dialog service that can be used by extensions.
|
|
||||||
*
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
if (service) {
|
|
||||||
service.setServiceImplementation({ create, dismiss, dismissAll });
|
|
||||||
}
|
|
||||||
}, [create, dismiss, service]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UI Dialog
|
|
||||||
*
|
|
||||||
* @typedef {Object} DialogProps
|
|
||||||
* @property {string} id The dialog id.
|
|
||||||
* @property {DialogContent} content The dialog content.
|
|
||||||
* @property {Object} contentProps The dialog content props.
|
|
||||||
* @property {boolean} isDraggable Controls if dialog content is draggable or not.
|
|
||||||
* @property {boolean} showOverlay Controls dialog overlay.
|
|
||||||
* @property {boolean} centralize Center the dialog on the screen.
|
|
||||||
* @property {boolean} preservePosition Use last position instead of default.
|
|
||||||
* @property {ElementPosition} defaultPosition Specifies the `x` and `y` that the dragged item should start at.
|
|
||||||
* @property {Function} onStart Called when dragging starts. If `false` is returned any handler, the action will cancel.
|
|
||||||
* @property {Function} onStop Called when dragging stops.
|
|
||||||
* @property {Function} onDrag Called while dragging.
|
|
||||||
*/
|
|
||||||
|
|
||||||
useEffect(() => _bringToFront(lastDialogId), [_bringToFront, lastDialogId]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new dialog and return its id.
|
* Creates a new dialog and return its id.
|
||||||
*
|
*
|
||||||
@ -109,20 +79,15 @@ const DialogProvider = ({ children, service }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismisses all dialogs.
|
* Sets the implementation of a dialog service that can be used by extensions.
|
||||||
*
|
*
|
||||||
* @returns void
|
* @returns void
|
||||||
*/
|
*/
|
||||||
const dismissAll = () => {
|
useEffect(() => {
|
||||||
setDialogs([]);
|
if (service) {
|
||||||
};
|
service.setServiceImplementation({ create, dismiss, dismissAll });
|
||||||
|
}
|
||||||
/**
|
}, [create, dismiss, service]);
|
||||||
* Indicate if there are no dialogs present.
|
|
||||||
*
|
|
||||||
* @returns True if no dialogs are present.
|
|
||||||
*/
|
|
||||||
const isEmpty = () => dialogs && dialogs.length < 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the dialog to the foreground if clicked.
|
* Moves the dialog to the foreground if clicked.
|
||||||
@ -139,6 +104,41 @@ const DialogProvider = ({ children, service }) => {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UI Dialog
|
||||||
|
*
|
||||||
|
* @typedef {Object} DialogProps
|
||||||
|
* @property {string} id The dialog id.
|
||||||
|
* @property {DialogContent} content The dialog content.
|
||||||
|
* @property {Object} contentProps The dialog content props.
|
||||||
|
* @property {boolean} isDraggable Controls if dialog content is draggable or not.
|
||||||
|
* @property {boolean} showOverlay Controls dialog overlay.
|
||||||
|
* @property {boolean} centralize Center the dialog on the screen.
|
||||||
|
* @property {boolean} preservePosition Use last position instead of default.
|
||||||
|
* @property {ElementPosition} defaultPosition Specifies the `x` and `y` that the dragged item should start at.
|
||||||
|
* @property {Function} onStart Called when dragging starts. If `false` is returned any handler, the action will cancel.
|
||||||
|
* @property {Function} onStop Called when dragging stops.
|
||||||
|
* @property {Function} onDrag Called while dragging.
|
||||||
|
*/
|
||||||
|
|
||||||
|
useEffect(() => _bringToFront(lastDialogId), [_bringToFront, lastDialogId]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dismisses all dialogs.
|
||||||
|
*
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
|
const dismissAll = () => {
|
||||||
|
setDialogs([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate if there are no dialogs present.
|
||||||
|
*
|
||||||
|
* @returns True if no dialogs are present.
|
||||||
|
*/
|
||||||
|
const isEmpty = () => dialogs && dialogs.length < 1;
|
||||||
|
|
||||||
const renderDialogs = () =>
|
const renderDialogs = () =>
|
||||||
dialogs.map(dialog => {
|
dialogs.map(dialog => {
|
||||||
const {
|
const {
|
||||||
@ -219,14 +219,12 @@ const DialogProvider = ({ children, service }) => {
|
|||||||
</Draggable>
|
</Draggable>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return showOverlay ? (
|
||||||
showOverlay ? (
|
|
||||||
<div className="Overlay" key={id}>
|
<div className="Overlay" key={id}>
|
||||||
{dragableItem()}
|
{dragableItem()}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
dragableItem()
|
dragableItem()
|
||||||
)
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -249,11 +247,7 @@ const DialogProvider = ({ children, service }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContext.Provider value={{ create, dismiss, dismissAll, isEmpty }}>
|
<DialogContext.Provider value={{ create, dismiss, dismissAll, isEmpty }}>
|
||||||
{!isEmpty() &&
|
{!isEmpty() && <div className="DraggableArea">{renderDialogs()}</div>}
|
||||||
<div className="DraggableArea">
|
|
||||||
{renderDialogs()}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
{children}
|
{children}
|
||||||
</DialogContext.Provider>
|
</DialogContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -41,17 +41,6 @@ const ModalProvider = ({ children, modal: Modal, service }) => {
|
|||||||
|
|
||||||
const [options, setOptions] = useState(DEFAULT_OPTIONS);
|
const [options, setOptions] = useState(DEFAULT_OPTIONS);
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the implementation of a modal service that can be used by extensions.
|
|
||||||
*
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
if (service) {
|
|
||||||
service.setServiceImplementation({ hide, show });
|
|
||||||
}
|
|
||||||
}, [hide, service, show]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the modal and override its configuration props.
|
* Show the modal and override its configuration props.
|
||||||
*
|
*
|
||||||
@ -71,6 +60,17 @@ const ModalProvider = ({ children, modal: Modal, service }) => {
|
|||||||
DEFAULT_OPTIONS,
|
DEFAULT_OPTIONS,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the implementation of a modal service that can be used by extensions.
|
||||||
|
*
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
if (service) {
|
||||||
|
service.setServiceImplementation({ hide, show });
|
||||||
|
}
|
||||||
|
}, [hide, service, show]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
content: ModalContent,
|
content: ModalContent,
|
||||||
contentProps,
|
contentProps,
|
||||||
|
|||||||
@ -27,17 +27,6 @@ const SnackbarProvider = ({ children, service }) => {
|
|||||||
const [count, setCount] = useState(1);
|
const [count, setCount] = useState(1);
|
||||||
const [snackbarItems, setSnackbarItems] = useState([]);
|
const [snackbarItems, setSnackbarItems] = useState([]);
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the implementation of a notification service that can be used by extensions.
|
|
||||||
*
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
if (service) {
|
|
||||||
service.setServiceImplementation({ hide, show });
|
|
||||||
}
|
|
||||||
}, [service, hide, show]);
|
|
||||||
|
|
||||||
const show = useCallback(
|
const show = useCallback(
|
||||||
options => {
|
options => {
|
||||||
if (!options || (!options.title && !options.message)) {
|
if (!options || (!options.title && !options.message)) {
|
||||||
@ -92,6 +81,17 @@ const SnackbarProvider = ({ children, service }) => {
|
|||||||
setSnackbarItems(() => []);
|
setSnackbarItems(() => []);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the implementation of a notification service that can be used by extensions.
|
||||||
|
*
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
if (service) {
|
||||||
|
service.setServiceImplementation({ hide, show });
|
||||||
|
}
|
||||||
|
}, [service, hide, show]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* expose snackbar methods to window for debug purposes
|
* expose snackbar methods to window for debug purposes
|
||||||
* TODO: Check if it's really necessary
|
* TODO: Check if it's really necessary
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user