Skip to content

Commit

Permalink
Merge branch 'master' into rm-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
epicfaace committed Jul 7, 2020
2 parents e4c6250 + 37ea574 commit abcb014
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/worksheets/Worksheet/Worksheet.js
Expand Up @@ -840,7 +840,7 @@ class Worksheet extends React.Component {
function(e) {
// if no active focus, scroll to the bottom position
if (this.state.focusIndex < 0) {
$('html, body').animate({ scrollTop: $(document).height() }, 'fast');
$('html, body').animate({ scrollTop: 0 }, 'fast');
}
this.setState({ showNewText: true });
}.bind(this),
Expand All @@ -853,7 +853,7 @@ class Worksheet extends React.Component {
function(e) {
// if no active focus, scroll to the bottom position
if (this.state.focusIndex < 0) {
$('html, body').animate({ scrollTop: $(document).height() }, 'fast');
$('html, body').animate({ scrollTop: 0 }, 'fast');
}
document.querySelector('#upload-button').click();
}.bind(this),
Expand All @@ -865,7 +865,7 @@ class Worksheet extends React.Component {
function(e) {
// if no active focus, scroll to the bottom position
if (this.state.focusIndex < 0) {
$('html, body').animate({ scrollTop: $(document).height() }, 'fast');
$('html, body').animate({ scrollTop: 0 }, 'fast');
}
this.setState({ showNewRun: true });
}.bind(this),
Expand Down
70 changes: 46 additions & 24 deletions frontend/src/components/worksheets/WorksheetItemList.js
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import Immutable from 'seamless-immutable';
import $ from 'jquery';
import * as Mousetrap from '../../util/ws_mousetrap_fork';
import { buildTerminalCommand, getAfterSortKey, getIds } from '../../util/worksheet_utils';
import { getAfterSortKey, getIds } from '../../util/worksheet_utils';
import ContentsItem from './items/ContentsItem';
import GraphItem from './items/GraphItem';
import ImageItem from './items/ImageItem';
Expand All @@ -13,6 +13,9 @@ import WorksheetItem from './items/WorksheetItem';
import ItemWrapper from './items/ItemWrapper';
import PlaceholderItem from './items/PlaceholderItem';
import NewUpload from './NewUpload/NewUpload';
import TextEditorItem from './items/TextEditorItem';
import NewRun from './NewRun';
import { withStyles } from '@material-ui/core/styles';

export const BLOCK_TO_COMPONENT = {
markup_block: MarkdownItem,
Expand Down Expand Up @@ -83,14 +86,10 @@ const addWorksheetItems = function(props, worksheet_items, prevItem, afterItem)
worksheetUUID={props.worksheetUUID}
reloadWorksheet={props.reloadWorksheet}
showNewRun={
!props.showNewButtonsAfterEachBundleRow &&
props.focusedForButtons &&
props.showNewRun
!props.showNewButtonsAfterEachBundleRow && props.focused && props.showNewRun
}
showNewText={
!props.showNewButtonsAfterEachBundleRow &&
props.focusedForButtons &&
props.showNewText
!props.showNewButtonsAfterEachBundleRow && props.focused && props.showNewText
}
onHideNewRun={props.onHideNewRun}
onHideNewText={props.onHideNewText}
Expand Down Expand Up @@ -124,14 +123,14 @@ class WorksheetItemList extends React.Component {
}

capture_keys() {
// Move focus to the top
// Move focus to the top, above the first item of worksheet
Mousetrap.bind(
['g g'],
function() {
$('body')
.stop(true)
.animate({ scrollTop: 0 }, 'fast');
this.props.setFocus(0, 0);
this.props.setFocus(-1, 0);
}.bind(this),
'keydown',
);
Expand Down Expand Up @@ -197,30 +196,25 @@ class WorksheetItemList extends React.Component {
},
];
}
let focusedForButtonsItem;
let focusedItem;
if (info && info.blocks.length > 0) {
var worksheet_items = [];
info.blocks.forEach(
function(item, index) {
const focused = index === this.props.focusIndex;

// focusedForButtons determines whether clicking on Cell/Upload/Run will
// focused determines whether clicking on Cell/Upload/Run will
// apply to this cell. If nothing is focused (focusIndex = -1),
// append to the end by default.
const focusedForButtons =
focused ||
(this.props.focusIndex === -1 && index === info.blocks.length - 1);

if (focusedForButtons) {
focusedForButtonsItem = item;
// prepend to the top by default.
if (focused) {
focusedItem = item;
}
var props = {
worksheetUUID: info.uuid,
item: item,
version: this.props.version,
active: this.props.active,
focused,
focusedForButtons,
canEdit: this.props.canEdit,
focusIndex: index,
subFocusIndex: this.props.subFocusIndex,
Expand Down Expand Up @@ -255,13 +249,34 @@ class WorksheetItemList extends React.Component {
);
items_display = (
<>
{/*Show new runs/text at the top of worksheet when no blocks are focused*/}
{this.props.showNewText && !focusedItem && (
<TextEditorItem
mode='create'
after_sort_key={-1}
worksheetUUID={info.uuid}
reloadWorksheet={() => this.props.reloadWorksheet(undefined, (0, 0))}
closeEditor={() => {
this.props.onHideNewText();
}}
/>
)}
{this.props.showNewRun && !focusedItem && (
<div className={this.props.classes.insertBox}>
<NewRun
after_sort_key={-1}
ws={this.props.ws}
onSubmit={() => this.props.onHideNewRun()}
reloadWorksheet={() =>
this.props.reloadWorksheet(undefined, (0, 0))
}
/>
</div>
)}
{worksheet_items}
<NewUpload
key={this.state.newUploadKey}
after_sort_key={getAfterSortKey(
focusedForButtonsItem,
this.props.subFocusIndex,
)}
after_sort_key={getAfterSortKey(focusedItem, this.props.subFocusIndex)}
worksheetUUID={info.uuid}
reloadWorksheet={this.props.reloadWorksheet}
// Reset newUploadKey so that NewUpload gets re-rendered. This way,
Expand All @@ -285,4 +300,11 @@ class WorksheetItemList extends React.Component {
}
}

export default WorksheetItemList;
const styles = (theme) => ({
insertBox: {
border: `2px solid ${theme.color.primary.base}`,
margin: '32px 64px !important',
},
});

export default withStyles(styles)(WorksheetItemList);

0 comments on commit abcb014

Please sign in to comment.