@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
106 lines (105 loc) • 6.35 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import { StatusColour } from '../../AdaptableState/Common/Enums';
import { PreviewResultsPanel } from '../Components/PreviewResultsPanel';
import * as GeneralConstants from '../../Utilities/Constants/GeneralConstants';
import { BulkUpdateValueSelector } from '../Components/Selectors/BulkUpdateValueSelector';
import { StringExtensions } from '../../Utilities/Extensions/StringExtensions';
import { ButtonApply } from '../Components/Buttons/ButtonApply';
import { AdaptablePopover } from '../AdaptablePopover';
import { UIHelper } from '../UIHelper';
import * as InternalRedux from '../../Redux/ActionsReducers/InternalRedux';
import * as BulkUpdateRedux from '../../Redux/ActionsReducers/BulkUpdateRedux';
import { connect } from 'react-redux';
import { Flex } from '../../components/Flex';
import { cn } from '../../lib/utils';
class BulkUpdateViewPanelComponent extends React.Component {
cleanupEvent;
constructor(props) {
super(props);
this.state = {
Disabled: true,
};
}
componentDidMount() {
if (this.props.api) {
let adaptable = this.props.api.internalApi.getAdaptableInstance();
if (adaptable) {
this.cleanupEvent = adaptable._on('CellsSelected', () => {
this.checkSelectedCells();
});
}
}
this.checkSelectedCells();
}
componentWillUnmount() {
this.cleanupEvent?.();
}
render() {
let statusColour = this.getStatusColour();
let selectedColumn = this.props.BulkUpdateValidationResult.Column;
let previewPanel = (_jsx(PreviewResultsPanel, { previewInfo: this.props.PreviewInfo, api: this.props.api, selectedColumn: selectedColumn, showPanel: true, showHeader: false }));
const valueSelectorDisabled = this.props.accessLevel == GeneralConstants.ACCESS_LEVEL_READ_ONLY ||
!this.props.BulkUpdateValidationResult.IsValid ||
this.props.api.layoutApi.isCurrentLayoutPivot();
const valueOperationDisabled = valueSelectorDisabled ||
StringExtensions.IsNullOrEmpty(this.props.BulkUpdateValue) ||
(this.props.PreviewInfo != null &&
this.props.PreviewInfo.previewValidationSummary.validationResult == 'All');
const applyStyle = {
color: statusColour,
fill: 'currentColor',
};
const isToolbar = this.props.viewType === 'Toolbar';
const elementType = isToolbar ? 'DashboardToolbar' : 'ToolPanel';
const messageStyle = UIHelper.getMessageTypeByStatusColour(statusColour);
const infoStyle = messageStyle === 'Success' ? 'Info' : messageStyle;
return (_jsxs(Flex, { className: cn(valueSelectorDisabled ? GeneralConstants.READ_ONLY_STYLE : '', `ab-${elementType}__BulkUpdate__wrap twa:gap-1 twa:flex-row`, {
'twa:min-w-[300px] twa:max-w-[300px] twa:w-[300px] twa:flex-nowrap': isToolbar,
'twa:flex-1 twa:flex-wrap': !isToolbar,
}), flexWrap: isToolbar ? 'nowrap' : 'wrap', children: [_jsx(Flex, { className: cn('twa:flex-1', {
'twa:min-w-[100px]': !isToolbar,
'twa:min-w-0': isToolbar,
}), children: _jsx(BulkUpdateValueSelector, { selectedGridCells: this.props.SelectedGridCells, newLabel: "New", existingLabel: "Existing", className: `ab-${elementType}__BulkUpdate__select twa:w-full`, disabled: valueSelectorDisabled, selectedColumnValue: this.props.BulkUpdateValue, selectedColumn: selectedColumn, api: this.props.api, onColumnValueChange: (columns) => this.onColumnValueSelectedChanged(columns) }) }), _jsxs(Flex, { className: "twa:flex-shrink-0 twa:gap-1", children: [_jsx(Flex, { className: "twa:flex twa:box-border twa:items-stretch", children: _jsx(ButtonApply, { className: `ab-${elementType}__BulkUpdate__apply twa:h-full`, onClick: () => this.onApplyClick(), style: applyStyle, tooltip: "Apply Bulk Update", disabled: valueOperationDisabled, accessLevel: this.props.accessLevel, children: 'Apply' }) }), _jsx(AdaptablePopover, { popoverMinWidth: 360, popoverMaxWidth: 500, popupPadding: 0, className: `ab-${elementType}__BulkUpdate__info`, headerText: "Preview Results", bodyText: [previewPanel], MessageType: infoStyle, useButton: true, showEvent: 'focus', hideEvent: "blur", disabled: valueSelectorDisabled || StringExtensions.IsNullOrEmpty(this.props.BulkUpdateValue) })] })] }));
}
onColumnValueSelectedChanged(selectedColumnValue) {
this.props.onBulkUpdateValueChange(selectedColumnValue);
}
checkSelectedCells() {
this.props.onBulkUpdateCheckSelectedCells();
if (StringExtensions.IsNotNullOrEmpty(this.props.BulkUpdateValue)) {
this.props.onBulkUpdateValueChange('');
}
}
getStatusColour() {
if (StringExtensions.IsNotNullOrEmpty(this.props.BulkUpdateValue) && this.props.PreviewInfo) {
if (this.props.PreviewInfo.previewValidationSummary.validationResult == 'All') {
return StatusColour.Error;
}
if (this.props.PreviewInfo.previewValidationSummary.validationResult == 'Some') {
return StatusColour.Warn;
}
}
return StatusColour.Success;
}
onApplyClick() {
this.props.onApplyBulkUpdate();
this.props.onBulkUpdateValueChange(undefined);
}
}
function mapStateToProps(state, ownProps) {
return {
SelectedGridCells: state.Internal.SelectedCellInfo?.gridCells,
BulkUpdateValue: state.Internal.BulkUpdate.BulkUpdateValue,
BulkUpdateValidationResult: state.Internal.BulkUpdate.BulkUpdateValidationResult,
PreviewInfo: state.Internal.BulkUpdate.BulkUpdatePreviewInfo,
};
}
function mapDispatchToProps(dispatch) {
return {
onBulkUpdateValueChange: (value) => dispatch(InternalRedux.BulkUpdateChangeValue(value)),
onBulkUpdateCheckSelectedCells: () => dispatch(InternalRedux.BulkUpdateCheckCellSelection()),
onApplyBulkUpdate: () => dispatch(BulkUpdateRedux.BulkUpdateApply(false)),
};
}
export let BulkUpdateViewPanelControl = connect(mapStateToProps, mapDispatchToProps)(BulkUpdateViewPanelComponent);