Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit 132a6a9

Browse files
committed
Disabled action buttons while one is active
1 parent 7934a08 commit 132a6a9

File tree

1 file changed

+65
-58
lines changed

1 file changed

+65
-58
lines changed

src/browser.js

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ class RawFileBrowser extends React.Component {
379379

380380
let actions
381381
if (selectedItem) {
382+
// Something is selected. Build custom actions depending on what it is.
382383
if (selectedItem.action) {
384+
// Selected item has an active action against it. Disable all other actions.
383385
let actionText
384386
switch (selectedItem.action) {
385387
case 'delete':
@@ -402,61 +404,63 @@ class RawFileBrowser extends React.Component {
402404
)
403405
} else {
404406
actions = []
405-
if (
406-
selectionIsFolder &&
407-
typeof this.props.onCreateFolder === 'function' &&
408-
!this.state.nameFilter
409-
) {
410-
actions.push(
411-
<li key="action-add-folder">
412-
<a
413-
onClick={this.handleActionBarAddFolderClick}
414-
href="#"
415-
role="button"
416-
>
417-
<i className="fa fa-folder-o" aria-hidden="true" />
418-
&nbsp;Add Subfolder
419-
</a>
420-
</li>
421-
)
422-
}
423-
if (
424-
selectedItem.keyDerived && (
425-
(selectionIsFolder && typeof this.props.onRenameFile === 'function') ||
426-
(!selectionIsFolder && typeof this.props.onRenameFolder === 'function')
427-
)
428-
) {
429-
actions.push(
430-
<li key="action-rename">
431-
<a
432-
onClick={this.handleActionBarRenameClick}
433-
href="#"
434-
role="button"
435-
>
436-
<i className="fa fa-i-cursor" aria-hidden="true" />
437-
&nbsp;Rename
438-
</a>
439-
</li>
440-
)
441-
}
442-
if (
443-
selectedItem.keyDerived && (
444-
(!selectionIsFolder && typeof this.props.onDeleteFile === 'function') ||
445-
(selectionIsFolder && typeof this.props.onDeleteFolder === 'function')
446-
)
447-
) {
448-
actions.push(
449-
<li key="action-delete">
450-
<a
451-
onClick={this.handleActionBarDeleteClick}
452-
href="#"
453-
role="button"
454-
>
455-
<i className="fa fa-trash-o" aria-hidden="true" />
456-
&nbsp;Delete
457-
</a>
458-
</li>
459-
)
407+
if (this.state.activeAction === null) {
408+
if (
409+
selectionIsFolder &&
410+
typeof this.props.onCreateFolder === 'function' &&
411+
!this.state.nameFilter
412+
) {
413+
actions.push(
414+
<li key="action-add-folder">
415+
<a
416+
onClick={this.handleActionBarAddFolderClick}
417+
href="#"
418+
role="button"
419+
>
420+
<i className="fa fa-folder-o" aria-hidden="true" />
421+
&nbsp;Add Subfolder
422+
</a>
423+
</li>
424+
)
425+
}
426+
if (
427+
selectedItem.keyDerived && (
428+
(selectionIsFolder && typeof this.props.onRenameFile === 'function') ||
429+
(!selectionIsFolder && typeof this.props.onRenameFolder === 'function')
430+
)
431+
) {
432+
actions.push(
433+
<li key="action-rename">
434+
<a
435+
onClick={this.handleActionBarRenameClick}
436+
href="#"
437+
role="button"
438+
>
439+
<i className="fa fa-i-cursor" aria-hidden="true" />
440+
&nbsp;Rename
441+
</a>
442+
</li>
443+
)
444+
}
445+
if (
446+
selectedItem.keyDerived && (
447+
(!selectionIsFolder && typeof this.props.onDeleteFile === 'function') ||
448+
(selectionIsFolder && typeof this.props.onDeleteFolder === 'function')
449+
)
450+
) {
451+
actions.push(
452+
<li key="action-delete">
453+
<a
454+
onClick={this.handleActionBarDeleteClick}
455+
href="#"
456+
role="button"
457+
>
458+
<i className="fa fa-trash-o" aria-hidden="true" />
459+
&nbsp;Delete
460+
</a>
461+
</li>
462+
)
463+
}
460464
}
461465
if (actions.length) {
462466
actions = (<ul className="item-actions">{actions}</ul>)
@@ -465,9 +469,13 @@ class RawFileBrowser extends React.Component {
465469
}
466470
}
467471
} else {
472+
// Nothing selected: We're in the 'root' folder. Only allowed action is adding a folder.
468473
actions = []
469-
470-
if (typeof this.props.onCreateFolder === 'function' && !this.state.nameFilter) {
474+
if (
475+
this.state.activeAction === null &&
476+
typeof this.props.onCreateFolder === 'function' &&
477+
!this.state.nameFilter
478+
) {
471479
actions.push(
472480
<li key="action-add-folder">
473481
<a
@@ -481,7 +489,6 @@ class RawFileBrowser extends React.Component {
481489
</li>
482490
)
483491
}
484-
485492
if (actions.length) {
486493
actions = (<ul className="item-actions">{actions}</ul>)
487494
} else {

0 commit comments

Comments
 (0)