mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Removed workspace update action
This commit is contained in:
parent
b44779d390
commit
461e343c24
@ -39,8 +39,14 @@ class App extends Component {
|
||||
|
||||
render () {
|
||||
const {actions, modals, workspaces, requests, entities} = this.props;
|
||||
|
||||
// TODO: Factor this out into a selector
|
||||
let workspace = entities.workspaces[workspaces.activeId];
|
||||
if (!workspace) {
|
||||
workspace = entities.workspaces[Object.keys(entities.workspaces)[0]];
|
||||
}
|
||||
|
||||
const activeRequestId = workspaces.active.activeRequestId;
|
||||
const activeRequestId = workspace.activeRequestId;
|
||||
const activeRequest = activeRequestId ? entities.requests[activeRequestId] : null;
|
||||
|
||||
const responses = Object.keys(entities.responses).map(id => entities.responses[id]);
|
||||
@ -50,15 +56,15 @@ class App extends Component {
|
||||
const activeResponse = responses.find(r => r.parentId === activeRequestId);
|
||||
|
||||
const children = this._generateSidebarTree(
|
||||
workspaces.active._id,
|
||||
workspace._id,
|
||||
allRequests.concat(allRequestGroups)
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="grid bg-super-dark tall">
|
||||
<Sidebar
|
||||
workspaceId={workspaces.active._id}
|
||||
activateRequest={r => db.update(workspaces.active, {activeRequestId: r._id})}
|
||||
workspaceId={workspace._id}
|
||||
activateRequest={r => db.update(workspace, {activeRequestId: r._id})}
|
||||
changeFilter={actions.requests.changeFilter}
|
||||
addRequestToRequestGroup={requestGroup => db.requestCreate({parentId: requestGroup._id})}
|
||||
toggleRequestGroup={requestGroup => db.update(requestGroup, {collapsed: !requestGroup.collapsed})}
|
||||
@ -122,7 +128,7 @@ App.propTypes = {
|
||||
responses: PropTypes.object.isRequired
|
||||
}).isRequired,
|
||||
workspaces: PropTypes.shape({
|
||||
active: PropTypes.object
|
||||
activeId: PropTypes.string
|
||||
}).isRequired,
|
||||
requests: PropTypes.shape({
|
||||
filter: PropTypes.string.isRequired
|
||||
|
@ -8,6 +8,7 @@ import {connect} from 'react-redux'
|
||||
import Dropdown from '../components/base/Dropdown'
|
||||
import DropdownDivider from '../components/base/DropdownDivider'
|
||||
import * as RequestGroupActions from '../redux/modules/requestGroups'
|
||||
import * as WorkspaceActions from '../redux/modules/workspaces'
|
||||
import * as db from '../database'
|
||||
import importData from '../lib/import'
|
||||
|
||||
@ -19,27 +20,46 @@ class WorkspaceDropdown extends Component {
|
||||
name: 'Insomnia Imports', extensions: ['json']
|
||||
}]
|
||||
};
|
||||
|
||||
|
||||
// TODO: Factor this out into a selector
|
||||
const {entities, workspaces} = this.props;
|
||||
let workspace = entities.workspaces[workspaces.activeId];
|
||||
if (!workspace) {
|
||||
workspace = entities.workspaces[Object.keys(entities.workspaces)[0]];
|
||||
}
|
||||
|
||||
electron.remote.dialog.showOpenDialog(options, paths => {
|
||||
paths.map(path => {
|
||||
fs.readFile(path, 'utf8', (err, data) => {
|
||||
err || importData(this.props.workspaces.active, data);
|
||||
err || importData(workspace, data);
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
_workspaceCreate () {
|
||||
db.workspaceCreate({name: 'New Workspace'}).then(workspace => {
|
||||
this.props.actions.workspaces.activate(workspace);
|
||||
});
|
||||
}
|
||||
|
||||
render () {
|
||||
const {actions, loading, workspaces, entities, ...other} = this.props;
|
||||
|
||||
const allWorkspaces = Object.keys(entities.workspaces).map(id => entities.workspaces[id]);
|
||||
|
||||
// TODO: Factor this out into a selector
|
||||
let workspace = entities.workspaces[workspaces.activeId];
|
||||
if (!workspace) {
|
||||
workspace = entities.workspaces[Object.keys(entities.workspaces)[0]];
|
||||
}
|
||||
|
||||
return (
|
||||
<Dropdown right={true} {...other} className="block">
|
||||
<button className="btn header__content">
|
||||
<div className="grid grid--center">
|
||||
<div className="grid__cell">
|
||||
<h1 className="no-pad">{workspaces.active.name}</h1>
|
||||
<h1 className="no-pad">{workspace.name}</h1>
|
||||
</div>
|
||||
<div className="no-wrap">
|
||||
{loading ? <i className="fa fa-refresh fa-spin txt-lg"></i> : ''}
|
||||
@ -52,12 +72,12 @@ class WorkspaceDropdown extends Component {
|
||||
<DropdownDivider name="Current Workspace"/>
|
||||
|
||||
<li>
|
||||
<button onClick={e => db.requestCreate({parentId: workspaces.active._id})}>
|
||||
<button onClick={e => db.requestCreate({parentId: workspace._id})}>
|
||||
<i className="fa fa-plus-circle"></i> New Request
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button onClick={e => db.requestGroupCreate({parentId: workspaces.active._id})}>
|
||||
<button onClick={e => db.requestGroupCreate({parentId: workspaces._id})}>
|
||||
<i className="fa fa-folder"></i> New Request Group
|
||||
</button>
|
||||
</li>
|
||||
@ -72,24 +92,24 @@ class WorkspaceDropdown extends Component {
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button onClick={e => db.remove(workspaces.active)}>
|
||||
<i className="fa fa-empty"></i> Delete <strong>{workspaces.active.name}</strong>
|
||||
<button onClick={e => db.remove(workspace)}>
|
||||
<i className="fa fa-empty"></i> Delete <strong>{workspace.name}</strong>
|
||||
</button>
|
||||
</li>
|
||||
|
||||
<DropdownDivider name="Workspaces"/>
|
||||
|
||||
{allWorkspaces.map(w => {
|
||||
return w._id === workspaces.active._id ? null : (
|
||||
return w._id === workspace._id ? null : (
|
||||
<li key={w._id}>
|
||||
<button onClick={() => db.workspaceActivate(w)}>
|
||||
<button onClick={() => actions.workspaces.activate(w)}>
|
||||
<i className="fa fa-random"></i> Switch to <strong>{w.name}</strong>
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
<li>
|
||||
<button onClick={e => db.workspaceCreate()}>
|
||||
<button onClick={e => this._workspaceCreate()}>
|
||||
<i className="fa fa-blank"></i> Create Workspace
|
||||
</button>
|
||||
</li>
|
||||
@ -107,7 +127,7 @@ class WorkspaceDropdown extends Component {
|
||||
WorkspaceDropdown.propTypes = {
|
||||
loading: PropTypes.bool.isRequired,
|
||||
workspaces: PropTypes.shape({
|
||||
active: PropTypes.object.isRequired
|
||||
activeId: PropTypes.object
|
||||
}),
|
||||
entities: PropTypes.shape({
|
||||
workspaces: PropTypes.object.isRequired
|
||||
@ -115,6 +135,9 @@ WorkspaceDropdown.propTypes = {
|
||||
actions: PropTypes.shape({
|
||||
requestGroups: PropTypes.shape({
|
||||
showEnvironmentEditModal: PropTypes.func.isRequired
|
||||
}),
|
||||
workspaces: PropTypes.shape({
|
||||
activate: PropTypes.func.isRequired
|
||||
})
|
||||
})
|
||||
};
|
||||
@ -131,7 +154,8 @@ function mapStateToProps (state) {
|
||||
function mapDispatchToProps (dispatch) {
|
||||
return {
|
||||
actions: {
|
||||
requestGroups: bindActionCreators(RequestGroupActions, dispatch)
|
||||
requestGroups: bindActionCreators(RequestGroupActions, dispatch),
|
||||
workspaces: bindActionCreators(WorkspaceActions, dispatch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -185,15 +185,10 @@ export function workspaceCreate (patch = {}) {
|
||||
return modelCreate(TYPE_WORKSPACE, 'wrk', {
|
||||
name: 'New Workspace',
|
||||
activeRequestId: null,
|
||||
activated: Date.now(), // TODO: Delete this property (replace with something better)
|
||||
environments: []
|
||||
}, patch);
|
||||
}
|
||||
|
||||
export function workspaceActivate (workspace) {
|
||||
return update(workspace, {activated: Date.now()});
|
||||
}
|
||||
|
||||
export function workspaceAll () {
|
||||
return db.find({
|
||||
selector: {type: 'Workspace'}
|
||||
@ -211,18 +206,6 @@ export function workspaceAll () {
|
||||
})
|
||||
}
|
||||
|
||||
export function workspaceGetActive () {
|
||||
return db.find({
|
||||
selector: {
|
||||
activated: {$gte: 0}, // HACK: because can't use $exists here?
|
||||
type: {$eq: 'Workspace'}
|
||||
},
|
||||
sort: [{activated: 'desc'}],
|
||||
limit: 1
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~ //
|
||||
// SETTINGS //
|
||||
// ~~~~~~~~ //
|
||||
|
@ -10,33 +10,14 @@ const ENTITY_REMOVE = 'entities/remove';
|
||||
// REDUCERS //
|
||||
// ~~~~~~~~ //
|
||||
|
||||
function generateEntityReducer (referenceName, updateAction, deleteAction) {
|
||||
return function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
|
||||
case updateAction:
|
||||
const doc = action[referenceName];
|
||||
return {...state, [doc._id]: doc};
|
||||
|
||||
case deleteAction:
|
||||
const newState = Object.assign({}, state);
|
||||
delete newState[action[referenceName]._id];
|
||||
return newState;
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function genericEntityReducer (referenceName) {
|
||||
return function (state = {}, action) {
|
||||
const doc = action[referenceName];
|
||||
|
||||
|
||||
if (!doc) {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
switch (action.type) {
|
||||
|
||||
case ENTITY_UPDATE:
|
||||
@ -53,14 +34,8 @@ function genericEntityReducer (referenceName) {
|
||||
}
|
||||
}
|
||||
|
||||
const workspaces = generateEntityReducer(
|
||||
'workspace',
|
||||
workspaceFns.WORKSPACE_UPDATE,
|
||||
'dne'
|
||||
);
|
||||
|
||||
export default combineReducers({
|
||||
workspaces,
|
||||
workspaces: genericEntityReducer('workspace'),
|
||||
requestGroups: genericEntityReducer('requestGroup'),
|
||||
requests: genericEntityReducer('request'),
|
||||
responses: genericEntityReducer('response')
|
||||
@ -72,15 +47,15 @@ export default combineReducers({
|
||||
// ~~~~~~~ //
|
||||
|
||||
const updateFns = {
|
||||
[TYPE_WORKSPACE]: workspaceFns.update,
|
||||
[TYPE_WORKSPACE]: workspace => ({type: ENTITY_UPDATE, workspace}),
|
||||
[TYPE_REQUEST_GROUP]: requestGroup => ({type: ENTITY_UPDATE, requestGroup}),
|
||||
[TYPE_RESPONSE]: response => ({type: ENTITY_UPDATE, response}),
|
||||
[TYPE_REQUEST]: request => ({type: ENTITY_UPDATE, request})
|
||||
};
|
||||
|
||||
const removeFns = {
|
||||
[TYPE_WORKSPACE]: workspace => ({type: ENTITY_UPDATE, workspace}),
|
||||
[TYPE_REQUEST_GROUP]: requestGroup => ({type: ENTITY_UPDATE, requestGroup}),
|
||||
[TYPE_WORKSPACE]: workspace => ({type: ENTITY_REMOVE, workspace}),
|
||||
[TYPE_REQUEST_GROUP]: requestGroup => ({type: ENTITY_REMOVE, requestGroup}),
|
||||
[TYPE_RESPONSE]: response => ({type: ENTITY_UPDATE, response}),
|
||||
[TYPE_REQUEST]: request => ({type: ENTITY_REMOVE, request})
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {combineReducers} from 'redux'
|
||||
|
||||
export const WORKSPACE_UPDATE = 'workspaces/update';
|
||||
export const WORKSPACE_ACTIVATE = 'workspaces/activate';
|
||||
|
||||
// ~~~~~~~~ //
|
||||
// REDUCERS //
|
||||
@ -8,15 +8,9 @@ export const WORKSPACE_UPDATE = 'workspaces/update';
|
||||
|
||||
function activeReducer (state = null, action) {
|
||||
switch (action.type) {
|
||||
|
||||
case WORKSPACE_UPDATE:
|
||||
if (state && state._id === action.workspace._id) {
|
||||
return action.workspace;
|
||||
} else if (state) {
|
||||
return action.workspace.activated > state.activated ? action.workspace : state;
|
||||
} else {
|
||||
return action.workspace;
|
||||
}
|
||||
|
||||
case WORKSPACE_ACTIVATE:
|
||||
return action.workspace._id;
|
||||
|
||||
default:
|
||||
return state;
|
||||
@ -24,7 +18,7 @@ function activeReducer (state = null, action) {
|
||||
}
|
||||
|
||||
export default combineReducers({
|
||||
active: activeReducer
|
||||
activeId: activeReducer
|
||||
});
|
||||
|
||||
|
||||
@ -32,6 +26,6 @@ export default combineReducers({
|
||||
// ACTIONS //
|
||||
// ~~~~~~~ //
|
||||
|
||||
export function update (workspace) {
|
||||
return {type: WORKSPACE_UPDATE, workspace};
|
||||
export function activate (workspace) {
|
||||
return {type: WORKSPACE_ACTIVATE, workspace};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user