providers.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Injectable } from '@angular/core';
  2. import { addActionBarItem, addNavMenuSection } from '@vendure/admin-ui/core';
  3. import { interval } from 'rxjs';
  4. import { map, switchMap } from 'rxjs/operators';
  5. @Injectable()
  6. class MyService {
  7. greet() {
  8. console.log('Hello!');
  9. }
  10. }
  11. export default [
  12. MyService,
  13. addNavMenuSection(
  14. {
  15. id: 'greeter',
  16. label: 'My Extensions',
  17. items: [
  18. {
  19. id: 'greeter',
  20. label: 'Greeter',
  21. routerLink: ['/extensions/example/greet'],
  22. // Icon can be any of https://clarity.design/icons
  23. icon: 'cursor-hand-open',
  24. },
  25. ],
  26. },
  27. // Add this section before the "settings" section
  28. 'settings',
  29. ),
  30. addActionBarItem({
  31. id: 'test',
  32. icon: 'cursor-hand-open',
  33. label: 'Test',
  34. locationId: 'order-detail',
  35. buttonState: context => {
  36. return context.route.data.pipe(
  37. switchMap(data => data.detail.entity),
  38. map((order: any) => {
  39. context.injector.get(MyService).greet();
  40. console.log(order);
  41. return {
  42. disabled: order.state === 'AddingItems',
  43. visible: true,
  44. };
  45. }),
  46. );
  47. // return interval(1000).pipe(
  48. // map(t => {
  49. // console.log(t);
  50. // return {
  51. // disabled: t % 2 === 0,
  52. // visible: t % 5 !== 0,
  53. // };
  54. // }),
  55. // );
  56. },
  57. }),
  58. ];