This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 973
Removes non-primitive types from NavigationBar #9792
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ const frameStateUtil = require('../state/frameStateUtil') | |
const ipc = require('electron').ipcRenderer | ||
const messages = require('../constants/messages') | ||
const debounce = require('../lib/debounce') | ||
const getSetting = require('../settings').getSetting | ||
const {getSetting} = require('../settings') | ||
const UrlUtil = require('../lib/urlutil') | ||
const {l10nErrorText} = require('../../app/common/lib/httpUtil') | ||
const { makeImmutable } = require('../../app/common/state/immutableUtil') | ||
|
@@ -23,6 +23,8 @@ const assert = require('assert') | |
const contextMenuState = require('../../app/common/state/contextMenuState') | ||
const appStoreRenderer = require('./appStoreRenderer') | ||
const windowActions = require('../actions/windowActions') | ||
const siteUtil = require('../state/siteUtil') | ||
const siteTags = require('../constants/siteTags') | ||
|
||
let windowState = Immutable.fromJS({ | ||
activeFrameKey: null, | ||
|
@@ -750,6 +752,22 @@ const doAction = (action) => { | |
} | ||
break | ||
} | ||
case windowConstants.WINDOW_ON_TOGGLE_BOOKMARK: | ||
{ | ||
// show the AddEditBookmarkHanger control; saving/deleting takes place there | ||
const activeFrame = frameStateUtil.getActiveFrame(windowState) | ||
let siteDetail = siteUtil.getDetailFromFrame(activeFrame, siteTags.BOOKMARK) | ||
const key = siteUtil.getSiteKey(siteDetail) | ||
|
||
if (key !== null) { | ||
const site = appStoreRenderer.state.getIn(['sites', key], Immutable.Map()) | ||
siteDetail = siteDetail.set('parentFolderId', site.get('parentFolderId')) | ||
siteDetail = siteDetail.set('customTitle', site.get('customTitle')) | ||
} | ||
siteDetail = siteDetail.set('location', UrlUtil.getLocationIfPDF(siteDetail.get('location'))) | ||
windowActions.setBookmarkDetail(siteDetail, siteDetail, null, action.isBookmarked, true) | ||
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. This is definitely something we want to avoid (calling an action in the handler for an action). If it can't be avoided, I think it would be preferable to call
cc: @bridiver 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. Yeah, we want to remove this, but sadly we need to keep it for now. You will see this pattern in other PR's as well. For this particular case we will remove it in #9710, because we will remove |
||
break | ||
} | ||
default: | ||
break | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this logic here would be better if it was contained inside
siteUtil.getDetailFromFrame
method, IMO (especially since it can be tested). There are other places that call this method and they too should be having the parentFolderId and customTitle set (in fact, if the other calls are not setting this, it may be causing a bug / bugs)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.
Not sure why this logic should be in
siteUtil.getDetailFromFrame
. In thisif
statement we are getting data fromappStore
and adding them to thesiteDetail
. Not sure where else would we be using this? We use this function in 13 different places. We only want to accessappStore
in reducers and not in components.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.
the data it gets from
appStore
is the site which matches...getDetailFromFrame
should be returning the entry from the sites map (which is whatsiteUtil
does; it's the wrapper around the sites map which is stored inappStore
)In this case,
getDetailFromFrame
is just taking data from the frame and returning it (without transforming it)... rather than doing a lookup and fetching the already existing one. This code here then copies the data from the existing one (which is a mistake IMO, since it could have just used the existing reference)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.
Here's a quick explanation of why this is a problem:
if you remove this line:
siteDetail = siteDetail.set('parentFolderId', site.get('parentFolderId'))
The code would then create a NEW sites entry (which is wrong). The reason why it creates a new one is because the key has the folderId in it. The windowStore shouldn't care about this logic- it should just use the object it gets back. Instead, we are having business logic in the windowStore about a siteDetails entry to avoid a bug (instead of returning an existing reference- the one which the key matches)
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.
this would fix the problem, although it's a little more sloppy:
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.
Not sure that we can to that, because now in your example you overrode sites from window state, which means that bookmark will not have favicon, tags, themeColor etc. It will only haveparentFolderId
,title
andcustomTitle
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.
we are only missing
parentFolderId
in this example, I just checked and everything else is there. But I think this whole PR, will be redundant when I do #9710 😃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.
that's true- maybe it's OK as-is (for this PR) and that would be the place to tackle it 😄
The example above should have everything (including
parentFolderId
). In the current code, whatever is found is copied from appState. So instead of copying it, just use the entire object (which like you said, has favicon, tags, themeColor, etc). This is great because if we needed to expose those we could. By not using the real object, we're opening ourselves up to bugs. For example, what ifparentFolderId
is changed toparentDirectoryId
. If we properly handled it, we'd only need to update insiteUtil
. But because this code is copying the object, we'd have to update in 2 (or more) places