@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
85 lines (84 loc) • 4.41 kB
JavaScript
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { OnePageAdaptableWizard, OnePageWizardSummary, } from '../../../View/Wizard/OnePageAdaptableWizard';
import { cloneObject } from '../../../Utilities/Helpers/Helper';
import { renderScopeSummary, isScopeValid } from '../../Components/NewScopeComponent';
import { ShortcutScopeWizardSection } from './ShortcutScopeWizardSection';
import { ShortcutSettingsSummary, ShortcutSettingsWizard, isSettingsValid, } from './ShortcutSettingsWizard';
import ObjectFactory from '../../../Utilities/ObjectFactory';
import { useDispatch } from 'react-redux';
import * as ShortcutRedux from '../../../Redux/ActionsReducers/ShortcutRedux';
import { shortcutKeys } from '../shortcutKeys';
import { useAdaptable } from '../../AdaptableContext';
import { ObjectTagsWizardSection, renderObjectTagsSummary, } from '../../Wizard/ObjectTagsWizardSection';
import { Box } from '../../../components/Flex';
import StringExtensions from '../../../Utilities/Extensions/StringExtensions';
export const ShortcutWizard = (props) => {
const [shortcut, doSetShortcut] = React.useState(() => {
const shortcut = props.data ? cloneObject(props.data) : ObjectFactory.CreateEmptyShortcut();
shortcut.Scope = shortcut.Scope ?? { All: true };
if (props.popupParams?.column && props.popupParams?.action === 'New') {
shortcut.Scope = {
ColumnIds: [props.popupParams.column.columnId],
};
}
return shortcut;
});
const setShortcut = React.useCallback((data) => {
doSetShortcut(data);
}, []);
const adaptable = useAdaptable();
const availableKeys = React.useMemo(() => {
const availableKeys = shortcutKeys.filter((key) => adaptable.api.shortcutApi.getShortcuts().every((shortcut) => shortcut.ShortcutKey !== key));
if (shortcut && StringExtensions.IsNotNullOrEmptyOrWhiteSpace(shortcut.ShortcutKey)) {
availableKeys.push(shortcut.ShortcutKey);
}
availableKeys.sort();
return availableKeys;
}, []);
const dispatch = useDispatch();
const handleFinish = () => {
if (props.data) {
dispatch(ShortcutRedux.ShortcutEdit(shortcut));
}
else {
dispatch(ShortcutRedux.ShortcutAdd(shortcut));
}
props.onFinishWizard(shortcut);
};
return (_jsx(OnePageAdaptableWizard, { defaultCurrentSectionName: props.defaultCurrentSectionName, moduleInfo: props.moduleInfo, data: shortcut, onHide: props.onCloseWizard, onFinish: handleFinish, sections: [
{
title: 'Settings',
isValid: isSettingsValid,
details: (_jsx(_Fragment, { children: "Provide details of the Shortcut" })),
renderSummary: () => _jsx(ShortcutSettingsSummary, {}),
render: () => (_jsx(Box, { className: "twa:p-2", children: _jsx(ShortcutSettingsWizard, { availableKeys: props.availableKeys ?? availableKeys, onChange: setShortcut }) })),
},
{
title: 'Target',
isValid: isScopeValid,
details: 'Specify where Shortcut should be applied',
renderSummary: () => renderScopeSummary(shortcut.Scope, {
scopeWholeRow: 'Shortcut is triggered for all numeric cells',
scopeColumns: 'Shortcut is triggered for cells in selected columns',
scopeDataTypes: '',
}),
render: () => (_jsx(Box, { className: "twa:p-2", children: _jsx(ShortcutScopeWizardSection, { onChange: setShortcut }) })),
},
{
details: 'Select Shortcut Tags',
title: 'Tags',
isVisible: (_, api) => api.internalApi.shouldDisplayTagSections(),
render: () => (_jsx(Box, { className: "twa:p-2", children: _jsx(ObjectTagsWizardSection, { onChange: setShortcut }) })),
renderSummary: renderObjectTagsSummary,
},
'-',
{
details: 'Review the Shortcut',
render: () => {
return (_jsx(Box, { className: "twa:p-2", children: _jsx(OnePageWizardSummary, {}) }));
},
title: 'Summary',
},
] }));
};