1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Switch sync buttons on windows (#3110)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-06-21 08:37:05 -04:00 committed by GitHub
parent a21ede72c8
commit 4cd25caca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,6 +32,7 @@ import { SubTitle } from "../layout/sub-title";
import { Spinner } from "../spinner"; import { Spinner } from "../spinner";
import logger from "../../../main/logger"; import logger from "../../../main/logger";
import { iter } from "../../utils"; import { iter } from "../../utils";
import { isWindows } from "../../../common/vars";
interface SyncInfo { interface SyncInfo {
type: "file" | "folder" | "unknown"; type: "file" | "folder" | "unknown";
@ -69,6 +70,8 @@ async function getMapEntry({ filePath, ...data}: KubeconfigSyncEntry): Promise<[
} }
} }
type SelectPathOptions = ("openFile" | "openDirectory")[];
@observer @observer
export class KubeconfigSyncs extends React.Component { export class KubeconfigSyncs extends React.Component {
syncs = observable.map<string, Value>(); syncs = observable.map<string, Value>();
@ -106,11 +109,11 @@ export class KubeconfigSyncs extends React.Component {
} }
@action @action
openFileDialog = async () => { async openDialog(message: string, actions: SelectPathOptions) {
const { dialog, BrowserWindow } = remote; const { dialog, BrowserWindow } = remote;
const { canceled, filePaths } = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), { const { canceled, filePaths } = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
properties: ["openFile", "showHiddenFiles", "multiSelections", "openDirectory"], properties: ["showHiddenFiles", "multiSelections", ...actions],
message: "Select kubeconfig file(s) and folder(s)", message,
buttonLabel: "Sync", buttonLabel: "Sync",
}); });
@ -123,7 +126,7 @@ export class KubeconfigSyncs extends React.Component {
for (const [filePath, info] of newEntries) { for (const [filePath, info] of newEntries) {
this.syncs.set(filePath, info); this.syncs.set(filePath, info);
} }
}; }
renderEntryIcon(entry: Entry) { renderEntryIcon(entry: Entry) {
switch (entry.info.type) { switch (entry.info.type) {
@ -181,16 +184,41 @@ export class KubeconfigSyncs extends React.Component {
); );
} }
renderSyncButtons() {
if (isWindows) {
return (
<div className="flex gaps align-center">
<Button
primary
label="Sync file(s)"
className="box grow"
onClick={() => void this.openDialog("Sync file(s)", ["openFile"])}
/>
<Button
primary
label="Sync folder(s)"
className="box grow"
onClick={() => void this.openDialog("Sync folder(s)", ["openDirectory"])}
/>
</div>
);
}
return (
<Button
primary
label="Sync file(s) and folder(s)"
onClick={() => void this.openDialog("Sync file(s) and folder(s)", ["openFile", "openDirectory"])}
/>
);
}
render() { render() {
return ( return (
<> <>
<section className="small"> <section className="small">
<SubTitle title="Files and Folders to sync" /> <SubTitle title="Files and Folders to sync" />
<Button {this.renderSyncButtons()}
primary
label="Sync file or folder"
onClick={() => void this.openFileDialog()}
/>
<div className="hint"> <div className="hint">
Sync an individual file or all files in a folder (non-recursive). Sync an individual file or all files in a folder (non-recursive).
</div> </div>