Skip to content

Commit

Permalink
feat(admin-ui): Channel aware picker
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Feb 14, 2024
1 parent f02fc56 commit fd92b4c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ export type CreateBulkAssignToChannelActionConfig<ItemType> = Pick<
bulkAssignToChannel: (
dataService: DataService,
ids: string[],
channelId: string,
) => Observable<Array<Partial<ItemType>>>;
channelIds: string[],
) => Array<Observable<Array<Partial<ItemType>>>>;
};

export function createBulkAssignToChannelAction<ItemType>(
Expand Down Expand Up @@ -215,7 +215,7 @@ export function createBulkAssignToChannelAction<ItemType>(
.bulkAssignToChannel(
dataService,
selection.map(c => c.id),
result.id,
result.map(c => c.id),
)
.pipe(mapTo(result));
} else {
Expand All @@ -224,10 +224,10 @@ export function createBulkAssignToChannelAction<ItemType>(
}),
)
.subscribe(result => {
notificationService.success(_('common.notify-assign-to-channel-success-with-count'), {
count: selection.length,
channelCode: result.code,
});
// notificationService.success(_('common.notify-assign-to-channel-success-with-count'), {
// count: selection.length,
// channelCode: result.code,
// });
clearSelection();
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<vdr-form-field [label]="'common.channel' | translate" class="mb-4">
<vdr-channel-assignment-control
clrInput
[multiple]="false"
[multiple]="true"
[includeDefaultChannel]="false"
[formControl]="selectedChannelIdControl"
></vdr-channel-assignment-control>
Expand All @@ -29,9 +29,9 @@

<ng-template vdrDialogButtons>
<button type="button" class="btn" (click)="cancel()">{{ 'common.cancel' | translate }}</button>
<button type="submit" (click)="assign()" [disabled]="!selectedChannel" class="btn btn-primary">
<ng-template [ngIf]="selectedChannel" [ngIfElse]="noSelection">
{{ 'catalog.assign-to-named-channel' | translate : { channelCode: selectedChannel?.code } }}
<button type="submit" (click)="assign()" [disabled]="selectedChannels.length > 0" class="btn btn-primary">
<ng-template [ngIf]="selectedChannels.length > 0" [ngIfElse]="noSelection">
{{ 'catalog.assign-to-channel' | translate }}
</ng-template>
<ng-template #noSelection>
{{ 'catalog.no-channel-selected' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ type Channel = ItemOf<GetChannelsQuery, 'channels'>;
styleUrls: ['./assign-to-channel-dialog.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AssignToChannelDialogComponent implements OnInit, Dialog<Channel> {
selectedChannel: Channel | null | undefined;
export class AssignToChannelDialogComponent implements OnInit, Dialog<Channel[]> {
selectedChannels: Channel[] = [];

currentChannel: Channel;
availableChannels: Channel[];
resolveWith: (result?: Channel) => void;
resolveWith: (result?: Channel[]) => void;
selectedChannelIdControl = new UntypedFormControl();

itemNames: string;
Expand All @@ -45,13 +46,13 @@ export class AssignToChannelDialogComponent implements OnInit, Dialog<Channel> {
}

selectChannel(channelIds: string[]) {
this.selectedChannel = this.availableChannels.find(c => c.id === channelIds[0]);
this.selectedChannels = this.availableChannels.filter(c => channelIds.includes(c.id));
}

assign() {
const selectedChannel = this.selectedChannel;
if (selectedChannel) {
this.resolveWith(selectedChannel);
const selectedChannels = this.selectedChannels;
if (selectedChannels.length > 0) {
this.resolveWith(selectedChannels);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ng-select
appendTo="body"
[addTag]="false"
[multiple]="multiple"
[multiple]="true"
[ngModel]="value"
[clearable]="false"
[searchable]="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,8 @@ import {
Permission,
RemovePromotionsFromChannelDocument,
} from '@vendure/admin-ui/core';
import { gql } from 'apollo-angular';
import { map } from 'rxjs/operators';

const ASSIGN_PROMOTIONS_TO_CHANNEL = gql`
mutation AssignPromotionsToChannel($input: AssignPromotionsToChannelInput!) {
assignPromotionsToChannel(input: $input) {
id
name
}
}
`;

const REMOVE_PROMOTIONS_FROM_CHANNEL = gql`
mutation RemovePromotionsFromChannel($input: RemovePromotionsFromChannelInput!) {
removePromotionsFromChannel(input: $input) {
id
name
}
}
`;

export const deletePromotionsBulkAction = createBulkDeleteAction<ItemOf<GetPromotionListQuery, 'promotions'>>(
{
location: 'promotion-list',
Expand All @@ -45,15 +26,17 @@ export const assignPromotionsToChannelBulkAction = createBulkAssignToChannelActi
location: 'promotion-list',
requiresPermission: Permission.UpdatePromotion,
getItemName: item => item.name,
bulkAssignToChannel: (dataService, promotionIds, channelId) =>
dataService
.mutate(AssignPromotionsToChannelDocument, {
input: {
channelId,
promotionIds,
},
})
.pipe(map(res => res.assignPromotionsToChannel)),
bulkAssignToChannel: (dataService, promotionIds, channelIds) =>
channelIds.map(channelId =>
dataService
.mutate(AssignPromotionsToChannelDocument, {
input: {
channelId,
promotionIds,
},
})
.pipe(map(res => res.assignPromotionsToChannel)),
),
});

export const removePromotionsFromChannelBulkAction = createBulkRemoveFromChannelAction<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<vdr-card [title]="'settings.permissions' | translate">
<vdr-form-field [label]="'settings.channel' | translate">
<vdr-channel-assignment-control
[multiple]="true"
formControlName="channelIds"
[vdrDisabled]="!('UpdateAdministrator' | hasPermission)"
></vdr-channel-assignment-control>
Expand Down

0 comments on commit fd92b4c

Please sign in to comment.