[ACS-9119] Fixed textOrientation getting reset on arabic after browser refresh (#10591)

* [ACS-9119] Fixed issue where hitting browser refresh on arabic language changes the direction from rtl to ltr

* [ACS-9119] Added unit test

* [ACS-9119] Fixed UI issue in sidenav where incorrect margin-right was set when switching window sizes

* [ACS-9119] Addressed PR comments

* [ACS-9119] Fixed sonar issue

* [ACS-9119] Added margin-right 0 to mat-sidenav-content
This commit is contained in:
swapnil-verma-gl
2025-01-31 13:49:44 +05:30
committed by GitHub
parent 4124a49f41
commit 3b95e4ab25
7 changed files with 65 additions and 30 deletions

View File

@@ -30,6 +30,7 @@ export * from './services/url.service';
export * from './models/log-levels.model';
export * from './models/user-info-mode.enum';
export * from './models/default-languages.model';
export * from './interface/search-component.interface';

View File

@@ -0,0 +1,38 @@
/*!
* @license
* Copyright © 2005-2024 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 { LanguageItem } from '../services/language-item.interface';
export const DEFAULT_LANGUAGE_LIST: LanguageItem[] = [
{ key: 'de', label: 'Deutsch' },
{ key: 'en', label: 'English' },
{ key: 'es', label: 'Español' },
{ key: 'fr', label: 'Français' },
{ key: 'it', label: 'Italiano' },
{ key: 'ja', label: '日本語' },
{ key: 'nb', label: 'Bokmål' },
{ key: 'nl', label: 'Nederlands' },
{ key: 'pt-BR', label: 'Português (Brasil)' },
{ key: 'ru', label: 'Русский' },
{ key: 'zh-CN', label: '中文简体' },
{ key: 'cs', label: 'Čeština' },
{ key: 'da', label: 'Dansk' },
{ key: 'fi', label: 'Suomi' },
{ key: 'pl', label: 'Polski' },
{ key: 'sv', label: 'Svenska' },
{ key: 'ar', label: 'العربية', direction: 'rtl' }
];

View File

@@ -193,6 +193,19 @@ describe('UserPreferencesService', () => {
expect(storage.getItem(textOrientation)).toBe('rtl');
});
it('should set direction from default languages when language config is not present', () => {
appConfig.config.languages = [
{
key: 'fake-locale-config',
direction: 'ltr'
}
];
appConfig.config.locale = 'ar';
appConfig.load();
const textOrientation = preferences.getPropertyKey('textOrientation');
expect(storage.getItem(textOrientation)).toBe('rtl');
});
it('should not store textOrientation based on language ', () => {
appConfig.config.languages = [
{

View File

@@ -24,6 +24,7 @@ import { distinctUntilChanged, map } from 'rxjs/operators';
import { LanguageItem } from './language-item.interface';
import { DOCUMENT } from '@angular/common';
import { Directionality, Direction } from '@angular/cdk/bidi';
import { DEFAULT_LANGUAGE_LIST } from '../models/default-languages.model';
// eslint-disable-next-line no-shadow
export enum UserPreferenceValues {
@@ -246,11 +247,13 @@ export class UserPreferencesService {
private getLanguageByKey(key: string): LanguageItem {
const defaultLanguage = { key: 'en' } as LanguageItem;
let language: LanguageItem;
const registeredLanguages = this.appConfig.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY);
if (registeredLanguages && Array.isArray(registeredLanguages)) {
return registeredLanguages.find((language) => key.includes(language.key)) || defaultLanguage;
const customLanguages = this.appConfig.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY);
if (Array.isArray(customLanguages)) {
language = customLanguages.find((customLanguage) => key.includes(customLanguage.key));
}
return defaultLanguage;
language ??= DEFAULT_LANGUAGE_LIST.find((defaultLang) => defaultLang.key === key) ?? defaultLanguage;
return language;
}
}

View File

@@ -21,36 +21,15 @@ import { BehaviorSubject } from 'rxjs';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { LanguageItem } from '../../common/services/language-item.interface';
import { UserPreferencesService } from '../../common/services/user-preferences.service';
import { DEFAULT_LANGUAGE_LIST } from '../../common/models/default-languages.model';
@Injectable({providedIn: 'root'})
@Injectable({ providedIn: 'root' })
export class LanguageService implements LanguageServiceInterface {
private languages = new BehaviorSubject<LanguageItem[]>([
{key: 'de', label: 'Deutsch'},
{key: 'en', label: 'English'},
{key: 'es', label: 'Español'},
{key: 'fr', label: 'Français'},
{key: 'it', label: 'Italiano'},
{key: 'ja', label: '日本語'},
{key: 'nb', label: 'Bokmål'},
{key: 'nl', label: 'Nederlands'},
{key: 'pt-BR', label: 'Português (Brasil)'},
{key: 'ru', label: 'Русский'},
{key: 'zh-CN', label: '中文简体'},
{key: 'cs', label: 'Čeština'},
{key: 'da', label: 'Dansk'},
{key: 'fi', label: 'Suomi'},
{key: 'pl', label: 'Polski'},
{key: 'sv', label: 'Svenska'},
{key: 'ar', label: 'العربية', direction: 'rtl'}
]);
private languages = new BehaviorSubject<LanguageItem[]>(DEFAULT_LANGUAGE_LIST);
languages$ = this.languages.asObservable();
constructor(
appConfigService: AppConfigService,
private userPreferencesService: UserPreferencesService) {
constructor(appConfigService: AppConfigService, private readonly userPreferencesService: UserPreferencesService) {
const customLanguages = appConfigService.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY);
this.setLanguages(customLanguages);
}

View File

@@ -1,4 +1,4 @@
<mat-sidenav-container class="adf-layout-container">
<mat-sidenav-container class="adf-layout-container" autosize>
<mat-sidenav
class="adf-layout-container-sidenav"
[position]="position"

View File

@@ -37,6 +37,7 @@ adf-layout-container {
#{$mat-sidenav-content},
#{$mat-drawer-transition} #{$mat-drawer-content} {
margin-left: 0 !important;
margin-right: 0 !important;
transform: unset !important;
transition-property: unset !important;
transition-duration: unset !important;