Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions src/actions/__test__/code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
changeExecutionState,
changeName,
changeId,
changeReadOnly,
fetchProgram,
saveProgram,
createProgram,
Expand Down Expand Up @@ -132,4 +133,12 @@ describe('Code actions', () => {
expect(payload).toEqual(program);
mock.restore();
});

test('changeReadOnly', () => {
const action = changeReadOnly(true);
const { type, payload } = action;

expect(type).toEqual('CHANGE_READ_ONLY');
expect(payload).toEqual(true);
});
});
6 changes: 6 additions & 0 deletions src/actions/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const CHANGE_NAME = 'CHANGE_NAME';
export const CHANGE_NAME_FULFILLED = `${CHANGE_NAME}_FULFILLED`;
export const CHANGE_NAME_REJECTED = `${CHANGE_NAME}_REJECTED`;
export const CHANGE_ID = 'CHANGE_ID';
export const CHANGE_READ_ONLY = 'CHANGE_READ_ONLY';

// Execution States
export const EXECUTION_RUN = 1;
Expand Down Expand Up @@ -87,3 +88,8 @@ export const createProgram = (name, xhroptions) => ({
data
)),
});

export const changeReadOnly = isReadOnly => ({
type: CHANGE_READ_ONLY,
payload: isReadOnly,
});
17 changes: 9 additions & 8 deletions src/components/ProgramList.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import ProgramCollection from './ProgramCollection';

const defaultState = {
programLoaded: false,
programReadOnly: false,
confirmOpen: false,
focusProgram: {
id: null,
Expand Down Expand Up @@ -63,13 +62,16 @@ class ProgramList extends Component {
}

loadProgram = (e) => {
const { fetchProgram } = this.props;
const { changeReadOnly, fetchProgram } = this.props;
const readOnly = e.target.dataset.owned === 'false';

fetchProgram(e.target.id).then(() => this.setState({
programLoaded: true,
programReadOnly: readOnly,
}));

fetchProgram(e.target.id).then(() => {
changeReadOnly(readOnly);
this.setState({
programLoaded: true,
});
});
}

fetch = (params, owned) => {
Expand Down Expand Up @@ -107,7 +109,6 @@ class ProgramList extends Component {
confirmOpen,
focusProgram,
programLoaded,
programReadOnly,
} = this.state;

return (
Expand All @@ -120,7 +121,6 @@ class ProgramList extends Component {
programLoaded ? (
<Redirect to={{
pathname: '/mission-control',
state: { readOnly: programReadOnly },
}}
/>
) : (null)
Expand Down Expand Up @@ -168,6 +168,7 @@ ProgramList.propTypes = {
fetchProgram: PropTypes.func.isRequired,
fetchPrograms: PropTypes.func.isRequired,
removeProgram: PropTypes.func.isRequired,
changeReadOnly: PropTypes.func.isRequired,
user: PropTypes.shape({
user_id: PropTypes.number.isRequired,
}).isRequired,
Expand Down
13 changes: 7 additions & 6 deletions src/components/ProgramName.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment } from 'react';
import React, { Component, Fragment } from 'react';
import { Confirm, Input } from 'semantic-ui-react';
import { connect } from 'react-redux';
import { hot } from 'react-hot-loader';
Expand All @@ -7,7 +7,6 @@ import PropTypes from 'prop-types';

import { updateValidAuth } from '@/actions/auth';
import { changeName as actionChangeName } from '@/actions/code';
import ReadOnlyComponent from '@/components/ReadOnly';

const mapStateToProps = ({ code }) => ({ code });
const mapDispatchToProps = (dispatch, { cookies }) => ({
Expand All @@ -26,13 +25,13 @@ const mapDispatchToProps = (dispatch, { cookies }) => ({
},
});

class ProgramName extends ReadOnlyComponent {
class ProgramName extends Component {
constructor(props) {
super(props);

this.state = {
confirmOpen: false,
editingName: null,
editingName: '',
previousPropName: null, // eslint-disable-line react/no-unused-state
};
}
Expand Down Expand Up @@ -70,6 +69,7 @@ class ProgramName extends ReadOnlyComponent {
}

render() {
const { code } = this.props;
const { confirmOpen, editingName, previousPropName } = this.state;
let actionProp = {};

Expand All @@ -88,8 +88,8 @@ class ProgramName extends ReadOnlyComponent {
<Input
type="text"
label="Name:"
defaultValue={editingName}
disabled={this.isReadOnly()}
value={editingName}
disabled={code.isReadOnly}
onChange={this.handleChange}
{...actionProp}
/>
Expand All @@ -108,6 +108,7 @@ ProgramName.propTypes = {
code: PropTypes.shape({
id: PropTypes.number,
name: PropTypes.string,
isReadOnly: PropTypes.bool,
}).isRequired,
changeName: PropTypes.func.isRequired,
};
Expand Down
36 changes: 0 additions & 36 deletions src/components/ReadOnly.js

This file was deleted.

Loading