vendure icon indicating copy to clipboard operation
vendure copied to clipboard

Custom order history timeline entries

Open Draykee opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe. I would like to display custom history entries with a custom HistoryEntryType.

Example: We have a marketplace and issue a payout for the product owner.

// Add history element to order to document the payout
await this.historyService.createHistoryEntryForOrder(
    {
        ctx,
        type: HistoryEntryType.ORDER_PAYOUT, //< custom type
        orderId: order.id,
        data: {
            // Data to display
            title, // display title
            link, // to navigate in the admin ui
            // Custom data
            amount,
            service,
            payoutId,
            ownerId,
        },
    } as any, //< because we have a custom type
    false,
);

But this entry will never be displayed in the admin UI, because the angular switchCase does not contain a default option. This default option should be a component that takes title and link from HistoryEntry.data and displays it. All other data should be displayed as JSON inside a popover (like for payments)

Describe the solution you'd like Add a default case for an history entry: https://github.com/vendure-ecommerce/vendure/blob/ce147dc13e139be6d734016f43f7abeed9fac8d9/packages/admin-ui/src/lib/order/src/components/order-history/order-history.component.html#L199

<ng-container *ngSwitchDefault>

  <div class="title" *ngIf="entry.data.title">
    {{ entry.data.title | translate }}
  </div>
  <div class="link" *ngIf="entry.data.link" >
     <a [routerLink]="entry.data.link"><clr-icon shape="cursor-hand-click"></clr-icon></a>
  </div>

<vdr-history-entry-detail *ngIf="entry.data">
  <component-to-show-json [data]="entry.data" />
</vdr-history-entry-detail>
</ng-container>

Draykee avatar Jul 29 '22 11:07 Draykee

Related:

  • #432

How did you extend the HistoryEntryType enum? Do you extend it in GraphQL and then use codegen to generate the TS enum with your custom option?

Would be also good to support custom history entry types & payloads without needing to assert as any in the createHistoryEntryForOrder() method.

michaelbromley avatar Jul 29 '22 16:07 michaelbromley

That's right, we extend the GraphQL Enum

extend enum HistoryEntryType {
    ORDER_PAYOUT
}

Making the type extendable is a good idea aswell.

Draykee avatar Jul 29 '22 16:07 Draykee

My idea would be to add a custom type that requires a few properties to display it in the UI but accepts any string as type

Draykee avatar Jul 29 '22 16:07 Draykee

https://github.com/vendure-ecommerce/vendure/issues/1698 related feature

tianyingchun avatar Aug 12 '22 06:08 tianyingchun

Note: With this we should do the same for Customer history timeline.

michaelbromley avatar Sep 08 '22 13:09 michaelbromley