[AAE-19610] Add specific date range settings to search filter (#9250)

* [AAE-19610] add specific date range settings to search filter

* [AAE-19610] remove unnecessary properties

* [AAE-19610] fix missing property bug

* [AAE-19610] fix lint issues
This commit is contained in:
Diogo Bastos
2024-01-18 15:01:20 +00:00
committed by GitHub
parent b46d468f76
commit e1fcaed12d
9 changed files with 171 additions and 5 deletions

View File

@@ -32,6 +32,11 @@ describe('ContentNodeSelectorPanelService', () => {
expect(contentNodeSelectorPanelService.isTypeSupported('d:date')).toEqual(true); expect(contentNodeSelectorPanelService.isTypeSupported('d:date')).toEqual(true);
}); });
it('should support datetime type', () => {
expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap.get('d:datetime')).toEqual('datetime-range');
expect(contentNodeSelectorPanelService.isTypeSupported('d:datetime')).toEqual(true);
});
it('should return false for an unsupported type', () => { it('should return false for an unsupported type', () => {
expect(contentNodeSelectorPanelService.isTypeSupported('d:unsupported')).toEqual(false); expect(contentNodeSelectorPanelService.isTypeSupported('d:unsupported')).toEqual(false);
}); });

View File

@@ -0,0 +1,69 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { SearchCategory } from '../search/models/search-category.interface';
export const mockSearchFilterWithoutDisplayedLabelsByField: SearchCategory = {
id : 'test',
name: 'test',
expanded: false,
enabled: true,
component: {
selector: 'date-range',
settings: {
pattern: `test:'(.*?)'`,
field: 'test',
placeholder: 'test placeholder'
}
}
};
export const mockSearchFilterWithWrongDisplayedLabelsByField: SearchCategory = {
id : 'test',
name: 'test',
expanded: false,
enabled: true,
component: {
selector: 'date-range',
settings: {
pattern: `test:'(.*?)'`,
field: 'test',
placeholder: 'test placeholder',
displayedLabelsByField: {
'wrong-test': 'test-tab-label'
}
}
}
};
export const mockSearchFilterWithDisplayedLabelsByField: SearchCategory = {
id : 'test',
name: 'test',
expanded: false,
enabled: true,
component: {
selector: 'date-range',
settings: {
pattern: `test:'(.*?)'`,
field: 'test',
placeholder: 'test placeholder',
displayedLabelsByField: {
'test': 'test-tab-label'
}
}
}
};

View File

@@ -23,3 +23,4 @@ export * from './search-filter-mock';
export * from './sites-dropdown.component.mock'; export * from './sites-dropdown.component.mock';
export * from './search-query.mock'; export * from './search-query.mock';
export * from './new-version-uploader.service.mock'; export * from './new-version-uploader.service.mock';
export * from './date-range-search-filter.mock';

View File

@@ -20,6 +20,7 @@ import { NgModule } from '@angular/core';
import { NodeNameTooltipPipe } from './node-name-tooltip.pipe'; import { NodeNameTooltipPipe } from './node-name-tooltip.pipe';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { IsIncludedPipe } from './is-included.pipe'; import { IsIncludedPipe } from './is-included.pipe';
import { TabLabelsPipe } from './tab-labels.pipe';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -28,15 +29,18 @@ import { IsIncludedPipe } from './is-included.pipe';
], ],
declarations: [ declarations: [
NodeNameTooltipPipe, NodeNameTooltipPipe,
IsIncludedPipe IsIncludedPipe,
TabLabelsPipe
], ],
providers: [ providers: [
NodeNameTooltipPipe, NodeNameTooltipPipe,
IsIncludedPipe IsIncludedPipe,
TabLabelsPipe
], ],
exports: [ exports: [
NodeNameTooltipPipe, NodeNameTooltipPipe,
IsIncludedPipe IsIncludedPipe,
TabLabelsPipe
] ]
}) })
export class ContentPipeModule { export class ContentPipeModule {

View File

@@ -17,4 +17,5 @@
export * from './node-name-tooltip.pipe'; export * from './node-name-tooltip.pipe';
export * from './is-included.pipe'; export * from './is-included.pipe';
export * from './tab-labels.pipe';
export * from './content-pipe.module'; export * from './content-pipe.module';

View File

@@ -0,0 +1,43 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { TabLabelsPipe } from './tab-labels.pipe';
import {
mockSearchFilterWithoutDisplayedLabelsByField,
mockSearchFilterWithWrongDisplayedLabelsByField,
mockSearchFilterWithDisplayedLabelsByField
} from '../mock/date-range-search-filter.mock';
describe('TabLabelsPipe', () => {
const pipe = new TabLabelsPipe();
it('should default to field name when there are no settings available', () => {
expect(pipe.transform('test', null)).toBe('test');
});
it('should default to field name when settings do not contain "displayedLabelsByField" property', () => {
expect(pipe.transform('test', mockSearchFilterWithoutDisplayedLabelsByField.component.settings)).toBe('test');
});
it('should default to field name when settings with "displayedLabelsByField" property are available but do not contain field', () => {
expect(pipe.transform('test', mockSearchFilterWithWrongDisplayedLabelsByField.component.settings)).toBe('test');
});
it('should display correct label when settings with "displayedLabelsByField" property are available and do contain field', () => {
expect(pipe.transform('test', mockSearchFilterWithDisplayedLabelsByField.component.settings)).toBe('test-tab-label');
});
});

View File

@@ -0,0 +1,30 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Pipe, PipeTransform } from '@angular/core';
import { SearchWidgetSettings } from '../search/models/search-widget-settings.interface';
@Pipe({
name: 'tabLabels'
})
export class TabLabelsPipe implements PipeTransform {
transform(field: string, settings?: SearchWidgetSettings): string {
return settings && settings.displayedLabelsByField && settings.displayedLabelsByField[field] ? settings.displayedLabelsByField[field] : field;
}
}

View File

@@ -1,7 +1,7 @@
<adf-search-filter-tabbed> <adf-search-filter-tabbed>
<ng-container *ngFor="let field of fields"> <ng-container *ngFor="let field of fields">
<adf-search-date-range <adf-search-date-range
*adf-search-filter-tab="settings.displayedLabelsByField[field]" *adf-search-filter-tab="field | tabLabels: settings"
[dateFormat]="settings.dateFormat" [dateFormat]="settings.dateFormat"
[maxDate]="settings.maxDate" [maxDate]="settings.maxDate"
[field]="field" [field]="field"

View File

@@ -37,6 +37,8 @@ import {
subWeeks subWeeks
} from 'date-fns'; } from 'date-fns';
const DEFAULT_DATE_DISPLAY_FORMAT = 'dd-MMM-yy';
@Component({ @Component({
selector: 'adf-search-date-range-tabbed', selector: 'adf-search-date-range-tabbed',
templateUrl: './search-date-range-tabbed.component.html', templateUrl: './search-date-range-tabbed.component.html',
@@ -67,6 +69,13 @@ export class SearchDateRangeTabbedComponent implements SearchWidget, OnInit {
ngOnInit(): void { ngOnInit(): void {
this.fields = this.settings?.field.split(',').map(field => field.trim()); this.fields = this.settings?.field.split(',').map(field => field.trim());
this.setDefaultDateFormatSettings();
}
private setDefaultDateFormatSettings() {
if (this.settings && !this.settings.dateFormat) {
this.settings.dateFormat = DEFAULT_DATE_DISPLAY_FORMAT;
}
} }
getCurrentValue(): { [key: string]: Partial<SearchDateRange> } { getCurrentValue(): { [key: string]: Partial<SearchDateRange> } {
@@ -163,9 +172,13 @@ export class SearchDateRangeTabbedComponent implements SearchWidget, OnInit {
this.displayValueMapByField.set(field, this.generateDisplayValue(value)); this.displayValueMapByField.set(field, this.generateDisplayValue(value));
this.displayValueMapByField.forEach((displayValue: string, fieldForDisplayLabel: string) => { this.displayValueMapByField.forEach((displayValue: string, fieldForDisplayLabel: string) => {
if (displayValue) { if (displayValue) {
const displayLabelForField = `${this.translateService.instant(this.settings.displayedLabelsByField[fieldForDisplayLabel]).toUpperCase()}: ${displayValue}`; const displayLabelForField = `${this.translateService.instant(this.getDisplayLabelForField(fieldForDisplayLabel)).toUpperCase()}: ${displayValue}`;
this.combinedDisplayValue = this.combinedDisplayValue ? `${this.combinedDisplayValue} ${displayLabelForField}` : `${displayLabelForField}`; this.combinedDisplayValue = this.combinedDisplayValue ? `${this.combinedDisplayValue} ${displayLabelForField}` : `${displayLabelForField}`;
} }
}); });
} }
private getDisplayLabelForField(fieldForDisplayLabel: string): string {
return this.settings && this.settings.displayedLabelsByField && this.settings.displayedLabelsByField[fieldForDisplayLabel] ? this.settings.displayedLabelsByField[fieldForDisplayLabel] : fieldForDisplayLabel;
}
} }