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

Commit

Permalink
fix: get filePaths (#1521)
Browse files Browse the repository at this point in the history
* fix: get filePaths

* tweak

* return value already inputted in cancel

* tweak

* rename

* simplify
  • Loading branch information
KazuCocoa committed Aug 15, 2020
1 parent f2e70df commit 23ebafb
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/renderer/components/Session/CapabilityControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ 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);
} catch (e) {
log.error(e);
}
}

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

const buttonAfter = <FileOutlined
const buttonAfter = (currentFilePath) => <FileOutlined
className={SessionStyles['filepath-button']}
onClick={() => this.getLocalFilePath((filepath) => onSetCapabilityParam(filepath[0]))} />;
onClick={async () => {onSetCapabilityParam(await this.getLocalFilePath() || currentFilePath);}} />;

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 +40,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

0 comments on commit 23ebafb

Please sign in to comment.