Skip to main content

useMMAppCommands

Returns functions for all capabilities of Embeddable Zones.

Usage

import { useMMAppCommands } from '@machinemetrics/mm-react-tools';

function MyWidget() {
const {
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());

// Show a confirmation dialog
const result = await confirm({
heading: 'Confirm Action',
body: 'Are you sure you want to proceed?',
choices: [
{ value: 'yes', label: 'Yes' },
{ value: 'no', label: 'No' },
],
});

if (result === 'yes') {
// Handle confirmation
console.log('User confirmed');
}
};

return (
<div>
<button onClick={handleAction}>Perform Action</button>
</div>
);
}

Returns

Returns an object containing:

  • toast: Function to show a toast notification
  • popup: Function to show a popup message (only available in Operator Dashboard)
  • setSummary: Function to set the tab sub heading in opdash
  • confirm: Function to show a confirmation dialog with options
  • setLoaded: Function to inform MachineMetrics that the app, widget, or input has loaded

confirm Parameters

ParameterDescription
headingThe heading text for the confirmation dialog
bodyThe body text for the confirmation dialog
choicesArray of objects with value and label properties