useMMAppCommands
Returns functions for all capabilities of Embeddable Zones.
Usage
import { useMMAppCommands } from '@machinemetrics/mm-react-tools';
function MyWidget() {
const {
launchModal, // open a sidesheet modal
toast, // present a toast notification to the user
popup, // mask screen and prompt user on opdash
setSummary, // set tab sub heading in opdash
confirm, // present an alert to the user with options
setLoaded, // informs framework that app/widget/input has loaded
} = useMMAppCommands();
const handleAction = async () => {
// Show a toast
toast('Operation completed successfully');
// Show a popup
popup('Please review the changes');
// Set a summary
setSummary('Last updated: ' + new Date().toLocaleString());
// Open a sidesheet modal
await launchModal(`${window.location.origin}/machine/123`, {
title: 'Machine Details',
editTitle: 'Edit Machine',
onSave: (data) => {
console.log('Saved:', data);
},
});
// Show a confirmation dialog
const result = await confirm({
heading: 'Confirm Action',
body: 'Are you sure you want to proceed?',
choices: [
{ value: 'no', label: 'No' },
{ value: 'yes', label: 'Yes' },
],
});
if (result === 'yes') {
// Handle confirmation
console.log('User confirmed');
}
};
return (
<div>
<button onClick={handleAction}>Perform Action</button>
</div>
);
}
Returns
Returns an object containing:
launchModal: Function to open a sidesheet modaltoast: Function to show a toast notificationpopup: Function to show a popup message (only available in Operator Dashboard)setSummary: Function to set the tab sub heading in opdashconfirm: Function to show a confirmation dialog with optionssetLoaded: Function to inform MachineMetrics that the app, widget, or input has loaded
launchModal Parameters
Opens a sidesheet modal that slides in from the right side of the screen.
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | Fully qualified URL to load in the modal (must include origin) |
options | object | No | Configuration options |
Options:
| Option | Type | Description |
|---|---|---|
title | string | Default title for the modal header |
editTitle | string | Title shown when in edit mode |
editOnly | boolean | Opens directly in edit mode (saves/cancels close the modal) |
onSave | function | Callback receiving data returned from useMMAppModalSave |
pagination | array | Array of { title, url } objects for navigating between items |
confirm Parameters
| Parameter | Description |
|---|---|
heading | The heading text for the confirmation dialog |
body | The body text for the confirmation dialog |
choices | Array of objects with value and label properties |