From 7d28a43993de6a058dd09665b22f59b6bcbc9464 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 19 Nov 2020 21:05:03 +0200 Subject: [PATCH] DropFileInput: common component to handle droped files (replaced also in add-cluster-page) Signed-off-by: Roman --- .../components/+add-cluster/add-cluster.scss | 8 -- .../components/+add-cluster/add-cluster.tsx | 110 ++++++++---------- .../components/+extensions/extensions.tsx | 44 ++++--- .../copy-to-click/copy-to-click.tsx | 3 +- .../components/input/drop-file-input.scss | 9 ++ .../components/input/drop-file-input.tsx | 76 ++++++++++++ src/renderer/components/input/index.ts | 1 + .../components/layout/wizard-layout.tsx | 5 +- 8 files changed, 165 insertions(+), 91 deletions(-) create mode 100644 src/renderer/components/input/drop-file-input.scss create mode 100644 src/renderer/components/input/drop-file-input.tsx diff --git a/src/renderer/components/+add-cluster/add-cluster.scss b/src/renderer/components/+add-cluster/add-cluster.scss index 90977fa78b..d80373406d 100644 --- a/src/renderer/components/+add-cluster/add-cluster.scss +++ b/src/renderer/components/+add-cluster/add-cluster.scss @@ -1,12 +1,4 @@ .AddCluster { - .droppable { - box-shadow: 0 0 0 5px inset $primary; - - > * { - pointer-events: none; - } - } - .hint { margin-top: -$padding; color: $textColorSecondary; diff --git a/src/renderer/components/+add-cluster/add-cluster.tsx b/src/renderer/components/+add-cluster/add-cluster.tsx index abb28d090e..ef9fb5c43c 100644 --- a/src/renderer/components/+add-cluster/add-cluster.tsx +++ b/src/renderer/components/+add-cluster/add-cluster.tsx @@ -8,7 +8,7 @@ import { KubeConfig } from "@kubernetes/client-node"; import { _i18n } from "../../i18n"; import { t, Trans } from "@lingui/macro"; import { Select, SelectOption } from "../select"; -import { Input } from "../input"; +import { DropFileInput, Input } from "../input"; import { AceEditor } from "../ace-editor"; import { Button } from "../button"; import { Icon } from "../icon"; @@ -43,7 +43,6 @@ export class AddCluster extends React.Component { @observable proxyServer = ""; @observable isWaiting = false; @observable showSettings = false; - @observable dropAreaActive = false; componentDidMount() { clusterStore.setActive(null); @@ -119,6 +118,11 @@ export class AddCluster extends React.Component { } }; + onDropKubeConfig = (files: File[]) => { + this.sourceTab = KubeConfigSourceTab.FILE; + this.setKubeConfig(files[0].path); + } + @action addClusters = () => { let newClusters: ClusterModel[] = []; @@ -137,7 +141,7 @@ export class AddCluster extends React.Component { return true; } catch (err) { this.error = String(err.message); - if (err instanceof ExecValidationNotFoundError ) { + if (err instanceof ExecValidationNotFoundError) { Notifications.error(Error while adding cluster(s): {this.error}); return false; } else { @@ -228,7 +232,7 @@ export class AddCluster extends React.Component { Select kubeconfig file} - active={this.sourceTab == KubeConfigSourceTab.FILE} /> + active={this.sourceTab == KubeConfigSourceTab.FILE}/> Paste as text} @@ -342,71 +346,55 @@ export class AddCluster extends React.Component { return (
{context} - {isNew && } - {isSelected && } + {isNew && } + {isSelected && }
); }; render() { const addDisabled = this.selectedContexts.length === 0; - return ( - this.dropAreaActive = true, - onDragLeave: event => this.dropAreaActive = false, - onDragOver: event => { - event.preventDefault(); // enable onDrop()-callback - event.dataTransfer.dropEffect = "move"; - }, - onDrop: event => { - this.sourceTab = KubeConfigSourceTab.FILE; - this.dropAreaActive = false; - this.setKubeConfig(event.dataTransfer.files[0].path); - } - }} - > -

Add Cluster

- {this.renderKubeConfigSource()} - {this.renderContextSelector()} - - {this.showSettings && ( -
-

HTTP Proxy server. Used for communicating with Kubernetes API.

- this.proxyServer = value} - theme="round-black" - /> - - {'A HTTP proxy server URL (format: http://
:).'} - + + +

Add Cluster

+ {this.renderKubeConfigSource()} + {this.renderContextSelector()} + - )} - {this.error && ( -
{this.error}
- )} -
-
-
+ {this.showSettings && ( +
+

HTTP Proxy server. Used for communicating with Kubernetes API.

+ this.proxyServer = value} + theme="round-black" + /> + + {'A HTTP proxy server URL (format: http://
:).'} + +
+ )} + {this.error && ( +
{this.error}
+ )} +
+
+ +
); } } diff --git a/src/renderer/components/+extensions/extensions.tsx b/src/renderer/components/+extensions/extensions.tsx index 14a22f7061..ffefee0fca 100644 --- a/src/renderer/components/+extensions/extensions.tsx +++ b/src/renderer/components/+extensions/extensions.tsx @@ -7,7 +7,7 @@ import { t, Trans } from "@lingui/macro"; import { _i18n } from "../../i18n"; import { Button } from "../button"; import { WizardLayout } from "../layout/wizard-layout"; -import { Input, InputValidators } from "../input"; +import { DropFileInput, Input, InputValidators } from "../input"; import { Icon } from "../icon"; import { PageLayout } from "../layout/page-layout"; import { CopyToClick } from "../copy-to-click/copy-to-click"; @@ -35,7 +35,7 @@ export class Extensions extends React.Component { return extensionManager.localFolderPath; } - selectPackedExtensionsDialog = async () => { + selectLocalExtensionsDialog = async () => { const { dialog, BrowserWindow, app } = remote; const { canceled, filePaths } = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), { defaultPath: app.getPath("downloads"), @@ -51,15 +51,23 @@ export class Extensions extends React.Component { } } + // todo installFromUrl = () => { if (!this.downloadUrl) { this.input?.focus(); return; } - + console.log('Install from URL', this.downloadUrl); } + // todo installFromLocalPath = (filePaths: string[]) => { + console.log('Install select from dialog', filePaths) + } + + // todo + installOnDrop = (files: File[]) => { + console.log('Install from D&D', files); } renderInfo() { @@ -104,7 +112,7 @@ export class Extensions extends React.Component {