From 883866a76ab9463e7c122a8c8a1c34fe250e8f61 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Tue, 31 Jan 2017 19:01:27 -0800 Subject: [PATCH] Better sidebar filtering, jsonpath, fix content-length --- app/common/network.js | 3 +- app/package.json | 4 +- app/ui/components/RequestUrlBar.js | 4 -- app/ui/components/Wrapper.js | 3 - app/ui/components/base/Editor.js | 8 ++- .../modals/PaymentNotificationModal.js | 4 +- app/ui/components/sidebar/Sidebar.js | 1 - app/ui/components/sidebar/SidebarChildren.js | 50 ++------------- app/ui/redux/selectors.js | 64 +++++++++++++++---- package.json | 2 +- 10 files changed, 71 insertions(+), 72 deletions(-) diff --git a/app/common/network.js b/app/common/network.js index c7f2502d0..05bffa5c6 100644 --- a/app/common/network.js +++ b/app/common/network.js @@ -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 || ''; } diff --git a/app/package.json b/app/package.json index dbdae2c0e..d8f72623e 100644 --- a/app/package.json +++ b/app/package.json @@ -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", diff --git a/app/ui/components/RequestUrlBar.js b/app/ui/components/RequestUrlBar.js index f2564c4e2..3c9bbf72e 100644 --- a/app/ui/components/RequestUrlBar.js +++ b/app/ui/components/RequestUrlBar.js @@ -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 = () => { diff --git a/app/ui/components/Wrapper.js b/app/ui/components/Wrapper.js index d070ac47e..8188fa925 100644 --- a/app/ui/components/Wrapper.js +++ b/app/ui/components/Wrapper.js @@ -69,13 +69,10 @@ class Wrapper extends Component { }); this.forceRequestPaneRefresh(); - return; } } catch (e) { // Import failed, that's alright } - - models.request.update(activeRequest, {url: text}); }; diff --git a/app/ui/components/base/Editor.js b/app/ui/components/base/Editor.js index 7bc5af1b5..bc91c9db1 100644 --- a/app/ui/components/base/Editor.js +++ b/app/ui/components/base/Editor.js @@ -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'); diff --git a/app/ui/components/modals/PaymentNotificationModal.js b/app/ui/components/modals/PaymentNotificationModal.js index 556abd59f..a1981705f 100644 --- a/app/ui/components/modals/PaymentNotificationModal.js +++ b/app/ui/components/modals/PaymentNotificationModal.js @@ -35,12 +35,12 @@ class PaymentNotificationModal extends Component { render () { return ( this.modal = m}> - Upgrade Now to Insomnia Plus + Insomnia Plus Trial Ended

Hi {session.getFirstName()},

- 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.


diff --git a/app/ui/components/sidebar/Sidebar.js b/app/ui/components/sidebar/Sidebar.js index 272b7059c..2804a3b28 100644 --- a/app/ui/components/sidebar/Sidebar.js +++ b/app/ui/components/sidebar/Sidebar.js @@ -100,7 +100,6 @@ class Sidebar extends PureComponent { handleGenerateCode={handleGenerateCode} moveRequest={moveRequest} moveRequestGroup={moveRequestGroup} - filter={filter} workspace={workspace} activeRequest={activeRequest} /> diff --git a/app/ui/components/sidebar/SidebarChildren.js b/app/ui/components/sidebar/SidebarChildren.js index e9c460251..78e6cdfb7 100644 --- a/app/ui/components/sidebar/SidebarChildren.js +++ b/app/ui/components/sidebar/SidebarChildren.js @@ -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 ( { + 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, diff --git a/package.json b/package.json index 31a67aa94..2200ebf86 100644 --- a/package.json +++ b/package.json @@ -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",