From e1fcaed12deffbf651d4bbd25ff4c26f8c82e30a Mon Sep 17 00:00:00 2001 From: Diogo Bastos <50139916+DiogoABastos@users.noreply.github.com> Date: Thu, 18 Jan 2024 15:01:20 +0000 Subject: [PATCH] [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 --- ...ontent-node-selector-panel.service.spec.ts | 5 ++ .../lib/mock/date-range-search-filter.mock.ts | 69 +++++++++++++++++++ .../src/lib/mock/public-api.ts | 1 + .../src/lib/pipes/content-pipe.module.ts | 10 ++- .../src/lib/pipes/public-api.ts | 1 + .../src/lib/pipes/tab-labels.pipe.spec.ts | 43 ++++++++++++ .../src/lib/pipes/tab-labels.pipe.ts | 30 ++++++++ .../search-date-range-tabbed.component.html | 2 +- .../search-date-range-tabbed.component.ts | 15 +++- 9 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 lib/content-services/src/lib/mock/date-range-search-filter.mock.ts create mode 100644 lib/content-services/src/lib/pipes/tab-labels.pipe.spec.ts create mode 100644 lib/content-services/src/lib/pipes/tab-labels.pipe.ts diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.spec.ts index 5186a5d30b..5c2c3314ed 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.spec.ts @@ -32,6 +32,11 @@ describe('ContentNodeSelectorPanelService', () => { 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', () => { expect(contentNodeSelectorPanelService.isTypeSupported('d:unsupported')).toEqual(false); }); diff --git a/lib/content-services/src/lib/mock/date-range-search-filter.mock.ts b/lib/content-services/src/lib/mock/date-range-search-filter.mock.ts new file mode 100644 index 0000000000..654ed5d6c4 --- /dev/null +++ b/lib/content-services/src/lib/mock/date-range-search-filter.mock.ts @@ -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' + } + } + } +}; diff --git a/lib/content-services/src/lib/mock/public-api.ts b/lib/content-services/src/lib/mock/public-api.ts index 50ce677096..5c8ae7df9c 100644 --- a/lib/content-services/src/lib/mock/public-api.ts +++ b/lib/content-services/src/lib/mock/public-api.ts @@ -23,3 +23,4 @@ export * from './search-filter-mock'; export * from './sites-dropdown.component.mock'; export * from './search-query.mock'; export * from './new-version-uploader.service.mock'; +export * from './date-range-search-filter.mock'; diff --git a/lib/content-services/src/lib/pipes/content-pipe.module.ts b/lib/content-services/src/lib/pipes/content-pipe.module.ts index 37eae541b2..e1e90e248a 100644 --- a/lib/content-services/src/lib/pipes/content-pipe.module.ts +++ b/lib/content-services/src/lib/pipes/content-pipe.module.ts @@ -20,6 +20,7 @@ import { NgModule } from '@angular/core'; import { NodeNameTooltipPipe } from './node-name-tooltip.pipe'; import { TranslateModule } from '@ngx-translate/core'; import { IsIncludedPipe } from './is-included.pipe'; +import { TabLabelsPipe } from './tab-labels.pipe'; @NgModule({ imports: [ @@ -28,15 +29,18 @@ import { IsIncludedPipe } from './is-included.pipe'; ], declarations: [ NodeNameTooltipPipe, - IsIncludedPipe + IsIncludedPipe, + TabLabelsPipe ], providers: [ NodeNameTooltipPipe, - IsIncludedPipe + IsIncludedPipe, + TabLabelsPipe ], exports: [ NodeNameTooltipPipe, - IsIncludedPipe + IsIncludedPipe, + TabLabelsPipe ] }) export class ContentPipeModule { diff --git a/lib/content-services/src/lib/pipes/public-api.ts b/lib/content-services/src/lib/pipes/public-api.ts index 2ab199eee7..9cb65d79eb 100644 --- a/lib/content-services/src/lib/pipes/public-api.ts +++ b/lib/content-services/src/lib/pipes/public-api.ts @@ -17,4 +17,5 @@ export * from './node-name-tooltip.pipe'; export * from './is-included.pipe'; +export * from './tab-labels.pipe'; export * from './content-pipe.module'; diff --git a/lib/content-services/src/lib/pipes/tab-labels.pipe.spec.ts b/lib/content-services/src/lib/pipes/tab-labels.pipe.spec.ts new file mode 100644 index 0000000000..a79f24b460 --- /dev/null +++ b/lib/content-services/src/lib/pipes/tab-labels.pipe.spec.ts @@ -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'); + }); +}); diff --git a/lib/content-services/src/lib/pipes/tab-labels.pipe.ts b/lib/content-services/src/lib/pipes/tab-labels.pipe.ts new file mode 100644 index 0000000000..cae67a20ce --- /dev/null +++ b/lib/content-services/src/lib/pipes/tab-labels.pipe.ts @@ -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; + } + +} diff --git a/lib/content-services/src/lib/search/components/search-date-range-tabbed/search-date-range-tabbed.component.html b/lib/content-services/src/lib/search/components/search-date-range-tabbed/search-date-range-tabbed.component.html index e60cb73b47..5602184528 100644 --- a/lib/content-services/src/lib/search/components/search-date-range-tabbed/search-date-range-tabbed.component.html +++ b/lib/content-services/src/lib/search/components/search-date-range-tabbed/search-date-range-tabbed.component.html @@ -1,7 +1,7 @@ field.trim()); + this.setDefaultDateFormatSettings(); + } + + private setDefaultDateFormatSettings() { + if (this.settings && !this.settings.dateFormat) { + this.settings.dateFormat = DEFAULT_DATE_DISPLAY_FORMAT; + } } getCurrentValue(): { [key: string]: Partial } { @@ -163,9 +172,13 @@ export class SearchDateRangeTabbedComponent implements SearchWidget, OnInit { this.displayValueMapByField.set(field, this.generateDisplayValue(value)); this.displayValueMapByField.forEach((displayValue: string, fieldForDisplayLabel: string) => { 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}`; } }); } + + private getDisplayLabelForField(fieldForDisplayLabel: string): string { + return this.settings && this.settings.displayedLabelsByField && this.settings.displayedLabelsByField[fieldForDisplayLabel] ? this.settings.displayedLabelsByField[fieldForDisplayLabel] : fieldForDisplayLabel; + } }