Skip to content

Commit

Permalink
feat: revert organization management store movement (#96422)
Browse files Browse the repository at this point in the history
  • Loading branch information
skoch-intershop committed Jun 25, 2024
1 parent fd539ad commit 150a252
Show file tree
Hide file tree
Showing 79 changed files with 529 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';

import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { UserBudget } from 'ish-core/models/user-budget/user-budget.model';
import { GenerateLazyComponent } from 'ish-core/utils/module-loader/generate-lazy-component.decorator';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { UserBudget } from '../../models/user-budget/user-budget.model';

@Component({
selector: 'ish-budget-widget',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { FormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';

import { AppFacade } from 'ish-core/facades/app.facade';
import { UserBudget } from 'ish-core/models/user-budget/user-budget.model';
import { whenTruthy } from 'ish-core/utils/operators';

import { UserBudget } from '../../models/user-budget/user-budget.model';

interface UserBudgetModel {
orderSpentLimitValue?: number;
budgetValue?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';

import { Price } from 'ish-core/models/price/price.model';
import { UserBudget } from 'ish-core/models/user-budget/user-budget.model';

import { UserBudget } from '../../models/user-budget/user-budget.model';

/**
* displays the user budget and the appropriate budget bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { FormGroup } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
import { MockComponent } from 'ng-mocks';

import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { ErrorMessageComponent } from 'ish-shared/components/common/error-message/error-message.component';
import { FormlyTestingModule } from 'ish-shared/formly/dev/testing/formly-testing.module';

import { B2bUser } from '../../models/b2b-user/b2b-user.model';

import { UserProfileFormComponent } from './user-profile-form.component';

describe('User Profile Form Component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { FormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { pick } from 'lodash-es';

import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { HttpError } from 'ish-core/models/http-error/http-error.model';

import { B2bUser } from '../../models/b2b-user/b2b-user.model';

@Component({
selector: 'ish-user-profile-form',
templateUrl: './user-profile-form.component.html',
Expand Down
1 change: 1 addition & 0 deletions projects/organization-management/src/app/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export { OrganizationManagementRoutingModule } from '../pages/organization-manag
export { OrganizationManagementExportsModule } from './organization-management-exports.module';
export { OrganizationManagementBreadcrumbService } from '../services/organization-management-breadcrumb/organization-management-breadcrumb.service';

export { UserBudget } from '../models/user-budget/user-budget.model';
export { LazyBudgetWidgetComponent } from './lazy-budget-widget/lazy-budget-widget.component';
export { LazyCostCenterWidgetComponent } from './lazy-cost-center-widget/lazy-cost-center-widget.component';
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import { differenceBy } from 'lodash-es';
import { Observable, combineLatest } from 'rxjs';
import { distinctUntilChanged, filter, map, switchMap, take, withLatestFrom } from 'rxjs/operators';

import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { CostCenter, CostCenterBase, CostCenterBuyer } from 'ish-core/models/cost-center/cost-center.model';
import { UserBudget } from 'ish-core/models/user-budget/user-budget.model';
import { getUserPermissions, getUserRoles } from 'ish-core/store/customer/authorization';
import { getLoggedInUser } from 'ish-core/store/customer/user';
import { toObservable } from 'ish-core/utils/functions';
import { mapToProperty, whenTruthy } from 'ish-core/utils/operators';

import { B2bUser } from '../models/b2b-user/b2b-user.model';
import { UserBudget } from '../models/user-budget/user-budget.model';
import {
getCurrentUserBudget,
getCurrentUserBudgetError,
getCurrentUserBudgetLoading,
loadBudget,
} from 'ish-core/store/organization-management/budget';
} from '../store/budget';
import {
addCostCenter,
addCostCenterBuyers,
Expand All @@ -27,7 +30,7 @@ import {
loadCostCenters,
updateCostCenter,
updateCostCenterBuyer,
} from 'ish-core/store/organization-management/cost-centers';
} from '../store/cost-centers';
import {
addUser,
deleteUser,
Expand All @@ -43,9 +46,7 @@ import {
setUserBudget,
setUserRoles,
updateUser,
} from 'ish-core/store/organization-management/users';
import { toObservable } from 'ish-core/utils/functions';
import { mapToProperty, whenTruthy } from 'ish-core/utils/operators';
} from '../store/users';

/* eslint-disable @typescript-eslint/member-ordering */
@Injectable({ providedIn: 'root' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { inject } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable, of } from 'rxjs';

import { loadCostCenters } from 'ish-core/store/organization-management/cost-centers';
import { loadCostCenters } from '../store/cost-centers';

/**
* Fetch cost centers for cost center management page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';

import { getUserCount, loadUsers } from 'ish-core/store/organization-management/users';
import { getUserCount, loadUsers } from '../store/users';

/**
* Fetch users for user management page
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Link } from 'ish-core/models/link/link.model';
import { UserData } from 'ish-core/models/user/user.interface';

export type B2bUserData = UserData & { active: boolean };

export type B2bUserDataLink = Link & { login: string };
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Address } from 'ish-core/models/address/address.model';
import { PaymentInstrument } from 'ish-core/models/payment-instrument/payment-instrument.model';
import { BasketMockData } from 'ish-core/utils/dev/basket-mock-data';

import { B2bUserData, B2bUserDataLink } from './b2b-user.interface';
import { B2bUserMapper } from './b2b-user.mapper';

describe('B2b User Mapper', () => {
describe('fromData', () => {
it(`should return User when getting UserData`, () => {
const userData = {
firstName: 'Patricia',
lastName: 'Miller',
preferredInvoiceToAddress: BasketMockData.getAddress(),
preferredShipToAddress: { urn: 'urn:1234' } as Address,
preferredPaymentInstrument: { id: '1234' } as PaymentInstrument,
preferredLanguage: 'en_US',
active: true,
} as B2bUserData;
const user = B2bUserMapper.fromData(userData);

expect(user).toMatchInlineSnapshot(`
{
"active": true,
"birthday": undefined,
"businessPartnerNo": undefined,
"department": undefined,
"email": undefined,
"fax": undefined,
"firstName": "Patricia",
"lastName": "Miller",
"login": undefined,
"phoneBusiness": undefined,
"phoneHome": undefined,
"phoneMobile": undefined,
"preferredInvoiceToAddressUrn": "urn:address:customer:JgEKAE8BA50AAAFgDtAd1LZU:ilMKAE8BlIUAAAFgEdAd1LZU",
"preferredLanguage": "en_US",
"preferredPaymentInstrumentId": "1234",
"preferredShipToAddressUrn": "urn:1234",
"title": undefined,
}
`);
});
});

describe('fromListData', () => {
it(`should return User when getting UserListData`, () => {
const userListData = [
{
login: 'pmiller@test.intershop.de',
attributes: [
{
name: 'roleIDs',
value: ['APP_B2B_COSTCENTER_OWNER', 'APP_B2B_BUYER'],
},
{ name: 'firstName', value: 'Patricia' },
{ name: 'lastName', value: 'Miller' },
{ name: 'active', value: true },
{ name: 'budgetPeriod', type: 'String', value: 'monthly' },
{ name: 'orderSpentLimit', type: 'MoneyRO', value: { currency: 'USD', value: 500 } },
{ name: 'budget', type: 'MoneyRO', value: { currency: 'USD', value: 10000 } },
{ name: 'remainingBudget', type: 'MoneyRO', value: { currency: 'USD', value: 8000 } },
{ name: 'spentBudget', type: 'MoneyRO', value: { currency: 'USD', value: 2000 } },
],
} as B2bUserDataLink,
];
const users = B2bUserMapper.fromListData(userListData);

expect(users).toMatchInlineSnapshot(`
[
{
"active": true,
"firstName": "Patricia",
"lastName": "Miller",
"login": "pmiller@test.intershop.de",
"roleIDs": [
"APP_B2B_COSTCENTER_OWNER",
"APP_B2B_BUYER",
],
"userBudget": {
"budget": {
"currency": "USD",
"value": 10000,
},
"budgetPeriod": "monthly",
"orderSpentLimit": {
"currency": "USD",
"value": 500,
},
"remainingBudget": {
"currency": "USD",
"value": 8000,
},
"spentBudget": {
"currency": "USD",
"value": 2000,
},
},
},
]
`);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { AttributeHelper } from 'ish-core/models/attribute/attribute.helper';
import { UserMapper } from 'ish-core/models/user/user.mapper';

import { B2bUserData, B2bUserDataLink } from './b2b-user.interface';
import { B2bUser } from './b2b-user.model';

export class B2bUserMapper {
static fromData(user: B2bUserData): B2bUser {
return { ...UserMapper.fromData(user), active: user.active };
}

static fromListData(data: B2bUserDataLink[]): B2bUser[] {
if (data) {
return data.map(e => ({
login: e.login,
firstName: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'firstName'),
lastName: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'lastName'),
roleIDs: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'roleIDs'),
active: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'active'),
userBudget: {
orderSpentLimit: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'orderSpentLimit'),
budget: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'budget'),
remainingBudget: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'remainingBudget'),
budgetPeriod: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'budgetPeriod'),
spentBudget: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'spentBudget') || {
...AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'budget'),
value: 0,
},
},
}));
} else {
throw new Error('data is required');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { User } from 'ish-core/models/user/user.model';

import { UserBudget } from '../user-budget/user-budget.model';

export interface B2bUser extends Partial<User> {
roleIDs?: string[];
active?: boolean;
userBudget?: UserBudget;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NgModule } from '@angular/core';

import { OrganizationManagementStoreModule } from 'ish-core/store/organization-management/organization-management-store.module';
import { SharedModule } from 'ish-shared/shared.module';

import { BudgetWidgetComponent } from './components/budget-widget/budget-widget.component';
Expand All @@ -13,6 +12,7 @@ import { UserBudgetFormComponent } from './components/user-budget-form/user-budg
import { UserBudgetComponent } from './components/user-budget/user-budget.component';
import { UserProfileFormComponent } from './components/user-profile-form/user-profile-form.component';
import { UserRolesSelectionComponent } from './components/user-roles-selection/user-roles-selection.component';
import { OrganizationManagementStoreModule } from './store/organization-management-store.module';

const exportedComponents = [
CostCenterBudgetComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { Observable, merge } from 'rxjs';
import { take, withLatestFrom } from 'rxjs/operators';

import { AppFacade } from 'ish-core/facades/app.facade';
import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { CostCenterBuyer } from 'ish-core/models/cost-center/cost-center.model';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { PriceHelper } from 'ish-core/models/price/price.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { FormsService } from 'ish-shared/forms/utils/forms.service';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';

/**
* The Cost Center Buyers Page Component displays all the users that are not yet assigned to this cost center. The user can enter user budgets and add these users to the cost center.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { FormBuilder, FormGroup } from '@angular/forms';
import { Observable } from 'rxjs';
import { v4 as uuid } from 'uuid';

import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';

@Component({
selector: 'ish-user-create-page',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';

import { UserBudget } from 'ish-core/models/user-budget/user-budget.model';
import { UserBudget } from '../../../models/user-budget/user-budget.model';

/**
* displays the user budget and the appropriate budget bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { MockComponent, MockPipe } from 'ng-mocks';
import { of } from 'rxjs';
import { anything, instance, mock, when } from 'ts-mockito';

import { B2bRole } from 'ish-core/models/b2b-role/b2b-role.model';
import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { ServerSettingPipe } from 'ish-core/pipes/server-setting.pipe';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bRole } from '../../models/b2b-role/b2b-role.model';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';

import { UserDetailPageComponent } from './user-detail-page.component';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';

import { B2bRole } from 'ish-core/models/b2b-role/b2b-role.model';
import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { mapToProperty, whenTruthy } from 'ish-core/utils/operators';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bRole } from '../../models/b2b-role/b2b-role.model';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';

@Component({
selector: 'ish-user-detail-page',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { MockComponent, MockPipe } from 'ng-mocks';
import { of } from 'rxjs';
import { anything, instance, mock, when } from 'ts-mockito';

import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { ServerSettingPipe } from 'ish-core/pipes/server-setting.pipe';
import { ErrorMessageComponent } from 'ish-shared/components/common/error-message/error-message.component';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';

import { UserEditBudgetPageComponent } from './user-edit-budget-page.component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { Observable } from 'rxjs';

import { B2bUser } from 'ish-core/models/b2b-user/b2b-user.model';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { UserBudget } from 'ish-core/models/user-budget/user-budget.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';
import { UserBudget } from '../../models/user-budget/user-budget.model';

@Component({
selector: 'ish-user-edit-budget-page',
Expand Down
Loading

0 comments on commit 150a252

Please sign in to comment.