mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Better sidebar filtering, jsonpath, fix content-length
This commit is contained in:
parent
dfa514c81d
commit
883866a76a
@ -81,8 +81,7 @@ export function _buildRequestConfig (renderedRequest, patch = {}) {
|
||||
config.formData = formData;
|
||||
} else if (renderedRequest.body.fileName) {
|
||||
// Check if file exists first (read stream won't right away)
|
||||
fs.statSync(renderedRequest.body.fileName);
|
||||
config.body = fs.createReadStream(renderedRequest.body.fileName);
|
||||
config.body = fs.readFileSync(renderedRequest.body.fileName);
|
||||
} else {
|
||||
config.body = renderedRequest.body.text || '';
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "insomnia",
|
||||
"version": "4.2.4",
|
||||
"version": "4.2.5",
|
||||
"productName": "Insomnia",
|
||||
"longName": "Insomnia REST Client",
|
||||
"description": "A simple and beautiful REST API client",
|
||||
@ -17,7 +17,7 @@
|
||||
"httpsnippet": "git@github.com:getinsomnia/httpsnippet.git#a3a2c0a0167fa844bf92df52a1442fa1d68a9053",
|
||||
"insomnia-importers": "^1.3.0",
|
||||
"jsonlint": "^1.6.2",
|
||||
"jsonpath-plus": "^0.15.0",
|
||||
"jsonpath": "^0.2.9",
|
||||
"mime-types": "^2.1.12",
|
||||
"mkdirp": "^0.5.1",
|
||||
"nedb": "^1.8.0",
|
||||
|
@ -35,12 +35,8 @@ class RequestUrlBar extends Component {
|
||||
};
|
||||
|
||||
_handleUrlPaste = e => {
|
||||
e.preventDefault();
|
||||
const text = e.clipboardData.getData('text/plain');
|
||||
this.props.onUrlPaste(text);
|
||||
|
||||
// Set the input anyway in case nothing is able to import
|
||||
e.target.value = text;
|
||||
};
|
||||
|
||||
_handleGenerateCode = () => {
|
||||
|
@ -69,13 +69,10 @@ class Wrapper extends Component {
|
||||
});
|
||||
|
||||
this.forceRequestPaneRefresh();
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// Import failed, that's alright
|
||||
}
|
||||
|
||||
models.request.update(activeRequest, {url: text});
|
||||
};
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ import React, {Component, PropTypes} from 'react';
|
||||
import {getDOMNode} from 'react-dom';
|
||||
import CodeMirror from 'codemirror';
|
||||
import classnames from 'classnames';
|
||||
import JSONPath from 'jsonpath-plus';
|
||||
import jq from 'jsonpath';
|
||||
import vkBeautify from 'vkbeautify';
|
||||
import {DOMParser} from 'xmldom';
|
||||
import xpath from 'xpath';
|
||||
@ -185,7 +185,11 @@ class Editor extends Component {
|
||||
let obj = JSON.parse(code);
|
||||
|
||||
if (this.props.updateFilter && this.state.filter) {
|
||||
obj = JSONPath({json: obj, path: this.state.filter});
|
||||
try {
|
||||
obj = jq.query(obj, this.state.filter);
|
||||
} catch (err) {
|
||||
obj = '[]';
|
||||
}
|
||||
}
|
||||
|
||||
return vkBeautify.json(obj, '\t');
|
||||
|
@ -35,12 +35,12 @@ class PaymentNotificationModal extends Component {
|
||||
render () {
|
||||
return (
|
||||
<Modal ref={m => this.modal = m}>
|
||||
<ModalHeader>Upgrade Now to Insomnia Plus</ModalHeader>
|
||||
<ModalHeader>Insomnia Plus Trial Ended</ModalHeader>
|
||||
<ModalBody className="pad changelog">
|
||||
<div className="text-center pad">
|
||||
<h1>Hi {session.getFirstName()},</h1>
|
||||
<p style={{maxWidth: '30rem', margin: 'auto'}}>
|
||||
Your Insomnia Plus trial has come to an end. Subscribe to a plan
|
||||
Your Insomnia Plus trial has come to an end. Please subscribe to a plan
|
||||
to continue using Plus features like encrypted data synchronization and backup.
|
||||
</p>
|
||||
<br/>
|
||||
|
@ -100,7 +100,6 @@ class Sidebar extends PureComponent {
|
||||
handleGenerateCode={handleGenerateCode}
|
||||
moveRequest={moveRequest}
|
||||
moveRequestGroup={moveRequestGroup}
|
||||
filter={filter}
|
||||
workspace={workspace}
|
||||
activeRequest={activeRequest}
|
||||
/>
|
||||
|
@ -4,36 +4,8 @@ import SidebarRequestGroupRow from './SidebarRequestGroupRow';
|
||||
|
||||
|
||||
class SidebarChildren extends PureComponent {
|
||||
|
||||
_filterChildren (filter, children, extra = null) {
|
||||
filter = filter || '';
|
||||
|
||||
return children.filter(child => {
|
||||
if (child.doc.type !== 'Request') {
|
||||
return true;
|
||||
}
|
||||
|
||||
const request = child.doc;
|
||||
|
||||
const otherMatches = extra || '';
|
||||
const toMatch = `${request.method}❅${request.name}❅${otherMatches}`.toLowerCase();
|
||||
const matchTokens = filter.toLowerCase().split(' ');
|
||||
|
||||
for (let i = 0; i < matchTokens.length; i++) {
|
||||
let token = `${matchTokens[i]}`;
|
||||
if (toMatch.indexOf(token) === -1) {
|
||||
// Filter failed. Don't render children
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
}
|
||||
|
||||
_renderChildren (children, requestGroup) {
|
||||
_renderChildren (children) {
|
||||
const {
|
||||
filter,
|
||||
handleCreateRequest,
|
||||
handleCreateRequestGroup,
|
||||
handleSetRequestGroupCollapsed,
|
||||
@ -47,15 +19,13 @@ class SidebarChildren extends PureComponent {
|
||||
workspace,
|
||||
} = this.props;
|
||||
|
||||
const filteredChildren = this._filterChildren(
|
||||
filter,
|
||||
children,
|
||||
requestGroup && requestGroup.name
|
||||
);
|
||||
|
||||
const activeRequestId = activeRequest ? activeRequest._id : 'n/a';
|
||||
|
||||
return filteredChildren.map(child => {
|
||||
return children.map(child => {
|
||||
if (child.hidden) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (child.doc.type === 'Request') {
|
||||
return (
|
||||
<SidebarRequestRow
|
||||
@ -90,12 +60,7 @@ class SidebarChildren extends PureComponent {
|
||||
}
|
||||
|
||||
const isActive = hasActiveChild(child.children);
|
||||
const children = this._renderChildren(child.children, requestGroup);
|
||||
|
||||
// Don't render the row if there are no children while filtering
|
||||
if (filter && !children.length) {
|
||||
return null;
|
||||
}
|
||||
const children = this._renderChildren(child.children);
|
||||
|
||||
return (
|
||||
<SidebarRequestGroupRow
|
||||
@ -141,7 +106,6 @@ SidebarChildren.propTypes = {
|
||||
moveRequest: PropTypes.func.isRequired,
|
||||
moveRequestGroup: PropTypes.func.isRequired,
|
||||
children: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
filter: PropTypes.string.isRequired,
|
||||
workspace: PropTypes.object.isRequired,
|
||||
|
||||
// Optional
|
||||
|
@ -28,6 +28,15 @@ export const selectActiveWorkspace = createSelector(
|
||||
}
|
||||
);
|
||||
|
||||
export const selectActiveWorkspaceMeta = createSelector(
|
||||
selectActiveWorkspace,
|
||||
selectEntitiesLists,
|
||||
(activeWorkspace, entities) => {
|
||||
const id = activeWorkspace ? activeWorkspace._id : 'n/a';
|
||||
return entities.workspaceMetas.find(m => m.parentId === id);
|
||||
}
|
||||
);
|
||||
|
||||
export const selectRequestsAndRequestGroups = createSelector(
|
||||
selectEntitiesLists,
|
||||
entities => [...entities.requests, ...entities.requestGroups]
|
||||
@ -50,7 +59,10 @@ export const selectSidebarChildren = createSelector(
|
||||
selectCollapsedRequestGroups,
|
||||
selectRequestsAndRequestGroups,
|
||||
selectActiveWorkspace,
|
||||
(collapsed, requestsAndRequestGroups, activeWorkspace) => {
|
||||
selectActiveWorkspaceMeta,
|
||||
(collapsed, requestsAndRequestGroups, activeWorkspace, activeWorkspaceMeta) => {
|
||||
const {sidebarFilter} = activeWorkspaceMeta;
|
||||
|
||||
function next (parentId) {
|
||||
const children = requestsAndRequestGroups
|
||||
.filter(e => e.parentId === parentId)
|
||||
@ -70,7 +82,8 @@ export const selectSidebarChildren = createSelector(
|
||||
if (children.length > 0) {
|
||||
return children.map(c => ({
|
||||
doc: c,
|
||||
children: next(c._id,),
|
||||
children: next(c._id),
|
||||
hidden: false,
|
||||
collapsed: !!collapsed[c._id],
|
||||
}));
|
||||
} else {
|
||||
@ -78,7 +91,43 @@ export const selectSidebarChildren = createSelector(
|
||||
}
|
||||
}
|
||||
|
||||
return next(activeWorkspace._id, false);
|
||||
function matchChildren (children, parentNames = []) {
|
||||
// Bail early if no filter defined
|
||||
if (!sidebarFilter) {
|
||||
return children;
|
||||
}
|
||||
|
||||
for (const child of children) {
|
||||
// Gather all parents so we can match them too
|
||||
matchChildren(child.children, [...parentNames, child.doc.name]);
|
||||
|
||||
const hasMatchedChildren = child.children.find(c => c.hidden === false);
|
||||
|
||||
// Build the monster string to match on
|
||||
const method = child.doc.method || '';
|
||||
const name = child.doc.name;
|
||||
const toMatch = `${method}❅${name}❅${parentNames.join('❅')}`.toLowerCase();
|
||||
|
||||
// Try to match name
|
||||
let hasMatchedName = true;
|
||||
for (const token of sidebarFilter.trim().toLowerCase().split(' ')) {
|
||||
// Filter failed. Don't render children
|
||||
if (toMatch.indexOf(token) === -1) {
|
||||
hasMatchedName = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update hidden state depending on whether it matched
|
||||
const matched = hasMatchedChildren || hasMatchedName;
|
||||
child.hidden = !matched;
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
const childrenTree = next(activeWorkspace._id, false);
|
||||
return matchChildren(childrenTree);
|
||||
}
|
||||
);
|
||||
|
||||
@ -104,15 +153,6 @@ export const selectWorkspaceRequestsAndRequestGroups = createSelector(
|
||||
}
|
||||
);
|
||||
|
||||
export const selectActiveWorkspaceMeta = createSelector(
|
||||
selectActiveWorkspace,
|
||||
selectEntitiesLists,
|
||||
(activeWorkspace, entities) => {
|
||||
const id = activeWorkspace ? activeWorkspace._id : 'n/a';
|
||||
return entities.workspaceMetas.find(m => m.parentId === id);
|
||||
}
|
||||
);
|
||||
|
||||
export const selectActiveRequest = createSelector(
|
||||
state => state.entities,
|
||||
selectActiveWorkspaceMeta,
|
||||
|
@ -107,7 +107,7 @@
|
||||
"httpsnippet": "git@github.com:getinsomnia/httpsnippet.git#a3a2c0a0167fa844bf92df52a1442fa1d68a9053",
|
||||
"insomnia-importers": "^1.3.0",
|
||||
"jsonlint": "^1.6.2",
|
||||
"jsonpath-plus": "^0.15.0",
|
||||
"jsonpath": "^0.2.9",
|
||||
"mime-types": "^2.1.12",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mousetrap": "^1.6.0",
|
||||
|
Loading…
Reference in New Issue
Block a user