New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for pinned requests #1471
Changes from 8 commits
5c50c87
c279d9d
4675d5b
dd02a96
5f9514e
e4f5882
249a0fa
e47fe11
163fc7e
af9075d
3465501
dba476e
76e64a4
e53999b
a3238a6
2b8b950
b8b9879
ee403f9
e8079a2
aca9a95
d0232fd
6d0d30e
174c1eb
4684fef
b1da85f
05c8e17
2ce8d12
7e6ce57
8938e9b
b18447c
6ab94d2
3fc894e
278b2fb
3461fb9
cc394f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,11 @@ type Child = { | |
pinned: boolean, | ||
}; | ||
|
||
export type SidebarChildObjects = { | ||
pinned: Array<Child>, | ||
all: Array<Child>, | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a more appropriate place to put this type definition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay with it here. It makes sense to have it defined where it's used. |
||
type Props = { | ||
// Required | ||
handleActivateRequest: Function, | ||
|
@@ -29,7 +34,7 @@ type Props = { | |
handleGenerateCode: Function, | ||
handleCopyAsCurl: Function, | ||
moveDoc: Function, | ||
childObjects: Array<Child>, | ||
childObjects: SidebarChildObjects, | ||
workspace: Workspace, | ||
filter: string, | ||
hotKeyRegistry: HotKeyRegistry, | ||
|
@@ -39,7 +44,7 @@ type Props = { | |
}; | ||
|
||
class SidebarChildren extends React.PureComponent<Props> { | ||
_renderChildren(children: Array<Child>): React.Node { | ||
_renderChildren(children: Array<Child>, isInPinnedList: boolean): React.Node { | ||
const { | ||
filter, | ||
handleCreateRequest, | ||
|
@@ -61,15 +66,15 @@ class SidebarChildren extends React.PureComponent<Props> { | |
const activeRequestId = activeRequest ? activeRequest._id : 'n/a'; | ||
|
||
return children.map(child => { | ||
if (child.hidden) { | ||
if (!isInPinnedList && child.hidden) { | ||
return null; | ||
} | ||
|
||
if (child.doc.type === models.request.type) { | ||
return ( | ||
<SidebarRequestRow | ||
key={child.doc._id} | ||
filter={filter || ''} | ||
filter={isInPinnedList ? '' : filter || ''} | ||
moveDoc={moveDoc} | ||
handleActivateRequest={handleActivateRequest} | ||
handleSetRequestPinned={handleSetRequestPinned} | ||
|
@@ -104,7 +109,7 @@ class SidebarChildren extends React.PureComponent<Props> { | |
} | ||
|
||
const isActive = hasActiveChild(child.children); | ||
const children = this._renderChildren(child.children); | ||
const children = this._renderChildren(child.children, isInPinnedList); | ||
|
||
return ( | ||
<SidebarRequestGroupRow | ||
|
@@ -129,26 +134,24 @@ class SidebarChildren extends React.PureComponent<Props> { | |
}); | ||
} | ||
|
||
_renderList(children: Array<Child>): React.Node { | ||
_renderList(children: Array<Child>, pinnedList: boolean): React.Node { | ||
return ( | ||
<ul className="sidebar__list sidebar__list-root theme--sidebar__list"> | ||
{this._renderChildren(children)} | ||
{this._renderChildren(children, pinnedList)} | ||
</ul> | ||
); | ||
} | ||
|
||
render() { | ||
const { childObjects } = this.props; | ||
|
||
const pinnedChildren = childObjects.filter(c => c.pinned); | ||
const unpinnedChildren = childObjects.filter(c => !c.pinned); | ||
const showSeparator = pinnedChildren.length > 0 && unpinnedChildren.length > 0; | ||
const showSeparator = childObjects.pinned.length > 0; | ||
|
||
return ( | ||
<React.Fragment> | ||
{this._renderList(pinnedChildren)} | ||
{showSeparator && <div className="sidebar__list-separator" />} | ||
{this._renderList(unpinnedChildren)} | ||
{this._renderList(childObjects.pinned, true)} | ||
<div className={`sidebar__list-separator${showSeparator ? '' : '--invisible'}`} /> | ||
{this._renderList(childObjects.all, false)} | ||
</React.Fragment> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,18 @@ class App extends PureComponent { | |
await this._requestDuplicate(this.props.activeRequest); | ||
}, | ||
], | ||
[ | ||
hotKeyRefs.REQUEST_TOGGLE_PIN, | ||
async () => { | ||
const metas = Object.values(this.props.entities.requestMetas).filter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL. Will update this evening! |
||
m => m.parentId === this.props.activeRequest._id, | ||
); | ||
await this._handleSetRequestPinned( | ||
this.props.activeRequest, | ||
!(metas[0] && metas[0].pinned), | ||
); | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big fan of this solution, but the other solution would be to put the Are there any other options that I am missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just thinking, whatever solution is decided here could also be used to show a pin icon/reordering for pinned requests in the quick switcher. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to keep Note. One thing that would help here is using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, you'll need to add a check to make sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ya I saw that. I thought your first comment was about the complexity of finding the request meta in the entities list. I was suggesting using getOrCreate instead of having to write the manual filter on the entities list |
||
], | ||
[hotKeyRefs.SIDEBAR_TOGGLE, this._handleToggleSidebar], | ||
[hotKeyRefs.PLUGIN_RELOAD, this._handleReloadPlugins], | ||
[ | ||
|
@@ -439,7 +451,6 @@ class App extends PureComponent { | |
|
||
async _handleSetRequestPinned(request, pinned) { | ||
App._updateRequestMetaByParentId(request._id, { pinned }); | ||
models.request.update(request, { parentId: this.props.activeWorkspace._id }); | ||
} | ||
|
||
_handleSetResponsePreviewMode(requestId, previewMode) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,7 +135,7 @@ export const selectSidebarChildren = createSelector( | |
(collapsed, pinned, activeWorkspace, activeWorkspaceMeta, childrenMap) => { | ||
const sidebarFilter = activeWorkspaceMeta ? activeWorkspaceMeta.sidebarFilter : ''; | ||
|
||
function next(parentId) { | ||
function next(parentId, pinnedChildren) { | ||
const children = (childrenMap[parentId] || []) | ||
.filter(doc => { | ||
return doc.type === models.request.type || doc.type === models.requestGroup.type; | ||
|
@@ -149,15 +149,23 @@ export const selectSidebarChildren = createSelector( | |
}); | ||
|
||
if (children.length > 0) { | ||
return children.map(c => ({ | ||
doc: c, | ||
hidden: false, | ||
collapsed: !!collapsed[c._id], | ||
pinned: !!pinned[c._id], | ||
return children.map(c => { | ||
const child = { | ||
doc: c, | ||
hidden: false, | ||
collapsed: !!collapsed[c._id], | ||
pinned: !!pinned[c._id], | ||
}; | ||
|
||
if (child.pinned) { | ||
pinnedChildren.push(child); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this for efficiency. Extracting all pinned requests (ie. nested requests) in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it actually fits well here within the context of "sidebar children" since the only place it's used is in the sidebar. If/when pinned requests are needed elsewhere, this would make less sense. For now, it's good though. |
||
} | ||
|
||
// Don't add children of requests | ||
children: c.type === models.request.type ? [] : next(c._id), | ||
})); | ||
child.children = c.type === models.request.type ? [] : next(c._id, pinnedChildren); | ||
|
||
return child; | ||
}); | ||
} else { | ||
return children; | ||
} | ||
|
@@ -189,8 +197,11 @@ export const selectSidebarChildren = createSelector( | |
return children; | ||
} | ||
|
||
const childrenTree = next(activeWorkspace._id, false); | ||
return matchChildren(childrenTree); | ||
let pinnedChildren = []; | ||
const childrenTree = next(activeWorkspace._id, pinnedChildren); | ||
const matchedChildren = matchChildren(childrenTree); | ||
|
||
return { pinned: pinnedChildren, all: matchedChildren }; | ||
}, | ||
); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mac key comb should probably be
false, false, true, true
to map to Cmd+Shift+P because Cmd+P already maps to the request switcher. Windows/Linux one is fine though with what you have (Ctrl+Shift+P)