Skip to content

Commit

Permalink
Revert "fix: add country to address details (SAP#9410)" (SAP#9486)
Browse files Browse the repository at this point in the history
This reverts commit a17ff44.
  • Loading branch information
tobi-or-not-tobi authored Oct 23, 2020
1 parent a17ff44 commit 14dad9a
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export const unitAddress = {
titles: 'Title',
firstName: 'First name',
lastName: 'Last name',
formattedAddress: 'Address',
address1: 'Address',
address2: '2nd address (optional)',
city: 'City',
Expand All @@ -179,4 +178,24 @@ export const unitAddress = {
title: 'Create Address',
subtitle: 'Unit: {{ item.name }} (TODO)',
},

formattedAddress: 'Address',

// confirmDeleteAddress: {
// title: 'Confirm address delete',
// message: 'Are you sure you want to delete this address?',
// },
};

// addressCreate: {
// header: 'New shipping address for {{code}}',
// },
// addressForm: {
// },
// addressDetails: {
// header: 'Details for {{name}}',
// },
// addressEdit: {
// header: 'Edit shipping address for {{code}}',
// },
// }
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export const ROUTE_PARAMS = {
permissionCode: 'permissionCode',
addressCode: 'addressId',
};
export const QUERY_PARAMS = {
parentUnit: 'parentUnit',
};

// TODO:#my-account-architecture - Number.MAX_VALUE?
export const MAX_OCC_INTEGER_VALUE = 2147483647;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { RoutingService } from '@spartacus/core';
import { Observable, of } from 'rxjs';
import { distinctUntilChanged, map, pluck, switchMap } from 'rxjs/operators';
import { distinctUntilChanged, pluck, switchMap } from 'rxjs/operators';
import { ROUTE_PARAMS } from '../constants';

/**
Expand Down Expand Up @@ -51,10 +51,4 @@ export abstract class CurrentOrganizationItemService<T> {
* Emits the current model or null, if there is no model available
*/
protected abstract getItem(...params: any[]): Observable<T>;

getRouterParam(paramKey: string): Observable<string> {
return this.routingService
.getParams()
.pipe(map((params) => params[paramKey]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
We leverage the soft-close feature from the split view, so that the animation
has time to kick in before the router outlet is deleted.
-->
<span (click)="back($event, card)">{{
<span (click)="card.closeView($event)">{{
'organization.cancel' | cxTranslate
}}</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Observable } from 'rxjs';
import { first, map } from 'rxjs/operators';
import { OrganizationCardComponent } from '../organization-card/organization-card.component';
import { OrganizationItemService } from '../organization-item.service';

/**
Expand All @@ -21,8 +20,6 @@ export class OrganizationFormComponent<T> {
*/
@Input() i18nRoot: string;

@Input() animateBack = true;

/**
* i18n key for the localizations.
*/
Expand Down Expand Up @@ -51,10 +48,4 @@ export class OrganizationFormComponent<T> {
// concatenate the i18n root with .edit or .create suffix
this.i18n = this.i18nRoot + (item ? '.edit' : '.create');
}

back(event: MouseEvent, card: OrganizationCardComponent<any>) {
if (this.animateBack) {
card.closeView(event);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export abstract class OrganizationItemService<T> {
*/
launchDetails(item: T): void {
const cxRoute = this.getDetailsRoute();
const params = this.buildRouteParams(item);
const params = this.getRouteParams(item);
if (cxRoute && item && Object.keys(item).length > 0) {
this.routingService.go({ cxRoute, params });
}
Expand All @@ -95,11 +95,7 @@ export abstract class OrganizationItemService<T> {
* doesn't match the expected route parameters. You can manipulate
* the parameter data.
*/
protected buildRouteParams(item: T): any {
protected getRouteParams(item: T): any {
return item;
}

getRouterParam(key: string): Observable<string> {
return this.currentItemService.getRouterParam(key);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
ChangeDetectionStrategy,
Component,
HostBinding,
Input,
} from '@angular/core';
import { ChangeDetectionStrategy, Component, HostBinding } from '@angular/core';
import { EntitiesModel, PaginationModel } from '@spartacus/core';
import { Table, TableStructure } from '@spartacus/storefront';
import { Observable } from 'rxjs';
Expand Down Expand Up @@ -52,7 +47,9 @@ export class OrganizationListComponent<T = any, P = PaginationModel> {
})
);

@Input() key = this.service.key();
get key(): string {
return this.service.key();
}

/**
* Returns the total number of items.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[structure]="structure"
[data]="data.values"
[i18nRoot]="domainType"
[currentItem]="{ property: key, value: subKey$ | async }"
[currentItem]="{ property: key, value: currentKey$ | async }"
>
</cx-table>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ describe('OrganizationSubListComponent', () => {
expect(component).toBeTruthy();
});

it('should resolve getRouteParam', () => {
let result;
component.getRouteParam().subscribe((param) => (result = param));
expect(result).toEqual({ code: 'key' });
});

it('should have cx-table element', () => {
const el = fixture.debugElement.query(By.css('cx-table'));
expect(el).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { EntitiesModel } from '@spartacus/core';
import { TableStructure } from '@spartacus/storefront';
import { Observable } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators';
import { map, switchMap, tap } from 'rxjs/operators';
import { OrganizationListComponent } from '../organization-list/organization-list.component';

@Component({
Expand All @@ -20,16 +20,8 @@ export class OrganizationSubListComponent extends OrganizationListComponent {

@Input() previous: boolean | string = true;

@Input() key = this.service.key();

@Input() set routerKey(key: string) {
this.subKey$ = this.organizationItemService.getRouterParam(key);
}

@HostBinding('class.ghost') hasGhostData = false;

subKey$: Observable<string>;

readonly listData$: Observable<EntitiesModel<any>> = this.currentKey$.pipe(
switchMap((key) => this.service.getData(key)),
tap((data) => {
Expand All @@ -40,4 +32,12 @@ export class OrganizationSubListComponent extends OrganizationListComponent {
readonly dataStructure$: Observable<
TableStructure
> = this.service.getStructure();

getRouteParam(): Observable<any> {
return this.currentKey$.pipe(
map((keyValue) => ({
[this.key]: keyValue,
}))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,11 @@
</div>

<div class="property full-width">
<label>{{ 'unitAddress.formattedAddress' | cxTranslate }}</label>
<label>{{ 'organization.details' | cxTranslate }}</label>
<span class="value">
{{ model.formattedAddress }}
</span>
</div>

<div class="property">
<label>{{ 'unitAddress.country' | cxTranslate }}</label>
<span class="value">
{{ (getCountry(model.country.isocode) | async)?.name }}
</span>
</div>
</section>
</cx-organization-card>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Address, B2BUnit, Country, UserAddressService } from '@spartacus/core';
import { Address, B2BUnit } from '@spartacus/core';
import { Observable } from 'rxjs';
import { map, shareReplay, switchMap, tap } from 'rxjs/operators';
import { shareReplay, switchMap } from 'rxjs/operators';
import { OrganizationItemService } from '../../../../shared/organization-item.service';
import { CurrentUnitService } from '../../../services/current-unit.service';
import { UnitAddressItemService } from '../services/unit-address-item.service';
Expand All @@ -28,23 +28,9 @@ export class UnitAddressDetailsComponent {
)
);

getCountry(isoCode): Observable<Country> {
return this.userAddressService.getDeliveryCountries().pipe(
tap((countries: Country[]) => {
if (Object.keys(countries).length === 0) {
this.userAddressService.loadDeliveryCountries();
}
}),
map((countries) =>
countries.find((country) => country.isocode === isoCode)
)
);
}

constructor(
protected itemService: OrganizationItemService<Address>,
protected currentUnitService: CurrentUnitService,
protected userAddressService: UserAddressService
protected currentUnitService: CurrentUnitService
) {}

deleteAddress(unitUid: string, addressId: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<cx-organization-form i18nRoot="unitAddress" [animateBack]="false">
<cx-organization-form i18nRoot="unitAddress">
<ng-container *ngIf="form" [formGroup]="form" main>
<label aria-required="true" formGroupName="country">
<span class="label-content required">{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ import { OrganizationCellComponent } from '../../../../shared/organization-table

@Component({
template: `
<ng-container *ngIf="unitKey$ | async as uid">
<a
*ngIf="linkable; else noLink"
[routerLink]="{ cxRoute: route, params: getRouterModel(uid) } | cxUrl"
[tabIndex]="tabIndex"
>
<span class="text">{{ property }}</span>
</a>
</ng-container>
<ng-template #noLink>
<a
*ngIf="unitKey$ | async as uid"
[routerLink]="{ cxRoute: route, params: getRouterModel(uid) } | cxUrl"
routerLinkActive="is-current"
[tabIndex]="tabIndex"
>
<span class="text">{{ property }}</span>
</ng-template>
</a>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<cx-organization-sub-list
key="id"
[routerKey]="routerKey"
class="has-nested-view"
>
<cx-organization-sub-list class="has-nested-view">
<a actions class="link" routerLink="create">
{{ 'organization.create' | cxTranslate }}
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ROUTE_PARAMS } from 'feature-libs/organization/administration/components/constants';
import { OrganizationListService } from '../../../../shared/organization-list/organization-list.service';
import { UnitAddressListService } from './unit-address-list.service';

Expand All @@ -13,6 +12,4 @@ import { UnitAddressListService } from './unit-address-list.service';
},
],
})
export class UnitAddressListComponent {
routerKey = ROUTE_PARAMS.addressCode;
}
export class UnitAddressListComponent {}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ChildUnitItemService extends UnitItemService {
return 'orgUnitChildren';
}

protected buildRouteParams(item: B2BUnit) {
protected getRouteParams(item: B2BUnit) {
return { uid: item.parentOrgUnit.uid };
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<cx-organization-sub-list key="customerId" [routerKey]="routerKey">
<cx-organization-sub-list>
<a actions class="link" routerLink="create">
{{ 'organization.create' | cxTranslate }}
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ROUTE_PARAMS } from 'feature-libs/organization/administration/components/constants';
import { OrganizationListService } from '../../../../shared/organization-list/organization-list.service';
import { UnitUserListService } from '../services/unit-user-list.service';

Expand All @@ -13,6 +12,4 @@ import { UnitUserListService } from '../services/unit-user-list.service';
},
],
})
export class UnitUserListComponent {
routerKey = ROUTE_PARAMS.userCode;
}
export class UnitUserListComponent {}
Loading

0 comments on commit 14dad9a

Please sign in to comment.