Skip to content

Commit

Permalink
NAC-273 restructuring code to create common template (#191)
Browse files Browse the repository at this point in the history
* NAC-273: restructuring initial commit

* created generic component,services & other elements

* store implementation

* common document tab

* common folder tab

* common nxql tab

* passing data dynamically

* Optimized data configuration & store

* optimized

* removed any

* fixxed lint issues

* optimized route title & removed common constants

* unit test & lint fixes

* unit tests 7 refactoring

* fixed test case

* incorporated fix for NAC-284 & NAC-275  in the new structure
  • Loading branch information
swarnadipa-dev authored Sep 25, 2024
1 parent 0adcc00 commit 56ca32e
Show file tree
Hide file tree
Showing 66 changed files with 3,007 additions and 2,798 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export const appRoutes: Route[] = [
},
{
path: "elasticsearch-reindex",
title: routeTitle.ELASTICSEARCH_REINDEX,
loadChildren: () =>
import(
"./features/elastic-search-reindex/elastic-search-reindex.module"
).then((m) => m.ElasticSearchReindexModule),
"./features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.module"
).then((m) => m.GenericMultiFeatureLayoutModule)
},
{
path: "bulk-action-monitoring",
title: routeTitle.BULKACTIONMONITORING,
loadChildren: () =>
import( "./features/bulk-action-monitoring/bulk-action-monitoring.module"
import(
"./features/bulk-action-monitoring/bulk-action-monitoring.module"
).then((m) => m.BulkActionMonitoringModule),
},
{
Expand All @@ -43,4 +43,4 @@ export const appRoutes: Route[] = [
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
export class AppRoutingModule {}
52 changes: 32 additions & 20 deletions nuxeo-admin-console-web/angular-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { bulkActionMonitoringReducer } from './features/bulk-action-monitoring/store/reducers';
import { GenericMultiFeatureLayoutModule } from "./features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.module";
import { GenericModalComponent } from "./features/sub-features/generic-multi-feature-layout/components/generic-modal/generic-modal.component";
import { bulkActionMonitoringReducer } from "./features/bulk-action-monitoring/store/reducers";
import { BaseLayoutModule } from "./layouts/base-layout/base-layout.module";
import { BaseLayoutComponent } from "./layouts/base-layout/components/base-layout.component";
import { NgModule } from "@angular/core";
Expand All @@ -13,7 +15,6 @@ import { MatIconModule } from "@angular/material/icon";
import { MatToolbarModule } from "@angular/material/toolbar";
import { AppRoutingModule } from "./app-routing.module";
import { AuthRoutingModule } from "./auth/auth-routing.module";
import { ElasticSearchReindexModule } from "./features/elastic-search-reindex/elastic-search-reindex.module";
import { HomeModule } from "./features/home/home.module";
import { WarningComponent } from "./features/warning/warning.component";
import { HylandSSOManagerComponent } from "./auth/components/SSO/hylandSSOManager.component";
Expand All @@ -29,21 +30,28 @@ import { MatButtonModule } from "@angular/material/button";
import { MatSidenavModule } from "@angular/material/sidenav";
import { HeaderBarComponent } from "./layouts/header-bar/header-bar.component";
import { MenuBarComponent } from "./layouts/menu-bar/menu-bar.component";
import { HyDialogBoxModule, HyDialogModule, HyMaterialIconModule } from "@hyland/ui";
import {
HyDialogBoxModule,
HyDialogModule,
HyMaterialIconModule,
} from "@hyland/ui";
import { MatCheckboxModule } from "@angular/material/checkbox";
import { MatListModule } from "@angular/material/list";
import { homeReducer } from "./features/home/store/reducers";
import { ProbeDataReducer } from "./features/sub-features/probes-data/store/reducers";
import * as HomeEffects from "./features/home/store/effects";
import * as ProbesEffects from "./features/sub-features/probes-data/store/effects";
import * as ReindexEffects from "./features/elastic-search-reindex/store/effects";
import * as ReindexEffects from "./features/sub-features/generic-multi-feature-layout/store/effects";
import * as BulkActionMonitoringEffects from "./features/bulk-action-monitoring/store/effects";
import { folderReindexReducer, reindexReducer, nxqlReindexReducer } from "./features/elastic-search-reindex/store/reducers";
import { ElasticSearchReindexModalComponent } from "./features/elastic-search-reindex/components/elastic-search-reindex-modal/elastic-search-reindex-modal.component";
import {
folderActionReducer,
documentActionReducer,
nxqlActionReducer,
} from "./features/sub-features/generic-multi-feature-layout/store/reducers";
import { HyKeyboardFocusService } from "@hyland/ui/keyboard-focus";
import { BulkActionMonitoringModule } from "./features/bulk-action-monitoring/bulk-action-monitoring.module";
import { ErrorModalComponent } from './shared/components/error-modal/error-modal.component';
import { ProbesDataModule } from './features/sub-features/probes-data/probes-data.module';
import { ErrorModalComponent } from "./features/sub-features/generic-multi-feature-layout/components/error-modal/error-modal.component";
import { ProbesDataModule } from "./features/sub-features/probes-data/probes-data.module";

@NgModule({
declarations: [
Expand All @@ -54,8 +62,8 @@ import { ProbesDataModule } from './features/sub-features/probes-data/probes-dat
BackendErrorMessagesComponent,
HylandSSOManagerComponent,
BaseLayoutComponent,
ElasticSearchReindexModalComponent,
ErrorModalComponent
GenericModalComponent,
ErrorModalComponent,
],
imports: [
BrowserModule,
Expand All @@ -69,21 +77,26 @@ import { ProbesDataModule } from './features/sub-features/probes-data/probes-dat
router: routerReducer,
auth: authReducer,
home: homeReducer,
reindex: reindexReducer,
folderReindex: folderReindexReducer,
nxqlReindex: nxqlReindexReducer,
bulkActionMonitoring: bulkActionMonitoringReducer,
documentAction: documentActionReducer,
folderAction: folderActionReducer,
nxqlAction: nxqlActionReducer,
bulkActionMonitoring: bulkActionMonitoringReducer,
probes: ProbeDataReducer,
}),
StoreRouterConnectingModule.forRoot(),
EffectsModule.forRoot(authEffects, HomeEffects, ReindexEffects, BulkActionMonitoringEffects, ProbesEffects),
EffectsModule.forRoot(
authEffects,
HomeEffects,
ReindexEffects,
BulkActionMonitoringEffects,
ProbesEffects
),
MatIconModule,
MatToolbarModule,
MatButtonModule,
MatSidenavModule,
HomeModule,
MatListModule,
ElasticSearchReindexModule,
BaseLayoutModule,
HyDialogModule,
MatSidenavModule,
Expand All @@ -94,6 +107,7 @@ import { ProbesDataModule } from './features/sub-features/probes-data/probes-dat
HyMaterialIconModule,
BulkActionMonitoringModule,
ProbesDataModule,
GenericMultiFeatureLayoutModule,
],
providers: [
{
Expand All @@ -106,7 +120,5 @@ import { ProbesDataModule } from './features/sub-features/probes-data/probes-dat
bootstrap: [AppComponent],
})
export class AppModule {
constructor(
private _hyKeyboardFocusService: HyKeyboardFocusService
) {}
}
constructor(private _hyKeyboardFocusService: HyKeyboardFocusService) {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="bulk-action-form-container">
<form [formGroup]="bulkActionMonitoringForm" (ngSubmit)="onBulkActionFormSubmit()" class="bulk-action-form">
<p id="requiredField"> {{ COMMON_LABELS.REQUIRED_FIELD_INDICATOR }}</p>
<p id="requiredField"> {{ GENERIC_LABELS.REQUIRED_FIELD_INDICATOR }}</p>
<mat-form-field hyFormField>
<mat-label>{{ BULK_ACTION_LABELS.BULK_ACTION_ID }}</mat-label>
<input matInput placeholder="{{ BULK_ACTION_LABELS.BULK_ACTION_ID }}" type="text"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { BULK_ACTION_LABELS } from './../../../bulk-action-monitoring.constants';
import { MODAL_DIMENSIONS } from './../../../../../shared/constants/common.constants';
import { ErrorModalComponent } from './../../../../../shared/components/error-modal/error-modal.component';
import { CommonService } from './../../../../../shared/services/common.service';
import { BULK_ACTION_LABELS } from "./../../../bulk-action-monitoring.constants";
import { CommonService } from "./../../../../../shared/services/common.service";
import { MatButtonModule } from "@angular/material/button";
import { MatInputModule } from "@angular/material/input";
import { MockStore, provideMockStore } from "@ngrx/store/testing";
Expand All @@ -21,15 +19,24 @@ import * as fromReducer from "../../../store/reducers";
import * as BulkActionMonitoringActions from "../../../store/actions";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { ActivatedRoute } from "@angular/router";
import { GenericMultiFeatureUtilitiesService } from "../../../../sub-features/generic-multi-feature-layout/services/generic-multi-feature-utilities.service";
import { ErrorModalComponent } from "../../../../sub-features/generic-multi-feature-layout/components/error-modal/error-modal.component";
import { MODAL_DIMENSIONS } from "../../../../sub-features/generic-multi-feature-layout/generic-multi-feature-layout.constants";

describe("BulkActionMonitoringFormComponent", () => {
let component: BulkActionMonitoringFormComponent;
let fixture: ComponentFixture<BulkActionMonitoringFormComponent>;
let mockStore: jasmine.SpyObj<Store>;
let mockCommonService: jasmine.SpyObj<CommonService>;
let genericMultiFeatureUtilitiesService: jasmine.SpyObj<GenericMultiFeatureUtilitiesService>;
let mockDialog: jasmine.SpyObj<MatDialog>;
let mockDialogRef: jasmine.SpyObj<MatDialogRef<ErrorModalComponent>>;
let store: MockStore<fromReducer.BulkActionMonitoringState>;
class genericMultiFeatureUtilitiesServiceStub {
removeLeadingCharacters() {
return "";
}
}
const initialState = {
bulkActionMonitoringInfo: {
"entity-type": null,
Expand Down Expand Up @@ -77,16 +84,20 @@ describe("BulkActionMonitoringFormComponent", () => {
providers: [
FormBuilder,
{ provide: CommonService, useValue: mockCommonService },
{
provide: GenericMultiFeatureUtilitiesService,
useClass: genericMultiFeatureUtilitiesServiceStub,
},
{ provide: MatDialog, useValue: mockDialog },
provideMockStore({ initialState }),
{
provide: ActivatedRoute,
useValue: {
paramMap: of({
get: (key: string) => (key === "bulkActionId" ? "123" : null)
})
}
}
get: (key: string) => (key === "bulkActionId" ? "123" : null),
}),
},
},
],
}).compileComponents();
});
Expand All @@ -98,12 +109,16 @@ describe("BulkActionMonitoringFormComponent", () => {
mockDialog.open.and.returnValue(mockDialogRef);
mockDialogRef.afterClosed.and.returnValue(of({}));
store = TestBed.inject(MockStore);
genericMultiFeatureUtilitiesService = TestBed.inject(
GenericMultiFeatureUtilitiesService
) as jasmine.SpyObj<GenericMultiFeatureUtilitiesService>;
spyOn(genericMultiFeatureUtilitiesService, 'removeLeadingCharacters');
fixture.detectChanges();
});

afterEach(() => {
mockStore.dispatch.calls.reset();
mockCommonService.removeLeadingCharacters.calls.reset();
genericMultiFeatureUtilitiesService.removeLeadingCharacters.calls.reset();
});

it("should create", () => {
Expand All @@ -128,7 +143,9 @@ describe("BulkActionMonitoringFormComponent", () => {

describe("getErrorMessage", () => {
it("should return required error message", () => {
component.bulkActionMonitoringForm.controls["bulkActionId"].setErrors({required: true,});
component.bulkActionMonitoringForm.controls["bulkActionId"].setErrors({
required: true,
});
expect(component.getErrorMessage()).toBe(
BULK_ACTION_LABELS.REQUIRED_BULK_ACTION_ID_ERROR
);
Expand All @@ -143,14 +160,19 @@ describe("BulkActionMonitoringFormComponent", () => {
describe("onBulkActionFormSubmit", () => {
it("should handle valid form submission", () => {
component.isBulkActionBtnDisabled = false;
mockCommonService.removeLeadingCharacters.and.returnValue("123");
component.bulkActionMonitoringForm.controls["bulkActionId"].setValue("123");
genericMultiFeatureUtilitiesService.removeLeadingCharacters.and.returnValue("123");
component.bulkActionMonitoringForm.controls["bulkActionId"].setValue(
"123"
);
spyOn(store, "dispatch");
component.onBulkActionFormSubmit();
expect(mockCommonService.removeLeadingCharacters).toHaveBeenCalledWith("123");
expect(store.dispatch).toHaveBeenCalledWith(BulkActionMonitoringActions.performBulkActionMonitor({ id: "123" }));
expect(genericMultiFeatureUtilitiesService.removeLeadingCharacters).toHaveBeenCalledWith(
"123"
);
expect(store.dispatch).toHaveBeenCalledWith(
BulkActionMonitoringActions.performBulkActionMonitor({ id: "123" })
);
});

});

describe("ngOnDestroy", () => {
Expand All @@ -160,10 +182,18 @@ describe("BulkActionMonitoringFormComponent", () => {
spyOn(component.errorDialogClosedSubscription, "unsubscribe");
spyOn(store, "dispatch");
component.ngOnDestroy();
expect(component.bulkActionLaunchedSubscription.unsubscribe).toHaveBeenCalled();
expect(component.bulkActionErrorSubscription.unsubscribe).toHaveBeenCalled();
expect(component.errorDialogClosedSubscription.unsubscribe).toHaveBeenCalled();
expect(store.dispatch).toHaveBeenCalledWith(BulkActionMonitoringActions.resetBulkActionMonitorState());
expect(
component.bulkActionLaunchedSubscription.unsubscribe
).toHaveBeenCalled();
expect(
component.bulkActionErrorSubscription.unsubscribe
).toHaveBeenCalled();
expect(
component.errorDialogClosedSubscription.unsubscribe
).toHaveBeenCalled();
expect(store.dispatch).toHaveBeenCalledWith(
BulkActionMonitoringActions.resetBulkActionMonitorState()
);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ErrorDetails } from './../../../../elastic-search-reindex/elastic-search-reindex.interface';
import { ERROR_MODAL_LABELS, GENERIC_LABELS, MODAL_DIMENSIONS } from './../../../../sub-features/generic-multi-feature-layout/generic-multi-feature-layout.constants';
import { GenericMultiFeatureUtilitiesService } from './../../../../sub-features/generic-multi-feature-layout/services/generic-multi-feature-utilities.service';
import { CommonService } from './../../../../../shared/services/common.service';
import { COMMON_LABELS, ERROR_MODAL_LABELS, MODAL_DIMENSIONS } from './../../../../../shared/constants/common.constants';
import { BULK_ACTION_LABELS } from './../../../bulk-action-monitoring.constants';
import { ErrorModalComponent } from './../../../../../shared/components/error-modal/error-modal.component';
import { ErrorModalComponent } from '../../../../sub-features/generic-multi-feature-layout/components/error-modal/error-modal.component';
import { ErrorModalClosedInfo } from './../../../../../shared/types/common.interface';
import { BulkActionMonitoringInfo } from './../../../bulk-action-monitoring.interface';
import { MatDialog, MatDialogRef } from "@angular/material/dialog";
Expand All @@ -20,6 +20,7 @@ import * as BulkActionMonitoringActions from "../../../store/actions";
import { HttpErrorResponse } from "@angular/common/http";
import { BulkActionMonitoringState } from "../../../store/reducers";
import { ActivatedRoute } from '@angular/router';
import { ErrorDetails } from '../../../../sub-features/generic-multi-feature-layout/generic-multi-feature-layout.interface';

@Component({
selector: "bulk-action-monitoring-form",
Expand All @@ -38,15 +39,16 @@ export class BulkActionMonitoringFormComponent implements OnInit, OnDestroy {
BULK_ACTION_LABELS = BULK_ACTION_LABELS;
isBulkActionBtnDisabled = false;
userInput = "";
COMMON_LABELS = COMMON_LABELS;
GENERIC_LABELS = GENERIC_LABELS;
bulkActionResponse: BulkActionMonitoringInfo = {} as BulkActionMonitoringInfo;

constructor(
private commonService: CommonService,
public dialogService: MatDialog,
private fb: FormBuilder,
private store: Store<{ bulkActionMonitoring: BulkActionMonitoringState }>,
private route: ActivatedRoute
private route: ActivatedRoute,
private genericMultiFeatureUtilitiesService: GenericMultiFeatureUtilitiesService
) {
this.bulkActionMonitoringForm = this.fb.group({
bulkActionId: ["", Validators.required],
Expand Down Expand Up @@ -133,7 +135,7 @@ export class BulkActionMonitoringFormComponent implements OnInit, OnDestroy {
onBulkActionFormSubmit(): void {
if (this.bulkActionMonitoringForm?.valid && !this.isBulkActionBtnDisabled) {
this.isBulkActionBtnDisabled = true;
this.userInput = this.commonService.removeLeadingCharacters(
this.userInput = this.genericMultiFeatureUtilitiesService.removeLeadingCharacters(
this.bulkActionMonitoringForm?.get("bulkActionId")?.value.trim()
);
this.store.dispatch(
Expand Down

This file was deleted.

Loading

0 comments on commit 56ca32e

Please sign in to comment.