Browse Source

chore(dev-server): Remove example ui extensions

They don't work well in the monorepo structure, and better examples will be available in the real-world-vendure repo.
Michael Bromley 5 years ago
parent
commit
2494ea6979

+ 0 - 5
packages/dev-server/dev-config.ts

@@ -13,8 +13,6 @@ import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
 import path from 'path';
 import { ConnectionOptions } from 'typeorm';
 
-import { UiPlugin } from './ui-plugin/ui-plugin';
-
 /**
  * Config settings used during development
  */
@@ -69,11 +67,8 @@ export const devConfig: VendureConfig = {
                 changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
             },
         }),
-        UiPlugin,
         AdminUiPlugin.init({
             port: 5001,
-            // extensions: UiPlugin.uiExtensions,
-            // watch: true,
         }),
     ],
 };

+ 0 - 10
packages/dev-server/ui-plugin/extensions/js-app/index.html

@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <title>Title</title>
-</head>
-<body>
-<h1>Hello from the plain JS app</h1>
-</body>
-</html>

+ 0 - 66
packages/dev-server/ui-plugin/extensions/ui-plugin.module.ts

@@ -1,66 +0,0 @@
-import { Component, NgModule } from '@angular/core';
-import { RouterModule } from '@angular/router';
-import {
-    ExtensionHostComponent,
-    ExtensionHostConfig,
-    ModalService,
-    SharedModule,
-} from '@vendure/admin-ui/src';
-
-@Component({
-    selector: 'plugin-test-component',
-    template: `
-        <p>Test component works!!!</p>
-        <button class="btn btn-primary" (click)="handleClick()">Click me!</button>
-    `,
-})
-export class TestComponent {
-    constructor(private modalService: ModalService) {}
-
-    handleClick() {
-        this.modalService
-            .dialog({
-                title: 'Did it work?',
-                buttons: [{ label: 'Yes!!!!', returnValue: true, type: 'primary' }],
-            })
-            .subscribe(val => {
-                // tslint:disable-next-line:no-console
-                console.log(val);
-            });
-    }
-}
-
-@NgModule({
-    declarations: [TestComponent],
-    imports: [
-        SharedModule,
-        RouterModule.forChild([
-            {
-                path: 'js-app',
-                component: ExtensionHostComponent,
-                data: {
-                    extensionHostConfig: new ExtensionHostConfig({
-                        extensionUrl: './assets/js-app/index.html',
-                    }),
-                },
-            },
-            {
-                path: 'vue-app',
-                component: ExtensionHostComponent,
-                data: {
-                    breadcrumb: [
-                        {
-                            label: 'Vue.js extension',
-                            link: ['./'],
-                        },
-                    ],
-                    extensionHostConfig: new ExtensionHostConfig({
-                        extensionUrl: './assets/vue-app/index.html',
-                        openInNewTab: true,
-                    }),
-                },
-            },
-        ]),
-    ],
-})
-export class TestModule {}

+ 0 - 163
packages/dev-server/ui-plugin/extensions/ui-shared-plugin.module.ts

@@ -1,163 +0,0 @@
-import { APP_INITIALIZER, ChangeDetectorRef, Component, NgModule, OnInit } from '@angular/core';
-import { FormControl } from '@angular/forms';
-import {
-    AssetPickerDialogComponent,
-    CustomFieldComponentService,
-    CustomFieldConfig,
-    CustomFieldControl,
-    DataService,
-    ModalService,
-    NavBuilderService,
-    SharedModule,
-} from '@vendure/admin-ui/src';
-import gql from 'graphql-tag';
-import { Observable, of } from 'rxjs';
-import { startWith, switchMap } from 'rxjs/operators';
-
-@Component({
-    template: `
-        <input
-            type="range"
-            [min]="customFieldConfig.intMin"
-            [max]="customFieldConfig.intMax"
-            [formControl]="formControl"
-        />
-        {{ formControl.value }}
-    `,
-})
-export class SliderControl implements CustomFieldControl {
-    customFieldConfig: CustomFieldConfig;
-    formControl: FormControl;
-}
-
-@Component({
-    template: `
-        <div class="featured-asset">
-            <img
-                *ngIf="currentAsset$ | async as asset; else placeholder"
-                [src]="asset!.preview + '?preset=thumb'"
-            />
-            <ng-template #placeholder>
-                <div class="placeholder">
-                    <clr-icon shape="image" size="128"></clr-icon>
-                    <div>{{ 'catalog.no-featured-asset' | translate }}</div>
-                </div>
-            </ng-template>
-        </div>
-        <button class="btn" (click)="selectAssets()">
-            <clr-icon shape="attachment"></clr-icon>
-            {{ 'asset.add-asset' | translate }}
-        </button>
-    `,
-})
-export class AssetPickerControl implements CustomFieldControl, OnInit {
-    customFieldConfig: CustomFieldConfig;
-    formControl: FormControl;
-    currentAsset$: Observable<any | null>;
-
-    constructor(
-        private changeDetectorRef: ChangeDetectorRef,
-        private modalService: ModalService,
-        private dataService: DataService,
-    ) {}
-
-    ngOnInit(): void {
-        this.currentAsset$ = this.formControl.valueChanges.pipe(
-            startWith(this.formControl.value),
-            switchMap(assetId => {
-                if (!assetId) {
-                    return of(null);
-                }
-                return this.dataService
-                    .query(
-                        gql`
-                            query($id: ID!) {
-                                asset(id: $id) {
-                                    id
-                                    name
-                                    preview
-                                    width
-                                    height
-                                }
-                            }
-                        `,
-                        { id: assetId },
-                    )
-                    .mapStream((data: any) => data.asset);
-            }),
-        );
-    }
-
-    selectAssets() {
-        this.modalService
-            .fromComponent(AssetPickerDialogComponent, {
-                size: 'xl',
-            })
-            .subscribe((result: any) => {
-                if (result && result.length) {
-                    this.formControl.setValue(result[0].id);
-                    this.formControl.markAsDirty();
-                    // this.changeDetectorRef.markForCheck();
-                }
-            });
-    }
-}
-
-@NgModule({
-    imports: [SharedModule],
-    declarations: [SliderControl, AssetPickerControl],
-    entryComponents: [SliderControl, AssetPickerControl],
-    providers: [
-        {
-            provide: APP_INITIALIZER,
-            multi: true,
-            useFactory: addNavItems,
-            deps: [NavBuilderService],
-        },
-        {
-            provide: APP_INITIALIZER,
-            multi: true,
-            useFactory: registerCustomFieldComponents,
-            deps: [CustomFieldComponentService],
-        },
-    ],
-})
-export class TestSharedModule {}
-
-export function registerCustomFieldComponents(customFieldComponentService: CustomFieldComponentService) {
-    return () => {
-        customFieldComponentService.registerCustomFieldComponent('Product', 'length', SliderControl);
-        customFieldComponentService.registerCustomFieldComponent('ProductVariant', 'length', SliderControl);
-        customFieldComponentService.registerCustomFieldComponent(
-            'Product',
-            'offerImageId',
-            AssetPickerControl,
-        );
-    };
-}
-
-export function addNavItems(navBuilder: NavBuilderService) {
-    return () => {
-        navBuilder.addNavMenuSection(
-            {
-                id: 'test-plugin',
-                label: 'UI Test Plugin',
-                items: [
-                    {
-                        id: 'js-app',
-                        label: 'Plain JS App',
-                        routerLink: ['/extensions/js-app'],
-                        icon: 'code',
-                    },
-                    {
-                        id: 'vue-app',
-                        label: 'Vue App',
-                        routerLink: ['/extensions/vue-app'],
-                        icon: 'code',
-                    },
-                ],
-            },
-            'settings',
-        );
-    };
-}

+ 0 - 81
packages/dev-server/ui-plugin/extensions/vue-app/index.html

@@ -1,81 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-    <head>
-        <meta charset="UTF-8" />
-        <title>Vue App</title>
-        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
-        <script src="../devkit/ui-devkit.js"></script>
-        <link rel="stylesheet" href="https://unpkg.com/@clr/ui/clr-ui.min.css" />
-    </head>
-    <body>
-        <div id="app" style="padding: 1rem;">
-            <div>
-                <h1>Hello from Vue.js!</h1>
-                <button v-on:click="getProducts" class="btn btn-primary">Get products</button>
-                <h3>Products</h3>
-                <ol>
-                    <li v-for="product in products">
-                        {{ product.name }}
-                        <span class="label label-success" v-if="product.enabled">Enabled</span>
-                        <span class="label label-danger" v-else>Disabled</span>
-                        <button
-                            v-on:click="toggleEnabled(product.id, !product.enabled)"
-                            class="btn btn-sm btn-secondary"
-                        >
-                            toggle
-                        </button>
-                    </li>
-                </ol>
-            </div>
-        </div>
-        <script>
-            var app = new Vue({
-                el: '#app',
-                data: {
-                    message: 'Hello Vue!',
-                    products: [],
-                },
-                methods: {
-                    getProducts: function() {
-                        const query = `
-                        query GetProducts($skip: Int, $take: Int) {
-                            products(options: { skip: $skip, take: $take }) {
-                                items { id, name, enabled },
-                                totalItems
-                            }
-                        }`;
-                        this.sub = VendureUiDevkit.graphQlQuery(query, {
-                            skip: 0,
-                            take: 10,
-                        }).stream.subscribe(
-                            val => {
-                                this.products = val.products.items;
-                            },
-                            err => console.error(err),
-                            () => console.log('completed products stream'),
-                        );
-                    },
-                    toggleEnabled: function(id, enabled) {
-                        const mutation = `
-                        mutation ToggleEnabled($id: ID!, $enabled: Boolean!) {
-                            updateProduct(input: { id: $id, enabled: $enabled }) {
-                                id
-                                enabled
-                            }
-                        }
-                        `;
-                        VendureUiDevkit.graphQlMutation(mutation, { id, enabled }).then(val => {
-                            VendureUiDevkit.notify({
-                                message: 'Updated Product',
-                            });
-                        });
-                    },
-                },
-                beforeDestroy: function() {
-                    console.log('destroying!');
-                    this.sub.unsubscribe();
-                },
-            });
-        </script>
-    </body>
-</html>

+ 0 - 28
packages/dev-server/ui-plugin/ui-plugin.ts

@@ -1,28 +0,0 @@
-import { AdminUiExtension } from '@vendure/common/lib/shared-types';
-import { VendurePlugin } from '@vendure/core';
-import path from 'path';
-
-@VendurePlugin({})
-export class UiPlugin {
-    static uiExtensions: AdminUiExtension[] = [
-        {
-            extensionPath: path.join(__dirname, 'extensions'),
-            ngModules: [
-                {
-                    type: 'lazy',
-                    ngModuleFileName: 'ui-plugin.module.ts',
-                    ngModuleName: 'TestModule',
-                },
-                {
-                    type: 'shared',
-                    ngModuleFileName: 'ui-shared-plugin.module.ts',
-                    ngModuleName: 'TestSharedModule',
-                },
-            ],
-            staticAssets: [
-                path.join(__dirname, 'extensions/js-app'),
-                path.join(__dirname, 'extensions/vue-app'),
-            ],
-        },
-    ];
-}