insomnia/app/ui/components/sidebar/Sidebar.js

182 lines
5.0 KiB
JavaScript
Raw Normal View History

import React, {Component, PropTypes} from 'react';
import classnames from 'classnames';
import EnvironmentsDropdown from '../../containers/EnvironmentsDropdown';
import SidebarRequestRow from './SidebarRequestRow';
import SidebarRequestGroupRow from './SidebarRequestGroupRow';
import SidebarFilter from './SidebarFilter';
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
import SyncButton from '../SyncButton';
import WorkspaceDropdown from '../../containers/WorkspaceDropdown';
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
import {
SIDEBAR_SKINNY_REMS,
COLLAPSE_SIDEBAR_REMS
} from '../../../backend/constants';
2016-03-18 00:36:00 +00:00
2016-03-23 05:26:27 +00:00
class Sidebar extends Component {
_filterChildren (filter, children, extra = null) {
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
filter = filter || '';
return children.filter(child => {
if (child.doc.type !== 'Request') {
2016-04-05 05:35:21 +00:00
return true;
}
const request = child.doc;
2016-04-05 05:35:21 +00:00
const otherMatches = extra || '';
const toMatch = `${request.method}${request.name}${otherMatches}`.toLowerCase();
const matchTokens = filter.toLowerCase().split(' ');
2016-04-05 05:35:21 +00:00
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;
}
}
2016-04-07 01:11:16 +00:00
return true;
})
2016-03-24 10:20:11 +00:00
}
_renderChildren (children, requestGroup) {
2016-04-29 04:57:03 +00:00
const {
filter,
toggleRequestGroup,
addRequestToRequestGroup,
addRequestToWorkspace,
moveRequest,
moveRequestGroup,
activateRequest,
activeRequestId
2016-04-29 04:57:03 +00:00
} = this.props;
const filteredChildren = this._filterChildren(
filter,
children,
requestGroup && requestGroup.name
);
return filteredChildren.map(child => {
if (child.doc.type === 'Request') {
return (
<SidebarRequestRow
key={child.doc._id}
moveRequest={moveRequest}
activateRequest={activateRequest}
requestCreate={addRequestToWorkspace}
isActive={child.doc._id === activeRequestId}
request={child.doc}
/>
)
2016-04-29 04:57:03 +00:00
}
2016-05-01 19:56:30 +00:00
2016-04-29 04:57:03 +00:00
// We have a RequestGroup!
2016-04-29 04:57:03 +00:00
const requestGroup = child.doc;
const isActive = !!child.children.find(c => c.doc._id === activeRequestId);
2016-04-29 04:57:03 +00:00
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;
}
2016-04-29 04:57:03 +00:00
return (
<SidebarRequestGroupRow
key={requestGroup._id}
isActive={isActive}
moveRequestGroup={moveRequestGroup}
moveRequest={moveRequest}
2016-04-29 04:57:03 +00:00
toggleRequestGroup={toggleRequestGroup}
addRequestToRequestGroup={() => addRequestToRequestGroup(requestGroup)}
2016-04-29 04:57:03 +00:00
numChildren={child.children.length}
requestGroup={requestGroup}>
2016-04-29 04:57:03 +00:00
{children}
</SidebarRequestGroupRow>
)
})
2016-03-24 10:20:11 +00:00
}
2016-03-23 05:26:27 +00:00
render () {
const {
showCookiesModal,
changeFilter,
filter,
children,
hidden,
requestCreate,
requestGroupCreate,
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
showSyncSettings,
width
} = this.props;
2016-03-23 05:26:27 +00:00
return (
<aside className={classnames('sidebar', {
'sidebar--hidden': hidden,
'sidebar--skinny': width < SIDEBAR_SKINNY_REMS,
'sidebar--collapsed': width < COLLAPSE_SIDEBAR_REMS
})}>
<WorkspaceDropdown
className="sidebar__header"
/>
<div className="sidebar__menu">
<EnvironmentsDropdown />
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
<button className="btn btn--super-compact"
onClick={e => showCookiesModal()}>
<div className="sidebar__menu__thing">
<span>Cookies</span>
</div>
</button>
</div>
<SidebarFilter
onChange={filter => changeFilter(filter)}
requestCreate={requestCreate}
requestGroupCreate={requestGroupCreate}
filter={filter}
/>
<ul className="sidebar__list sidebar__list-root">
2016-05-01 19:56:30 +00:00
{this._renderChildren(children)}
</ul>
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
{showSyncSettings ? (
<div className="sidebar__footer">
<SyncButton/>
</div>
) : null}
2016-05-01 19:56:30 +00:00
</aside>
2016-03-23 05:26:27 +00:00
)
}
}
2016-03-18 00:36:00 +00:00
2016-03-20 04:00:40 +00:00
Sidebar.propTypes = {
// Functions
2016-03-20 04:47:43 +00:00
activateRequest: PropTypes.func.isRequired,
toggleRequestGroup: PropTypes.func.isRequired,
2016-04-16 23:24:57 +00:00
addRequestToRequestGroup: PropTypes.func.isRequired,
addRequestToWorkspace: PropTypes.func.isRequired,
2016-03-23 05:26:27 +00:00
changeFilter: PropTypes.func.isRequired,
moveRequest: PropTypes.func.isRequired,
moveRequestGroup: PropTypes.func.isRequired,
2016-07-21 19:15:35 +00:00
requestCreate: PropTypes.func.isRequired,
requestGroupCreate: PropTypes.func.isRequired,
showEnvironmentsModal: PropTypes.func.isRequired,
showCookiesModal: PropTypes.func.isRequired,
width: PropTypes.number.isRequired,
hidden: PropTypes.bool.isRequired,
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
showSyncSettings: PropTypes.bool.isRequired,
// Other
children: PropTypes.array.isRequired,
// Optional
filter: PropTypes.string,
activeRequestId: PropTypes.string
2016-03-20 04:00:40 +00:00
};
2016-03-18 00:36:00 +00:00
export default Sidebar;