@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
53 lines (52 loc) • 2.08 kB
JavaScript
import * as ModuleConstants from '../../Utilities/Constants/ModuleConstants';
import { IsNullOrEmptyOrWhiteSpace } from '../../Utilities/Extensions/StringExtensions';
import { NamedQueryInternalApi } from '../Internal/NamedQueryInternalApi';
import { ApiBase } from './ApiBase';
import * as NamedQueryRedux from '../../Redux/ActionsReducers/NamedQueryRedux';
export class NamedQueryApiImpl extends ApiBase {
constructor(_adaptable) {
super(_adaptable);
this.internalApi = new NamedQueryInternalApi(_adaptable);
}
addNamedQuery(namedQuery) {
this.dispatchAction(NamedQueryRedux.NamedQueryAdd(namedQuery));
}
addNamedQueries(namedQueries) {
this.dispatchAction(NamedQueryRedux.NamedQueriesAdd(namedQueries));
}
getNamedQueryState() {
return this.getAdaptableState().NamedQuery;
}
getNamedQueries() {
return this.getNamedQueryState().NamedQueries || [];
}
getNamedQueryByName(namedQueryName) {
return this.getNamedQueries().find((se) => se.Name == namedQueryName);
}
isValidNamedQuery(namedQuery) {
if (IsNullOrEmptyOrWhiteSpace(namedQuery?.Name)) {
return { valid: false, message: 'Named Query name cannot be blank' };
}
// check that there is no other existing named query with the same name
const duplicate = this.getNamedQueries().find((q) => q.Name === namedQuery.Name && q.Uuid !== namedQuery.Uuid);
if (duplicate) {
return {
valid: false,
message: 'A Named Query already exists with that name',
};
}
return { valid: true, message: '' };
}
openNamedQuerySettingsPanel() {
this.showModulePopup(ModuleConstants.NamedQueryModuleId);
}
runNamedQuery(namedQuery) {
this.getGridFilterApi().setGridFilterExpression(namedQuery.Name);
}
runQueryByName(queryName) {
const namedQuery = this.getNamedQueryByName(queryName);
if (namedQuery) {
this.runNamedQuery(namedQuery);
}
}
}