Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove core lib & migrate to cdk #500

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion javascript/apps/taiga-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"types": ["cypress", "cypress-axe"],
"paths": {
"@taiga/api": ["libs/api/src/index.ts"],
"@taiga/core": ["libs/core/src/index.ts"],
"@taiga/cdk/*": ["libs/cdk/src/lib/*"],
"@taiga/data": ["libs/data/src/index.ts"],
"@taiga/ui/*": ["libs/ui/src/lib/*"],
"@test/*": ["apps/taiga-e2e/src/*"],
Expand Down
5 changes: 2 additions & 3 deletions javascript/apps/taiga/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { TranslocoService } from '@ngneat/transloco';
import { concatLatestFrom } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { selectLanguages } from '@taiga/core';
import { User } from '@taiga/data';
import { Observable, of } from 'rxjs';
import { filter, map, share, switchMap } from 'rxjs/operators';
Expand All @@ -23,7 +22,7 @@ import { LocalStorageService } from './shared/local-storage/local-storage.servic
import { RouteHistoryService } from './shared/route-history/route-history.service';
import { InputModalityDetector } from '@angular/cdk/a11y';
import { LanguageService } from './services/language/language.service';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
Expand Down Expand Up @@ -127,7 +126,7 @@ export class AppComponent {
}
return of({ userLang: user.lang, anonymous: false });
}),
concatLatestFrom(() => [this.store.select(selectLanguages)])
concatLatestFrom(() => [this.languageService.getLanguages()])
)
.subscribe(([user, languages]) => {
const lang = languages.find((it) => it.code === user.userLang);
Expand Down
8 changes: 4 additions & 4 deletions javascript/apps/taiga/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { TUI_LANGUAGE } from '@taiga-ui/i18n';
import { tuiToggleOptionsProvider } from '@taiga-ui/kit';
import { SystemApiService } from '@taiga/api';
import { ConfigService, CoreModule, coreActions } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { PROMPT_PROVIDER } from '@taiga/ui/modal/services/modal.service';
import { paramCase } from 'change-case';
import { DataAccessAuthModule } from '~/app/modules/auth/data-access/auth.module';
Expand Down Expand Up @@ -72,7 +72,6 @@ export function prefersReducedMotion(): boolean {
imports: [
DataAccessAuthModule,
ErrorsModule,
CoreModule,
HttpClientModule,
ApiRestInterceptorModule,
NavigationModule,
Expand Down Expand Up @@ -119,14 +118,15 @@ export function prefersReducedMotion(): boolean {
EnvironmentService,
TranslocoService,
SystemApiService,
LanguageService,
Store,
],
useFactory: (
appConfigService: ConfigService,
environmentService: EnvironmentService,
translocoService: TranslocoService,
systemApiService: SystemApiService,
store: Store
languageService: LanguageService
) => {
return () => {
return new Promise((resolve) => {
Expand All @@ -148,7 +148,7 @@ export function prefersReducedMotion(): boolean {
}

systemApiService.getLanguages().subscribe((langs) => {
store.dispatch(coreActions.setLanguages({ languages: langs }));
languageService.setLanguages(langs);
const availableCodes = langs.map((lang) => lang.code);
const defaultLang = langs.find((lang) => lang.isDefault);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { randBoolean, randUrl, randUuid } from '@ngneat/falso';
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import { ConfigService, ConfigServiceMock } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { ConfigServiceMock } from '@taiga/cdk/services/config/config.service.mock';
import { getTranslocoModule } from '~/app/transloco/transloco-testing.module';
import { SocialLoginButtonComponent } from './social-login-button.component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
TranslocoService,
TRANSLOCO_SCOPE,
} from '@ngneat/transloco';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';

interface SocialParams {
social: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TranslocoModule, TRANSLOCO_SCOPE } from '@ngneat/transloco';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';

import { SocialLoginButtonComponent } from '../social-login-button/social-login-button.component';
import { ContextNotificationComponent } from '@taiga/ui/context-notification/context-notification.component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ActivatedRouteSnapshot, CanActivateFn, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TuiNotification } from '@taiga-ui/core';
import { ProjectApiService, UsersApiService } from '@taiga/api';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import {
Auth,
ProjectInvitationInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { AuthApiService } from '@taiga/api';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { Auth, User } from '@taiga/data';
import { WsService } from '~/app/services/ws';
import { LocalStorageService } from '~/app/shared/local-storage/local-storage.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Component } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { TuiButtonModule } from '@taiga-ui/core';
import { TranslocoDirective } from '@ngneat/transloco';
import { CommonModule } from '@angular/common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Component } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { TuiButtonModule } from '@taiga-ui/core';
import { TranslocoDirective } from '@ngneat/transloco';
import { CommonModule } from '@angular/common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Component } from '@angular/core';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { Router, RouterLink } from '@angular/router';
import { TuiButtonModule } from '@taiga-ui/core';
import { TranslocoDirective } from '@ngneat/transloco';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { provideMockActions } from '@ngrx/effects/testing';
import { Action } from '@ngrx/store';
import { UsersApiService } from '@taiga/api';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { AppService } from '~/app/services/app.service';

import {
Expand All @@ -27,11 +27,11 @@ import {
import { UserSettingsEffects } from './user-settings.effects';

import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { selectLanguages } from '@taiga/core';
import { selectUser } from '~/app/modules/auth/data-access/+state/selectors/auth.selectors';
import { AuthService } from '~/app/modules/auth/services/auth.service';
import { HttpErrorResponse } from '@angular/common/http';
import { unexpectedError } from '~/app/modules/errors/+state/actions/errors.actions';
import { LanguageService } from '~/app/services/language/language.service';

describe('UserSettingsEffects', () => {
let actions$: Observable<Action>;
Expand All @@ -44,7 +44,7 @@ describe('UserSettingsEffects', () => {
provideMockActions(() => actions$),
provideMockStore({ initialState: {} }),
],
mocks: [UsersApiService, AppService, AuthService],
mocks: [UsersApiService, AppService, AuthService, LanguageService],
});

beforeEach(() => {
Expand All @@ -55,8 +55,9 @@ describe('UserSettingsEffects', () => {
it('load languages', () => {
const languages = LanguageListMockFactory();
const effects = spectator.inject(UserSettingsEffects);
const languageService = spectator.inject(LanguageService);

store.overrideSelector(selectLanguages, languages);
languageService.getLanguages.mockReturnValue(of(languages));

actions$ = hot('-a', { a: userSettingsActions.initPreferences() });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import { TuiNotification } from '@taiga-ui/core';
import { AuthService } from '~/app/modules/auth/services/auth.service';
import { selectUser } from '~/app/modules/auth/data-access/+state/selectors/auth.selectors';
import { filterNil } from '~/app/shared/utils/operators';
import { selectLanguages } from '@taiga/core';
import { Router } from '@angular/router';
import { LanguageService } from '~/app/services/language/language.service';

@Injectable()
export class UserSettingsEffects {
public loadLanguages$ = createEffect(() => {
return this.actions$.pipe(
ofType(userSettingsActions.initPreferences),
concatLatestFrom(() => [this.store.select(selectLanguages)]),
concatLatestFrom(() => [this.languageService.getLanguages()]),
fetch({
run: (_, languages) => {
return userSettingsApiActions.fetchLanguagesSuccess({
Expand Down Expand Up @@ -153,6 +153,7 @@ export class UserSettingsEffects {
private appService: AppService,
private actions$: Actions,
private usersApiService: UsersApiService,
private router: Router
private router: Router,
private languageService: LanguageService
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
TuiSvgModule,
} from '@taiga-ui/core';
import { TuiToggleModule } from '@taiga-ui/kit';
import { ShortcutsService } from '@taiga/core';
import { ShortcutsService } from '@taiga/cdk/services/shortcuts';
import { Membership, Permissions, Story, User } from '@taiga/data';
import { InputsModule } from '@taiga/ui/inputs';
import { TooltipDirective } from '@taiga/ui/tooltip';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivateFn, Router } from '@angular/router';
import { TuiNotification } from '@taiga-ui/core';
import { ProjectApiService } from '@taiga/api';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { ProjectInvitationInfo, Project } from '@taiga/data';
import { of } from 'rxjs';
import { catchError, map, mergeMap } from 'rxjs/operators';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { randUuid } from '@ngneat/falso';

import { mockProvider, SpyObject } from '@ngneat/spectator/jest';
import { ProjectApiService } from '@taiga/api';
import { ConfigService, ConfigServiceMock } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { ConfigServiceMock } from '@taiga/cdk/services/config/config.service.mock';
import { InvitationInfoMockFactory, ProjectMockFactory } from '@taiga/data';
import { of } from 'rxjs';
import { AuthService } from '~/app/modules/auth/services/auth.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { TuiNotification } from '@taiga-ui/core';
import { ProjectApiService } from '@taiga/api';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { ProjectInvitationInfo } from '@taiga/data';
import { EMPTY, of, throwError } from 'rxjs';
import { catchError, mergeMap, tap } from 'rxjs/operators';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { concatLatestFrom } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { RxState } from '@rx-angular/state';
import { TuiNotification } from '@taiga-ui/core';
import { ShortcutsService } from '@taiga/core';
import { ShortcutsService } from '@taiga/cdk/services/shortcuts';
import {
Membership,
Permissions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@angular/core';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { Store } from '@ngrx/store';
import { ShortcutsService } from '@taiga/core';
import { ShortcutsService } from '@taiga/cdk/services/shortcuts';
import { Membership, Project, Role, User } from '@taiga/data';
import { finalize } from 'rxjs';
import { A11yModule } from '@angular/cdk/a11y';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from '@angular/forms';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { RxState } from '@rx-angular/state';
import { ShortcutsService } from '@taiga/core';
import { ShortcutsService } from '@taiga/cdk/services/shortcuts';
import { StoryDetailForm } from '~/app/modules/project/story-detail/story-detail.component';
import {
StoryTitleMaxLength,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { HttpClient } from '@angular/common/http';
import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivateFn, Router } from '@angular/router';
import { TuiNotification } from '@taiga-ui/core';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import {
WorkspaceInvitationInfo,
InvitationWorkspaceMember,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
*/

import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { selectLanguages } from '@taiga/core';
import { provideMockStore } from '@ngrx/store/testing';
import { LanguageListMockFactory } from '@taiga/data';
import { LanguageService } from './language.service';

describe('LanguageService', () => {
let spectator: SpectatorService<LanguageService>;

let store: MockStore;

const createService = createServiceFactory({
service: LanguageService,
providers: [provideMockStore({})],
Expand All @@ -25,14 +22,13 @@ describe('LanguageService', () => {

beforeEach(() => {
spectator = createService();
store = spectator.inject(MockStore);
});

describe('get user registration language', () => {
it('user language es-ES', (done) => {
spectator.service.navigatorLanguage = jest.fn().mockReturnValue('es-ES');

store.overrideSelector(selectLanguages, LanguageListMockFactory());
spectator.service.setLanguages(LanguageListMockFactory());

spectator.service.getUserLanguage().subscribe((lang) => {
expect(lang.code).toBe('es-ES');
Expand All @@ -43,7 +39,7 @@ describe('LanguageService', () => {
it('not available language', (done) => {
spectator.service.navigatorLanguage = jest.fn().mockReturnValue('xx-XX');

store.overrideSelector(selectLanguages, LanguageListMockFactory());
spectator.service.setLanguages(LanguageListMockFactory());

spectator.service.getUserLanguage().subscribe((lang) => {
expect(lang.code).toBe('en-US');
Expand All @@ -54,7 +50,7 @@ describe('LanguageService', () => {
it('skip locale if not available', (done) => {
spectator.service.navigatorLanguage = jest.fn().mockReturnValue('es-MX');

store.overrideSelector(selectLanguages, LanguageListMockFactory());
spectator.service.setLanguages(LanguageListMockFactory());

spectator.service.getUserLanguage().subscribe((lang) => {
expect(lang.code).toBe('es-ES');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,35 @@

import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { selectLanguages } from '@taiga/core';
import { filter, map, switchMap, take } from 'rxjs';
import { BehaviorSubject, filter, map, switchMap, take } from 'rxjs';
import { selectUser } from '~/app/modules/auth/data-access/+state/selectors/auth.selectors';
import { TuiLanguage } from '@taiga-ui/i18n';
import { TUI_ENGLISH_LANGUAGE, TUI_SPANISH_LANGUAGE } from '@taiga-ui/i18n';
import editorLanguages from '~/assets/editor/languages.json';
import { LocalStorageService } from '~/app/shared/local-storage/local-storage.service';
import { Language } from '@taiga/data';

@Injectable({
providedIn: 'root',
})
export class LanguageService {
#languages = new BehaviorSubject<Language[]>([]);

constructor(private store: Store) {}
public navigatorLanguage() {
return navigator.language;
}

public setLanguages(languages: Language[]) {
this.#languages.next(languages);
}

public getLanguages() {
return this.#languages.asObservable();
}

public getUserLanguage() {
return this.store.select(selectLanguages).pipe(
return this.getLanguages().pipe(
filter((langs) => !!langs.length),
take(1),
switchMap((langs) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { WsService } from '../services/ws.service';
import { wsMessage } from '../ws.actions';
import { ConfigService } from '@taiga/core';
import { ConfigService } from '@taiga/cdk/services/config';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator';
import { createEffect } from '@ngrx/effects';
import { provideMockActions } from '@ngrx/effects/testing';
Expand Down
Loading