Skip to content

Commit

Permalink
Merge pull request #8612 from ever-co/fix/ui-core-circular-dependency
Browse files Browse the repository at this point in the history
[Fix] UI Core Circular Dependency
  • Loading branch information
rahul-rocket authored Dec 23, 2024
2 parents f056b6c + a513a21 commit 3c08f12
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import {
ToastrService
} from '@gauzy/ui-core/core';
import {
AddProjectModuleDialogComponent,
CardGridComponent,
ContactLinksComponent,
DateViewComponent,
DeleteConfirmationComponent,
EmployeesMergedTeamsComponent,
EmployeeWithLinksComponent,
PaginationFilterBaseComponent,
ProjectModuleMutationComponent,
ProjectOrganizationComponent,
ProjectOrganizationEmployeesComponent,
ProjectOrganizationGridComponent,
Expand Down Expand Up @@ -620,7 +620,7 @@ export class ProjectListComponent extends PaginationFilterBaseComponent implemen
public async createProjectModuleDialog(project: IOrganizationProject): Promise<void> {
try {
const result = await firstValueFrom(
this._dialogService.open(AddProjectModuleDialogComponent, {
this._dialogService.open(ProjectModuleMutationComponent, {
context: {
project,
createModule: true
Expand Down
6 changes: 3 additions & 3 deletions apps/gauzy/src/app/pages/projects/projects.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
CardGridModule,
EntityWithMembersModule,
ProjectMutationModule,
AddProjectModuleDialogModule
ProjectModuleMutationModule
} from '@gauzy/ui-core/shared';
import { ProjectsRoutingModule } from './projects-routing.module';
import { TableComponentsModule } from '@gauzy/ui-core/shared';
Expand All @@ -37,15 +37,15 @@ import { ProjectListComponent } from './components/project-list/list.component';
NbSpinnerModule,
NbTooltipModule,
TranslateModule.forChild(),
NgxPermissionsModule.forChild(),
ProjectsRoutingModule,
TableComponentsModule,
EntityWithMembersModule,
SharedModule,
SmartDataViewLayoutModule,
CardGridModule,
ProjectMutationModule,
AddProjectModuleDialogModule,
NgxPermissionsModule.forChild()
ProjectModuleMutationModule
],
declarations: [
ProjectLayoutComponent,
Expand Down
1 change: 1 addition & 0 deletions packages/ui-core/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export * from './lib/pipes';
export * from './lib/pipes/pipes.module';
export * from './lib/product';
export * from './lib/project';
export * from './lib/project-module';
export * from './lib/proposal-template-select';
export * from './lib/remove-lodash';
export * from './lib/regex';
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-core/shared/src/lib/project-module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './project-module-mutation/project-module-mutation.component';
export * from './project-module-mutation/project-module-mutation.module';
export * from './project-module-table/project-module-table.component';
export * from './project-module-table/project-module-table.module';
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ <h5 class="title">
</div>
</div>
</div>

<!-- Managers Selection -->
<div class="row">
<div class="col-sm-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CKEditor4 } from 'ckeditor4-angular/ckeditor';
import { firstValueFrom } from 'rxjs';
import { filter, tap } from 'rxjs/operators';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { distinctUntilChange } from '@gauzy/ui-core/common';
import {
IEmployee,
IOrganization,
Expand All @@ -20,7 +19,7 @@ import {
ID,
IOrganizationProjectModuleEmployee
} from '@gauzy/contracts';
import { TranslationBaseComponent } from '@gauzy/ui-core/i18n';
import { distinctUntilChange } from '@gauzy/ui-core/common';
import {
EmployeesService,
OrganizationTeamsService,
Expand All @@ -30,15 +29,16 @@ import {
TasksService,
ToastrService
} from '@gauzy/ui-core/core';
import { richTextCKEditorConfig } from '../../../ckeditor.config';
import { TranslationBaseComponent } from '@gauzy/ui-core/i18n';
import { richTextCKEditorConfig } from '../../ckeditor.config';

@UntilDestroy({ checkProperties: true })
@Component({
selector: 'ngx-add-module-dialog',
templateUrl: './add-project-module-dialog.component.html',
styleUrls: ['./add-project-module-dialog.component.scss']
selector: 'ngx-project-module-mutation',
templateUrl: './project-module-mutation.component.html',
styleUrl: './project-module-mutation.component.scss'
})
export class AddProjectModuleDialogComponent extends TranslationBaseComponent implements OnInit {
export class ProjectModuleMutationComponent extends TranslationBaseComponent implements OnInit {
memberIds: ID[] = [];
managerIds: ID[] = [];
selectedEmployeeIds: ID[] = [];
Expand Down Expand Up @@ -78,7 +78,6 @@ export class AddProjectModuleDialogComponent extends TranslationBaseComponent im
}
@Input() set projectModule(value: IOrganizationProjectModule) {
this._projectModule = value;

this.populateForm(value);
}

Expand All @@ -92,7 +91,7 @@ export class AddProjectModuleDialogComponent extends TranslationBaseComponent im
}

constructor(
public dialogRef: NbDialogRef<AddProjectModuleDialogComponent>,
public dialogRef: NbDialogRef<ProjectModuleMutationComponent>,
private fb: UntypedFormBuilder,
private store: Store,
public translateService: TranslateService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {
import { CKEditorModule } from 'ckeditor4-angular';
import { NgSelectModule } from '@ng-select/ng-select';
import { TranslateModule } from '@ngx-translate/core';
import { TaskSelectModule, TaskStatusSelectModule } from '../../../tasks';
import { ProjectSelectModule, SelectorsModule } from '../../../selectors';
import { TagsColorInputModule } from '../../../tags';
import { EmployeeMultiSelectModule } from '../../../employee';
import { AddProjectModuleDialogComponent } from './add-project-module-dialog.component';
import { TaskSelectModule, TaskStatusSelectModule } from '../../tasks';
import { ProjectSelectModule, SelectorsModule } from '../../selectors';
import { TagsColorInputModule } from '../../tags/tags-color-input/tags-color-input.module';
import { EmployeeMultiSelectModule } from '../../employee/employee-multi-select/employee-multi-select.module';
import { ProjectModuleMutationComponent } from './project-module-mutation.component';

@NgModule({
imports: [
Expand All @@ -47,7 +47,7 @@ import { AddProjectModuleDialogComponent } from './add-project-module-dialog.com
TaskSelectModule,
TaskStatusSelectModule
],
declarations: [AddProjectModuleDialogComponent],
exports: [AddProjectModuleDialogComponent]
declarations: [ProjectModuleMutationComponent],
exports: [ProjectModuleMutationComponent]
})
export class AddProjectModuleDialogModule {}
export class ProjectModuleMutationModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
[source]="smartTableSource"
style="cursor: pointer"
#variantTable
>
</angular2-smart-table>
></angular2-smart-table>
</div>
</div>

<!-- Actions -->
<ng-template #actionButtons>
<div class="actions">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
.transition-container span {
background-color: unset;
}

.actions-container {
padding-top: 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProjectModuleTableComponent } from './project-module-table.component';

describe('ProjectModuleTableComponent', () => {
let component: ProjectModuleTableComponent;
let fixture: ComponentFixture<ProjectModuleTableComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ProjectModuleTableComponent]
}).compileComponents();

fixture = TestBed.createComponent(ProjectModuleTableComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,66 +1,63 @@
import { Component, OnInit, Input } from '@angular/core';
import { first, firstValueFrom, tap } from 'rxjs';
import { NbDialogService } from '@nebular/theme';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { Cell, LocalDataSource } from 'angular2-smart-table';
import { TranslateService } from '@ngx-translate/core';
import { TranslationBaseComponent } from '@gauzy/ui-core/i18n';
import { ID, IEmployee, IOrganizationProjectModule, IOrganizationProjectModuleEmployee } from '@gauzy/contracts';
import { firstValueFrom } from 'rxjs';
import { first } from 'rxjs/operators';
import { NbDialogService } from '@nebular/theme';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { OrganizationProjectModuleService, ToastrService } from '@gauzy/ui-core/core';
import { TranslationBaseComponent } from '@gauzy/ui-core/i18n';
import {
StatusViewComponent,
ToggleSwitcherComponent,
DateViewComponent,
DeleteConfirmationComponent,
EmployeesMergedTeamsComponent,
EmployeeWithLinksComponent,
StatusViewComponent,
ToggleSwitcherComponent
} from '../../../../index';
import { AddProjectModuleDialogComponent } from '../add-project-module-dialog/add-project-module-dialog.component';
} from '../../table-components';
import { DeleteConfirmationComponent } from '../../user/forms/delete-confirmation/delete-confirmation.component';
import { ProjectModuleMutationComponent } from '../project-module-mutation/project-module-mutation.component';

@UntilDestroy()
@UntilDestroy({ checkProperties: true})
@Component({
selector: 'ngx-project-module-table',
templateUrl: './project-module-table.component.html',
styleUrls: ['./project-module-table.component.scss']
styleUrl: './project-module-table.component.scss'
})
export class ProjectModuleTableComponent extends TranslationBaseComponent implements OnInit {
private _projectId: ID;
public modules: IOrganizationProjectModule[] = [];
public selectedItem: IOrganizationProjectModule;
public settingsSmartTable: object;
public smartTableSource = new LocalDataSource();
public loading: boolean = true;
public disableButton: boolean = true;

/**
* Project ID to fetch modules for.
* Uses getter and setter to detect changes and reload data if needed.
*/
@Input()
private _projectId: ID;
get projectId(): ID {
return this._projectId;
}
set projectId(value: ID) {
@Input() set projectId(value: ID) {
if (value !== this._projectId) {
this._projectId = value;
this.loadModules();
}
}

modules: IOrganizationProjectModule[] = [];
selectedItem: IOrganizationProjectModule;
settingsSmartTable: object;
smartTableSource = new LocalDataSource();
loading = true;
disableButton = true;

constructor(
readonly translateService: TranslateService,
private dialogService: NbDialogService,
private toastrService: ToastrService,
private organizationProjectModuleService: OrganizationProjectModuleService
public readonly translateService: TranslateService,
private readonly dialogService: NbDialogService,
private readonly toastrService: ToastrService,
private readonly organizationProjectModuleService: OrganizationProjectModuleService
) {
super(translateService);
}

async ngOnInit() {
this.loadSmartTable();
ngOnInit() {
this._applyTranslationOnSmartTable();
this._loadSmartTableSettings();
}

/**
Expand All @@ -72,7 +69,6 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem
}

this.loading = true;

try {
const { items } = await firstValueFrom(
this.organizationProjectModuleService.getAllModulesByProjectId({ projectId: this.projectId }, [
Expand Down Expand Up @@ -106,7 +102,7 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem
/**
* Configures the settings for the Smart Table.
*/
loadSmartTable() {
_loadSmartTableSettings() {
this.settingsSmartTable = {
actions: false,
columns: {
Expand Down Expand Up @@ -217,7 +213,7 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem
* Opens the edit dialog for the selected project module.
*/
async onEditProjectModuleDialog() {
const dialogRef = this.dialogService.open(AddProjectModuleDialogComponent, {
const dialogRef = this.dialogService.open(ProjectModuleMutationComponent, {
context: {
projectModule: this.selectedItem,
createModule: false
Expand All @@ -238,6 +234,7 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem

/**
* Updates a module's properties and reloads the table if successful.
*
* @param id Module ID.
* @param changes Object containing the updated fields.
*/
Expand All @@ -252,12 +249,16 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem
}

/**
* Applies translations dynamically on Smart Table columns when the language changes.
* Listens for language changes and triggers the loading of Smart Table settings.
* Unsubscribes when the component is destroyed.
*/
private _applyTranslationOnSmartTable() {
this.translateService.onLangChange.pipe(untilDestroyed(this)).subscribe(() => {
this.loadSmartTable();
});
private _applyTranslationOnSmartTable(): void {
this.translateService.onLangChange
.pipe(
tap(() => this._loadSmartTableSettings()),
untilDestroyed(this)
)
.subscribe();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NbSpinnerModule } from '@nebular/theme';
import { SmartDataViewLayoutModule } from '../../smart-data-layout';
import { ProjectModuleTableComponent } from './project-module-table.component';
import { ProjectModuleMutationModule } from '../project-module-mutation/project-module-mutation.module';

@NgModule({
declarations: [ProjectModuleTableComponent],
exports: [ProjectModuleTableComponent],
imports: [CommonModule, NbSpinnerModule, ProjectModuleMutationModule, SmartDataViewLayoutModule]
})
export class ProjectModuleTableModule {}
1 change: 0 additions & 1 deletion packages/ui-core/shared/src/lib/project/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './project-mutation/project-mutation.module';
export * from './project-mutation/project-mutation.component';
export * from './project-module';

This file was deleted.

Loading

0 comments on commit 3c08f12

Please sign in to comment.