Skip to content

Commit

Permalink
Merge branch 'updated-backend-compatibility-issues-5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrb24 committed Sep 11, 2020
2 parents 960f71f + d8ff317 commit 6e34bb6
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 69 deletions.
51 changes: 48 additions & 3 deletions src/core/components/notebook/Notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { PropTypes } from 'prop-types';
import { Icon } from 'semantic-ui-react';
import { LargeMessageButton } from '../Button'
import NotebookCell from './NotebookCell';
import { INSERT_AFTER } from '../../resources/Notebook'
import {INSERT_AFTER, INSERT_BEFORE} from '../../resources/Notebook'

/**
* List of cells in a read-only notebook.
Expand Down Expand Up @@ -55,11 +55,55 @@ class Notebook extends React.Component {
const { notebook, onInsertCell } = this.props;
// If the notebook is empty both parameters are null.
if (notebook.isEmpty()) {
onInsertCell();
this.handleRecommendAction('data','load',null);
} else {
onInsertCell(notebook.lastCell().module, INSERT_AFTER);
}
}
/**
* Allow recommendations
*/
handleRecommendAction = (packageId, commandId, cell) => {
const { apiEngine, userSettings, onInsertCell } = this.props;
try{
let packages = apiEngine.packages.toList();
for (let pckg of packages){
if(packageId === pckg.id){
let cmd = pckg.toList();
for (let command of cmd){
if (commandId === command.id){
command.suggest = true
}
}
}
}
} catch (err){
// recommendation system shouldn't break the workflow
}
if (cell === null){
onInsertCell()
}else{
if (userSettings.showNotebookReversed()) {
onInsertCell(cell, INSERT_BEFORE);
} else {
onInsertCell(cell, INSERT_AFTER);
}
}
}
/**
* Reset all recommendations
*/
handleResetRecommendations = () => {
const { apiEngine } = this.props;
let packages = apiEngine.packages.toList();
for (let pckg of packages){
let cmd = pckg.toList();
for (let command of cmd){
command.suggest = false
}
}
}

render() {
const {
activeNotebookCell,
Expand Down Expand Up @@ -138,7 +182,6 @@ class Notebook extends React.Component {
cellNumber={moduleCount}
datasets={datasets}
isActiveCell={cell.id === activeNotebookCell}
isFirstCell={notebook.cells.length===1}
isNewNext={isNewNext}
isNewPrevious={isNewPrevious}
notebook={notebook}
Expand All @@ -158,6 +201,8 @@ class Notebook extends React.Component {
onSubmitCell={submitHandler}
userSettings={userSettings}
onEditSpreadsheet={onEditSpreadsheet}
onRecommendAction={this.handleRecommendAction}
onResetRecommendations={this.handleResetRecommendations}
/>
);
if (!cell.isNewCell()) {
Expand Down
54 changes: 32 additions & 22 deletions src/core/components/notebook/NotebookCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class NotebookCell extends React.Component {
isNewNext: PropTypes.bool.isRequired,
isNewPrevious: PropTypes.bool.isRequired,
notebook: PropTypes.object.isRequired,
isFirstCell:PropTypes.bool,
onAddFilteredCommand: PropTypes.func.isRequired,
onCancelExec: PropTypes.func,
onCheckStatus: PropTypes.func,
Expand All @@ -71,7 +70,9 @@ class NotebookCell extends React.Component {
onSelect: PropTypes.func.isRequired,
onSubmitCell: PropTypes.func,
userSettings: PropTypes.object.isRequired,
onEditSpreadsheet: PropTypes.func.isRequired
onEditSpreadsheet: PropTypes.func.isRequired,
onRecommendAction: PropTypes.func.isRequired,
onResetRecommendations: PropTypes.func.isRequired
}
/**
* Add the command that is associated with this notebook cell module
Expand Down Expand Up @@ -147,6 +148,13 @@ class NotebookCell extends React.Component {
onSelect(cell);
}
}
/**
* Handle new cell recommendations
*/
handleRecommendAction = (packageId, commandId) => {
const { cell, onRecommendAction } = this.props;
onRecommendAction(packageId, commandId, cell);
}
render() {
const {
apiEngine,
Expand All @@ -165,7 +173,7 @@ class NotebookCell extends React.Component {
onSubmitCell,
userSettings,
onEditSpreadsheet,
isFirstCell
onResetRecommendations
} = this.props;
// The main components of a notebook cell are the cell index, the cell
// dropdown menu, the cell command text or input form and the cell
Expand All @@ -185,18 +193,18 @@ class NotebookCell extends React.Component {
// know which (and how many) cells are still executing.
const cmdSpec = cell.commandSpec;
if ((!cell.isActive()) && (userSettings.isFiltered(cmdSpec))) {
let errorcss = '';
let errorIcon = null;
let errorcss = '';
let errorIcon = null;
if (cell.isErrorOrCanceled()) {
errorcss = ' collapsed-error-cell';
if (cell.isCanceled()) {
errorIcon = (<Icon name='cancel' color='red' title='Canceled'/>);
errorcss = ' collapsed-error-cell';
if (cell.isCanceled()) {
errorIcon = (<Icon name='cancel' color='red' title='Canceled'/>);
} else if (cell.isError()) {
errorIcon = (<Icon name='warning circle' color='red' title='Error' />);
errorIcon = (<Icon name='warning circle' color='red' title='Error' />);
}

}
if (!userSettings.hideFilteredCommands()) {
if (!userSettings.hideFilteredCommands()) {
return (
<div className={'horizontal-divider' + errorcss} >
{ errorIcon }
Expand Down Expand Up @@ -249,6 +257,8 @@ class NotebookCell extends React.Component {
onSelectCell={this.handleSelectCell}
userSettings={userSettings}
onEditSpreadsheet={onEditSpreadsheet}
onRecommendAction={this.handleRecommendAction}
apiEngine={apiEngine}
/>
);
}
Expand All @@ -258,12 +268,12 @@ class NotebookCell extends React.Component {
datasets={datasets}
cell={cell}
isActiveCell={(isActiveCell) && (!notebook.readOnly)}
isFirstCell={isFirstCell}
onClick={this.handleSelectCell}
onDismiss={onDismissCell}
onSelectCell={this.handleSelectCell}
onSubmit={onSubmitCell}
userSettings={userSettings}
onResetRecommendations={onResetRecommendations}
/>
);
// The CSS class depends on whether the cell is active or not and
Expand All @@ -280,16 +290,16 @@ class NotebookCell extends React.Component {
}
return (
<table className={css + cssState}><tbody>
<tr>
<td className={'cell-index' + cssState} onClick={this.handleSelectCell}>
<p className={'cell-index' + cssState}>[{cellIndex}]</p>
{ cellMenu }
</td>
<td className={'cell-area' + cssState}>
{ commandText }
{ outputArea }
</td>
</tr>
<tr>
<td className={'cell-index' + cssState} onClick={this.handleSelectCell}>
<p className={'cell-index' + cssState}>[{cellIndex}]</p>
{ cellMenu }
</td>
<td className={'cell-area' + cssState}>
{ commandText }
{ outputArea }
</td>
</tr>
</tbody></table>
);
}
Expand Down
12 changes: 7 additions & 5 deletions src/core/components/notebook/input/CellCommandArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CellCommandArea extends React.Component {
onSelectCell: PropTypes.func.isRequired,
onSubmit: PropTypes.func,
userSettings: PropTypes.object.isRequired,
isFirstCell: PropTypes.bool
onResetRecommendations: PropTypes.func
}
constructor(props) {
super(props);
Expand Down Expand Up @@ -228,11 +228,13 @@ class CellCommandArea extends React.Component {
*/
handleDismissCommandsListing = () => {
const { selectedCommand } = this.state;
const { onResetRecommendations } = this.props;
if (selectedCommand != null) {
this.setState({showCommandsListing: false});
} else {
this.handleDismiss();
}
onResetRecommendations()
}
/**
* Clear the list of error messages.
Expand All @@ -244,7 +246,7 @@ class CellCommandArea extends React.Component {
* Set the command in the user settings clipboard as the selected command.
*/
handlePasteCommand = () => {
const { datasets, userSettings } = this.props;
const { datasets, userSettings, onResetRecommendations} = this.props;
this.setState({
formValues: toFormValues(
userSettings.clipboard.commandSpec.parameters,
Expand All @@ -254,19 +256,21 @@ class CellCommandArea extends React.Component {
selectedCommand: userSettings.clipboard.commandSpec,
showCommandsListing: false
});
onResetRecommendations()
}
/**
* Update the selected command to the command that is identified by the
* given pair of package and command identifier.
*/
handleSelectCommand = (packageId, commandId) => {
const { apiEngine, datasets } = this.props;
const { apiEngine, datasets, onResetRecommendations} = this.props;
const cmd = apiEngine.packages.getCommandSpec(packageId, commandId);
this.setState({
formValues: toFormValues(cmd.parameters, datasets),
selectedCommand: cmd,
showCommandsListing: false
});
onResetRecommendations()
}
/**
* Set the showCommandsListing to true to show a list of available commands.
Expand Down Expand Up @@ -345,7 +349,6 @@ class CellCommandArea extends React.Component {
onClick,
onSubmit,
userSettings,
isFirstCell
} = this.props;
const {
errors,
Expand Down Expand Up @@ -385,7 +388,6 @@ class CellCommandArea extends React.Component {
mainContent = (
<CommandsListing
apiEngine={apiEngine}
isFirstCell={isFirstCell}
onDismiss={this.handleDismissCommandsListing}
onPaste={onPaste}
onSelect={this.handleSelectCommand} />
Expand Down
5 changes: 2 additions & 3 deletions src/core/components/notebook/input/CommandsListing.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class CommandsListing extends React.Component {
onDismiss: PropTypes.func.isRequired,
onPaste: PropTypes.func,
onSelect: PropTypes.func.isRequired,
isFirstCell:PropTypes.bool
}

groupBy = (arr, property) => {
Expand All @@ -45,7 +44,7 @@ class CommandsListing extends React.Component {


render() {
const { apiEngine, onDismiss, onPaste, onSelect, isFirstCell} = this.props;
const { apiEngine, onDismiss, onPaste, onSelect} = this.props;
// Get a list of command types
const gridColumns = [];
// Get list of packages. The list is sorted by package name by default.
Expand All @@ -69,7 +68,7 @@ class CommandsListing extends React.Component {
);
for (let i = 0; i < commands.length; i++) {
const cmd = commands[i];
let item = isFirstCell && cmd.suggest ? <List.Item key={listItems.length} onClick={() => (onSelect(pckg.id, cmd.id))}>
let item = cmd.suggest ? <List.Item key={listItems.length} onClick={() => (onSelect(pckg.id, cmd.id))}>
<List.Content>
<List.Header as='a' className='suggested-action' icon>
<Header.Content>
Expand Down
14 changes: 12 additions & 2 deletions src/core/components/notebook/output/CellOutputArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ import { isCellOutputRequest } from '../../../actions/project/Notebook';
class CellOutputArea extends React.Component {
static propTypes = {
cell: PropTypes.object.isRequired,
datasets: PropTypes.object.isRequired,
onCancelExec: PropTypes.func,
onCheckStatus: PropTypes.func,
onFetchAnnotations: PropTypes.func.isRequired,
onNavigateDataset: PropTypes.func.isRequired,
onOutputSelect: PropTypes.func.isRequired,
onSelectCell: PropTypes.func.isRequired,
userSettings: PropTypes.object.isRequired,
onEditSpreadsheet: PropTypes.func.isRequired
onEditSpreadsheet: PropTypes.func.isRequired,
onRecommendAction: PropTypes.func.isRequired,
apiEngine: PropTypes.object.isRequired
};
state = {
activeTab: null,
Expand Down Expand Up @@ -255,7 +258,12 @@ class CellOutputArea extends React.Component {
* Returns a dataset view
*/
getDatasetView = (id, dataset) => {
const {onSelectCell, onNavigateDataset, userSettings, onEditSpreadsheet} = this.props;
const {onSelectCell, datasets, onNavigateDataset, userSettings, onEditSpreadsheet, onRecommendAction, apiEngine} = this.props;
try {
dataset.name = datasets[dataset.id].name;
}catch (TypeError) {
// prevent breakage
}
return (
<div className='output-content'>
<DatasetView
Expand All @@ -266,6 +274,8 @@ class CellOutputArea extends React.Component {
userSettings={userSettings}
onEditSpreadsheet={onEditSpreadsheet}
moduleId={id}
downloadLimit={apiEngine.serviceProperties.maxDownloadRowLimit}
onRecommendAction={onRecommendAction}
/>
</div>
)
Expand Down
10 changes: 7 additions & 3 deletions src/core/components/spreadsheet/DatasetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class DatasetView extends React.Component {
onSelectCell: PropTypes.func.isRequired,
userSettings: PropTypes.object.isRequired,
onEditSpreadsheet: PropTypes.func.isRequired,
moduleId: PropTypes.string.isRequired
downloadLimit: PropTypes.number.isRequired,
onRecommendAction: PropTypes.func
}
constructor(props) {
super(props);
Expand Down Expand Up @@ -88,7 +89,7 @@ class DatasetView extends React.Component {
}

render() {
const { dataset, onFetchAnnotations, onNavigate, onSelectCell, userSettings, onEditSpreadsheet, moduleId } = this.props;
const { dataset, onFetchAnnotations, onNavigate, onSelectCell, userSettings, onEditSpreadsheet, moduleId, downloadLimit, onRecommendAction } = this.props;
const activeCell = this.state;
// Content header
const contentHeader = (
Expand All @@ -100,7 +101,10 @@ class DatasetView extends React.Component {
<SpreadsheetDropDown
dataset={dataset}
onEditSpreadsheet={onEditSpreadsheet}
moduleId={moduleId} />
moduleId={moduleId}
downloadLimit={downloadLimit}
onRecommendAction={onRecommendAction}
/>
</div>
);

Expand Down

0 comments on commit 6e34bb6

Please sign in to comment.