@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
55 lines (54 loc) • 2.59 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import * as InternalRedux from '../../Redux/ActionsReducers/InternalRedux';
import * as React from 'react';
import { StringExtensions } from '../../Utilities/Extensions/StringExtensions';
import { connect } from 'react-redux';
import ArrayExtensions from '../../Utilities/Extensions/ArrayExtensions';
import { Flex } from '../../components/Flex';
import { SingleSelect } from '../../components/NewSelect';
class DataSetViewPanelComponent extends React.Component {
getCurrentDataSet() {
return StringExtensions.IsNullOrEmpty(this.props.CurrentDataSetName)
? null
: this.getDataSets().find((ds) => ds.name == this.props.CurrentDataSetName);
}
getDataSets() {
return this.props.api.dataSetApi.getDataSets();
}
render() {
const selectDataSetString = 'Select Data Set';
let currentDataSetName = this.getCurrentDataSet()?.name ?? selectDataSetString;
let availableDataSets = this.getDataSets().map((dataSet) => {
return {
value: dataSet.name,
label: dataSet.name,
onClick: () => this.onSelectedDataSetChanged(dataSet.name),
};
});
const elementType = this.props.viewType === 'Toolbar' ? 'DashboardToolbar' : 'ToolPanel';
return (_jsx(Flex, { flexDirection: "row", className: `ab-${elementType}__DataSet__wrap`, children: _jsx(SingleSelect, { ariaLabel: 'Select Data Set', placeholder: 'Select Data Set', disabled: ArrayExtensions.IsNullOrEmpty(availableDataSets), items: availableDataSets, value: currentDataSetName, className: `ab-${elementType}__DataSet__select twa:w-full`, onValueChange: (destination) => this.onSelectedDataSetChanged(destination) }) }));
}
onSelectedDataSetChanged(dataSetName) {
if (StringExtensions.IsNullOrEmpty(dataSetName)) {
this.setState({ CurrentDataSet: null });
}
else {
let newDataSet = this.getDataSets().find((ds) => ds.name == dataSetName);
this.setState({ CurrentDataSet: newDataSet });
this.props.onSelectDataSet(newDataSet);
}
}
}
function mapStateToProps(state) {
return {
CurrentDataSetName: state.Internal.CurrentDataSet,
};
}
function mapDispatchToProps(dispatch) {
return {
onSelectDataSet: (dataSet) => {
return dispatch(InternalRedux.DataSetSelect(dataSet));
},
};
}
export let DataSetViewPanelControl = connect(mapStateToProps, mapDispatchToProps)(DataSetViewPanelComponent);