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

gh-594 Update bulk editor item selection #621

Merged
merged 7 commits into from
Jul 28, 2022
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
8 changes: 8 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ export const pageRoutes: { states: Ng2StateDeclaration[] } = {
url: '/:domainType/bulkEdit/:id',
component: BulkEditContainerComponent
},
{
name: 'appContainer.mainApp.bulkEditDataClass',
url: '/:domainType/bulkEdit/:dataModelId/:dataClassId/:id',
component: BulkEditContainerComponent,
params: {
dataClassId: null
}
},
{
name: 'appContainer.mainApp.twoSidePanel.catalogue.dataModel',
url: '/dataModel/:id/{tabView:string}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,20 @@ limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/
import { Title } from '@angular/platform-browser';
import {
CatalogueItemDomainType,
DataModelDetail,
DataModelDetailResponse
} from '@maurodatamapper/mdm-resources';
import { MdmResourcesService } from '@mdm/modules/resources';
import { CatalogueItemDomainType } from '@maurodatamapper/mdm-resources';
import { MauroItemProviderService } from '@mdm/mauro/mauro-item-provider.service';
import { MauroIdentifier, MauroItem } from '@mdm/mauro/mauro-item.types';
import { MessageHandlerService } from '@mdm/services';
import { EditingService } from '@mdm/services/editing.service';
import {
ComponentHarness,
setupTestModuleForComponent
} from '@mdm/testing/testing.helpers';
import { StateParams, UIRouterGlobals } from '@uirouter/core';
import { of } from 'rxjs';
import { Observable, of } from 'rxjs';
import { BulkEditStep } from '../bulk-edit.types';
import { BulkEditContainerComponent } from './bulk-edit-container.component';

interface MdmDataModelResourceStub {
get: jest.Mock;
}

interface MdmResourcesStub {
dataModel: MdmDataModelResourceStub;
}

interface UIRouterGlobalsStub {
params: StateParams;
}
Expand All @@ -61,10 +50,10 @@ interface MessageHandlerStub {
describe('BulkEditBaseComponent', () => {
let harness: ComponentHarness<BulkEditContainerComponent>;

const resourcesStub: MdmResourcesStub = {
dataModel: {
get: jest.fn()
}
const itemProviderStub = {
get: jest.fn() as jest.MockedFunction<
(identifier: MauroIdentifier) => Observable<MauroItem>
>
};

const uiRouterGlobalsStub: UIRouterGlobalsStub = {
Expand All @@ -84,7 +73,7 @@ describe('BulkEditBaseComponent', () => {
};

const id = '123';
const dataModel: DataModelDetail = {
const dataModel: MauroItem = {
id,
label: 'test',
domainType: CatalogueItemDomainType.DataModel,
Expand All @@ -96,8 +85,8 @@ describe('BulkEditBaseComponent', () => {
harness = await setupTestModuleForComponent(BulkEditContainerComponent, {
providers: [
{
provide: MdmResourcesService,
useValue: resourcesStub
provide: MauroItemProviderService,
useValue: itemProviderStub
},
{
provide: UIRouterGlobals,
Expand All @@ -122,11 +111,7 @@ describe('BulkEditBaseComponent', () => {
});

beforeEach(() => {
resourcesStub.dataModel.get.mockImplementationOnce(() =>
of<DataModelDetailResponse>({
body: dataModel
})
);
itemProviderStub.get.mockImplementationOnce(() => of(dataModel));
});

it('should create', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ SPDX-License-Identifier: Apache-2.0
*/
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import {
DataModelDetail,
DataModelDetailResponse
} from '@maurodatamapper/mdm-resources';
import { MdmResourcesService } from '@mdm/modules/resources';
import { MauroItemProviderService } from '@mdm/mauro/mauro-item-provider.service';
import { MauroItem } from '@mdm/mauro/mauro-item.types';
import { StateHandlerService, MessageHandlerService } from '@mdm/services';
import { EditingService } from '@mdm/services/editing.service';
import { UIRouterGlobals } from '@uirouter/core';
Expand All @@ -37,14 +34,14 @@ import { BulkEditContext, BulkEditStep } from '../bulk-edit.types';
})
export class BulkEditContainerComponent implements OnInit {
context: BulkEditContext;
parent: DataModelDetail;
parent: MauroItem;
currentStep: BulkEditStep = BulkEditStep.Selection;

public Steps = BulkEditStep;

constructor(
private stateHandler: StateHandlerService,
private resource: MdmResourcesService,
private itemProvider: MauroItemProviderService,
private uiRouterGlobals: UIRouterGlobals,
private messageHandler: MessageHandlerService,
private title: Title,
Expand All @@ -55,14 +52,16 @@ export class BulkEditContainerComponent implements OnInit {
this.context = {
rootItem: {
id: this.uiRouterGlobals.params.id,
domainType: this.uiRouterGlobals.params.domainType
domainType: this.uiRouterGlobals.params.domainType,
model: this.uiRouterGlobals.params.dataModelId,
parentDataClass: this.uiRouterGlobals.params.dataClassId
},
elements: [],
childItems: [],
profiles: []
};

this.resource.dataModel
.get(this.context.rootItem.id)
this.itemProvider
.get(this.context.rootItem)
.pipe(
catchError((error) => {
this.messageHandler.showError(
Expand All @@ -72,8 +71,8 @@ export class BulkEditContainerComponent implements OnInit {
return EMPTY;
})
)
.subscribe((response: DataModelDetailResponse) => {
this.parent = response.body;
.subscribe((item: MauroItem) => {
this.parent = item;
this.title.setTitle(`Bulk Edit - ${this.parent.label}`);
this.editing.start();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

SPDX-License-Identifier: Apache-2.0
-->
<div class="mdm-bulk-edit__container-controls">
<button mat-stroked-button color="primary" type="button" (click)="previous()">
<span class="fas fa-tasks"></span>
Select items
</button>
<button mat-stroked-button color="warn" type="button" (click)="cancel()">
<span class="fas fa-door-open"></span>
Close
</button>
</div>
<mat-tab-group class="pxy-2">
<mat-tab *ngFor="let tab of tabs; let index = index" class="tab-title">
<ng-template mat-tab-label>{{ tab.displayName }}</ng-template>
Expand All @@ -26,17 +36,3 @@
></mdm-bulk-edit-editor>
</mat-tab>
</mat-tab-group>
<div class="modal-footer pxy-2">
<button mat-button color="warn" type="button" class="mr-1" (click)="cancel()">
Close
</button>
<button
mat-button
color="warn"
type="button"
class="mr-1"
(click)="previous()"
>
Back
</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ limitations under the License.

SPDX-License-Identifier: Apache-2.0
*/
.mdm-bulk-edit {
&__container-controls {
display: flex;
align-items: center;
justify-content: flex-end;
padding: 1rem;

button {
margin-right: 8px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class BulkEditEditorGroupComponent implements OnInit {
return {
displayName: profile.displayName,
profileProvider: profile,
identifiers: this.context.elements as MauroIdentifier[],
identifiers: this.context.childItems as MauroIdentifier[],
editedProfiles: null
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
-->
<div class="modal-body mdm-bulk-editor">
<mat-toolbar>
<button mat-icon-button matTooltip="Validate changes" (click)="validate()">
<button mat-button color="primary" (click)="validate()">
<span class="fas fa-clipboard-check"></span>
Validate
</button>
<button mat-icon-button matTooltip="Save changes" (click)="save()">
<button mat-button color="primary" (click)="save()">
<span class="fas fa-save"></span>
Save
</button>
<span class="spacer"></span>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class BulkEditEditorComponent implements OnInit {

this.validated.forEach((validationResult) => {
if (
validationResult.profile.label === data.element &&
validationResult.profile.label === data.label &&
validationResult.errors
) {
validationResult.errors.forEach((error) => {
Expand All @@ -218,8 +218,8 @@ export class BulkEditEditorComponent implements OnInit {
const elementGroup: ColGroupDef = {
children: [
{
headerName: 'Element',
field: 'element',
headerName: 'Item',
field: 'label',
pinned: 'left'
}
]
Expand Down Expand Up @@ -281,7 +281,7 @@ export class BulkEditEditorComponent implements OnInit {
});

return {
element: profile.label,
label: profile.label,
profile,
...data
};
Expand Down
1 change: 0 additions & 1 deletion src/app/bulk-edit/bulk-edit-profile.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ describe('BulkEditProfileService', () => {
const badDomains = [
CatalogueItemDomainType.Folder,
CatalogueItemDomainType.VersionedFolder,
CatalogueItemDomainType.DataClass,
CatalogueItemDomainType.DataElement,
CatalogueItemDomainType.Term
];
Expand Down
14 changes: 11 additions & 3 deletions src/app/bulk-edit/bulk-edit-profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SPDX-License-Identifier: Apache-2.0
*/
import { Injectable } from '@angular/core';
import {
CatalogueItemDomainType,
isModelDomainType,
Profile,
ProfileProvider,
Expand Down Expand Up @@ -77,7 +78,7 @@ export class BulkEditProfileService {
identifiers: MauroIdentifier[],
provider: ProfileProvider
): Observable<Profile[]> {
if (!isModelDomainType(rootItem.domainType)) {
if (!this.isCorrectDomainType(rootItem.domainType)) {
return throwError(
new Error(`${rootItem.domainType} is not a model domain type`)
);
Expand All @@ -103,7 +104,7 @@ export class BulkEditProfileService {
provider: ProfileProvider,
payloads: MauroProfileUpdatePayload[]
): Observable<Profile[]> {
if (!isModelDomainType(rootItem.domainType)) {
if (!this.isCorrectDomainType(rootItem.domainType)) {
return throwError(
new Error(`${rootItem.domainType} is not a model domain type`)
);
Expand All @@ -130,7 +131,7 @@ export class BulkEditProfileService {
provider: ProfileProvider,
profiles: Profile[]
): Observable<MauroProfileValidationResult[]> {
if (!isModelDomainType(rootItem.domainType)) {
if (!this.isCorrectDomainType(rootItem.domainType)) {
return throwError(
new Error(`${rootItem.domainType} is not a model domain type`)
);
Expand All @@ -143,6 +144,13 @@ export class BulkEditProfileService {
);
}

private isCorrectDomainType(domainType: CatalogueItemDomainType) {
return (
isModelDomainType(domainType) ||
domainType === CatalogueItemDomainType.DataClass
);
}

private listAvailableProfilesFromProvider(
provider: ProfileProviderService,
item: MauroItem
Expand Down
Loading