Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

fix: get filePaths #1521

Merged
merged 6 commits into from
Aug 15, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions app/renderer/components/Session/CapabilityControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@ import SessionStyles from './Session.css';
import { remote } from 'electron';
import { FileOutlined } from '@ant-design/icons';
import { INPUT } from '../AntdTypes';
import _ from 'lodash';
import log from 'electron-log';

const {dialog} = remote;


export default class NewSessionForm extends Component {

getLocalFilePath (success) {
dialog.showOpenDialog((filepath) => {
if (filepath) {
success(filepath);
async getLocalFilePath () {
try {
const {canceled, filePaths} = await dialog.showOpenDialog({properties: ['openFile']});
if (!canceled && !_.isEmpty(filePaths)) {
return filePaths[0];
}
});
this.handleSetType = this.handleSetType.bind(this);
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
log.error(e);
}
}

render () {
const {cap, onSetCapabilityParam, isEditingDesiredCaps, id, t} = this.props;

const buttonAfter = <FileOutlined
const buttonAfter = (currentPath) => <FileOutlined
className={SessionStyles['filepath-button']}
onClick={() => this.getLocalFilePath((filepath) => onSetCapabilityParam(filepath[0]))} />;
onClick={async () => {
const filePath = await this.getLocalFilePath();
onSetCapabilityParam(filePath ? filePath : currentPath) ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be simplified to filePath || currentPath

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of calling onSetCapabilityParam with currentPath argument?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the current inputted path when file browsing was cancelled. Previous filepath behaviour (before #1492) also behaved as the same.

}} />;

switch (cap.type) {
case 'text': return <Input disabled={isEditingDesiredCaps} id={id} placeholder={t('Value')} value={cap.value} onChange={(e) => onSetCapabilityParam(e.target.value)} />;
Expand All @@ -37,7 +43,7 @@ export default class NewSessionForm extends Component {
return <Input disabled={isEditingDesiredCaps} id={id} type={INPUT.TEXTAREA} rows={4} placeholder={t('Value')} value={cap.value}
onChange={(e) => onSetCapabilityParam(e.target.value)} />;
case 'file': return <div className={SessionStyles.fileControlWrapper}>
<Input disabled={isEditingDesiredCaps} id={id} placeholder={t('Value')} value={cap.value} addonAfter={buttonAfter} />
<Input disabled={isEditingDesiredCaps} id={id} placeholder={t('Value')} value={cap.value} addonAfter={buttonAfter(cap.value)} />
</div>;

default:
Expand Down