@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
143 lines (142 loc) • 5.59 kB
JavaScript
import * as PopupRedux from '../../Redux/ActionsReducers/PopupRedux';
import { ArrayExtensions } from '../../Utilities/Extensions/ArrayExtensions';
import { logDeprecation } from '../../Utilities/logDeprecation';
import UIHelper from '../../View/UIHelper';
import { CUSTOM_WINDOW_FACTORY_ID } from '../../View/Components/Popups/WindowPopups/WindowPopups';
import { UserInterfaceInternalApi } from '../Internal/UserInterfaceInternalApi';
import { ApiBase } from './ApiBase';
import { ProgressIndicatorHide, ProgressIndicatorShow, } from '../../Redux/ActionsReducers/PopupRedux';
import * as UserInterfaceRedux from '../../Redux/ActionsReducers/UserInterfaceRedux';
export class UserInterfaceApiImpl extends ApiBase {
internalApi;
showProgressIndicatorTimeout = null;
constructor(_adaptable) {
super(_adaptable);
this.internalApi = new UserInterfaceInternalApi(_adaptable);
}
getColorPalette() {
const colorPalette = this.getUserInterfaceOptions().colorPalette;
if (colorPalette != null) {
logDeprecation(this._adaptable.logger, 'UserInterfaceOptions', 'colorPalette', undefined, 'Override `--ab-color-swatch-*`, `--ab-color-palette-*`, and semantic `--ab-color-*` variables in your light or dark theme CSS instead. `colorPalette` will be removed in a future major release.');
if (typeof colorPalette === 'function') {
return colorPalette(this.getThemeApi().getCurrentTheme());
}
if (Array.isArray(colorPalette)) {
return colorPalette;
}
}
return UIHelper.getDefaultColorPalette();
}
getCustomIcons() {
let customIconsProp = this.getUserInterfaceOptions().customIcons;
if (customIconsProp != null) {
return typeof customIconsProp === 'function'
? customIconsProp()
: customIconsProp;
}
return [];
}
getStyleClassNames() {
return this.getUserInterfaceOptions().styleClassNames;
}
getEditableCellStyle() {
return this.getUserInterfaceOptions().editableCellStyle;
}
getEditedCellStyle() {
return this.getUserInterfaceOptions().editedCellStyle;
}
getReadOnlyCellStyle() {
return this.getUserInterfaceOptions().readOnlyCellStyle;
}
getAdaptableObjectTags() {
const objectTags = this.getUserInterfaceOptions().objectTags;
if (objectTags != null && typeof objectTags === 'function') {
return objectTags(this.getAdaptableInternalApi().buildBaseContext());
}
else {
let arr = objectTags;
if (arr && ArrayExtensions.IsNotNullOrEmpty(arr)) {
return arr;
}
}
}
getAdaptableObjectsWithTag(tag, adaptableModule) {
if (adaptableModule) {
const module = this.getAdaptableInternalApi()
.getModuleService()
.getModuleById(adaptableModule);
if (!module) {
return undefined;
}
return module
.getModuleAdaptableObjects()
?.filter((ao) => ao.Tags?.includes(tag));
}
else {
const modules = this.getAdaptableInternalApi().getModules();
let returnObjects = [];
modules.forEach((module) => {
returnObjects.push(...module
.getModuleAdaptableObjects()
?.filter((ao) => ao.Tags?.includes(tag)));
});
return returnObjects;
}
}
showProgressIndicator(config) {
const close = () => {
this.hideProgressIndicator();
};
if (config.delay) {
this.showProgressIndicatorTimeout = setTimeout(() => {
this.dispatchAction(ProgressIndicatorShow(config));
}, config.delay);
}
else {
this.dispatchAction(ProgressIndicatorShow(config));
}
return { close };
}
hideProgressIndicator() {
if (this.showProgressIndicatorTimeout) {
clearTimeout(this.showProgressIndicatorTimeout);
this.showProgressIndicatorTimeout = null;
}
this.dispatchAction(ProgressIndicatorHide());
}
openCustomWindowPopup(config) {
const close = () => {
this.dispatchAction(PopupRedux.PopupHideWindow(config.id));
};
const action = PopupRedux.PopupShowWindow({
Id: config.id,
Title: config.title,
FactoryId: CUSTOM_WINDOW_FACTORY_ID,
PopupProps: {
render: config.render,
frameworkComponent: config.frameworkComponent,
onFrameworkComponentDestroyed: config.onFrameworkComponentDestroyed,
size: config.size,
position: config.position,
},
Icon: config.icon,
});
this.dispatchAction(action);
return { close };
}
closeCustomWindowPopup(windowId) {
this.dispatchAction(PopupRedux.PopupHideWindow(windowId));
}
getUserInterfaceState() {
return this.getAdaptableState().UserInterface;
}
isAdaptableUIVisible() {
return !(this.getUserInterfaceState().HideAdaptableUI ?? false);
}
hideAdaptableUI() {
this.dispatchAction(UserInterfaceRedux.UserInterfaceSetHideAdaptableUI(true));
}
showAdaptableUI() {
this.dispatchAction(UserInterfaceRedux.UserInterfaceSetHideAdaptableUI(false));
}
}