Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private onDateExpressionChange(newValue: string): string {
// Validates the picker
let regex = new RegExp(/^\[Today\](\s{0,}[\+-]\s{0,}\[{0,1}\d{1,4}\]{0,1}){0,1}$/);
let isValid = regex.test(newValue) || isEmpty(newValue);
let errorMsg = isValid ? '' : this.props.strings.datePickerExpressionError;
if(isValid) {
// If the change is NOT triggered by the date picker change
if(!(isEmpty(newValue) && this.state.filter.value != null)) {
this.state.filter.value = null;
this.state.filter.expression = newValue;
this.setState({ filter: this.state.filter, pickersKey: this.state.pickersKey });
this.onAnyChange();
}
}
return errorMsg;
}
return (
<div>
{loading}
{error}
{/* Shows the validation checklist if mandatory properties aren't all configured */}
{ !mandatoryFieldsConfigured && !this.state.loading && !this.state.error &&
<div>
{ this.props.strings.mandatoryProperties }
</div>
}
{/* Shows the query results once loaded */}
{ mandatoryFieldsConfigured && !this.state.loading && !this.state.error &&
<div></div>
}
</div>
);
}
}
private isFilterEmpty(filter:IQueryFilter) {
let isFilterEmpty = false;
// If the filter has no field
if(filter.field == null) {
isFilterEmpty = true;
}
// If the filter has a null or empty value
if(filter.value == null || isEmpty(filter.value.toString())) {
// And has no date time expression
if(isEmpty(filter.expression)) {
// And isn't a [Me] switch
if(!filter.me) {
// And isn't a or operator
if(filter.operator != QueryFilterOperator.IsNull && filter.operator != QueryFilterOperator.IsNotNull) {
isFilterEmpty = true;
}
}
}
}
return isFilterEmpty;
}
const mandatoryFieldsConfigured = this.areMandatoryFieldsConfigured();
return (
<div>
{loading}
{error}
{/* Shows the validation checklist if mandatory properties aren't all configured */}
{ !mandatoryFieldsConfigured && !this.state.loading && !this.state.error &&
<div>
{ this.props.strings.mandatoryProperties }
</div>
}
{/* Shows the query results once loaded */}
{ mandatoryFieldsConfigured && !this.state.loading && !this.state.error &&
<div></div>
}
</div>
);
}
}
public getFilterFields(webUrl: string, listId: string):Promise {
Log.verbose(this.logSource, "Loading dropdown options for toolpart property 'Filters'...", this.context.serviceScope);
// Resolves an empty array if no web or no list has been selected
if (isEmpty(webUrl) || isEmpty(listId)) {
return Promise.resolve(new Array());
}
// Resolves the already loaded data if available
if(this.filterFields) {
return Promise.resolve(this.filterFields);
}
// Otherwise gets the options asynchronously
return new Promise((resolve, reject) => {
this.listService.getListFields(webUrl, listId, ['InternalName', 'Title', 'TypeAsString'], 'Title').then((data:any) => {
let fields:any[] = data.value;
let options:IQueryFilterField[] = fields.map((field) => { return {
internalName: field.InternalName,
displayName: field.Title,
type: this.getFieldTypeFromString(field.TypeAsString)
private resetWebUrlPropertyPane() {
Log.verbose(this.logSource, "Resetting 'webUrl' property...", this.context.serviceScope);
this.properties.webUrl = "";
this.ContentQueryService.clearCachedWebUrlOptions();
update(this.properties, ContentQueryConstants.propertyWebUrl, (): any => { return this.properties.webUrl; });
this.webUrlDropdown.properties.selectedKey = "";
this.webUrlDropdown.properties.disabled = isEmpty(this.properties.siteUrl);
this.webUrlDropdown.render();
}
private static formatFilterValue(filter:IQueryFilter): string
{
let filterValue = "";
if(filter.field.type == QueryFilterFieldType.Datetime) {
if(filter.expression != null && !isEmpty(filter.expression)) {
filterValue = this.formatDateExpressionFilterValue(filter.expression);
}
else {
filterValue = this.formatDateFilterValue(filter.value as string);
}
}
else {
filterValue = this.formatTextFilterValue(filter.value as string);
}
return filterValue;
}
private resetListTitlePropertyPane() {
Log.verbose(this.logSource, "Resetting 'listTitle' property...", this.context.serviceScope);
this.properties.listId = null;
this.ContentQueryService.clearCachedListTitleOptions();
update(this.properties, ContentQueryConstants.propertyListId, (): any => { return this.properties.listId; });
this.listTitleDropdown.properties.selectedKey = "";
this.listTitleDropdown.properties.disabled = isEmpty(this.properties.webUrl);
this.listTitleDropdown.render();
}
private areMandatoryFieldsConfigured(): boolean {
return !isEmpty(this.props.siteUrl) &&
!isEmpty(this.props.querySettings.webUrl) &&
!isEmpty(this.props.querySettings.listId) &&
!isEmpty(this.props.querySettings.viewFields) &&
(!isEmpty(this.props.templateUrl) || !isEmpty(this.props.templateText));
}
private resetFiltersPropertyPane() {
Log.verbose(this.logSource, "Resetting 'filters' property...", this.context.serviceScope);
this.properties.filters = null;
this.ContentQueryService.clearCachedFilterFields();
update(this.properties, ContentQueryConstants.propertyFilters, (): any => { return this.properties.filters; });
this.filtersPanel.properties.filters = null;
this.filtersPanel.properties.disabled = isEmpty(this.properties.webUrl) || isEmpty(this.properties.listId);
this.filtersPanel.render();
}