Skip to content

Repository Remove menu label now indicates if it will show a dialog - #6489

Closed
Daniel-McCarthy wants to merge 3 commits into
desktop:developmentfrom
Daniel-McCarthy:Update-Repo-Remove-Dialog-Indicator
Closed

Daniel-McCarthy wants to merge 3 commits into
desktop:developmentfrom
Daniel-McCarthy:Update-Repo-Remove-Dialog-Indicator

Conversation

@Daniel-McCarthy

Copy link
Copy Markdown
Member

Overview

Closes #4976

Description

  • The "Remove" menu label under the Repository category will now display as "Remove..." if it will result in a dialog opening. The dialog can be enabled and disabled in the options.

Before changes (With dialog enabled):
image

After changes (With dialog enabled):
image

Release notes

Notes: The Repository Remove menu label now indicates if it will open a dialog.

Previously the menu label Repository>Remove would not display the dialog indicator "...".

If the user has the setting enabled for a dialog to be shown the indicator will be displayed, however if it is disabled it will not have the "...".

@shiftkey shiftkey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, one suggestion to leverage our baked parsing rules for local storage.

I'm now wanting to tidy up this area because it's kind of organically grown complex, but I'll write that up as a future issue.

Comment thread app/src/lib/stores/app-store.ts Resolved
@shiftkey

Copy link
Copy Markdown
Member

Also, this failing test is interesting - not sure what we want to do here:

Summary of all failing tests
 FAIL  app/test/unit/git/remote-test.ts
  ● git/remote › getRemotes › should return both remotes
    TypeError: Cannot read property 'origin' of undefined
      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:256:26)
      at AppStore.getRemoveRepoLabel (app/src/lib/stores/app-store.ts:36100:90)
      at AppStore.updateMenuItemLabels (app/src/lib/stores/app-store.ts:36053:35)
      at AppStore._refreshRepository (app/src/lib/stores/app-store.ts:36729:14)

@shiftkey shiftkey self-assigned this Dec 27, 2018
This simplifies the code necessary to get the repository removal boolean and makes use of a helper function that was not previously being used.
@Daniel-McCarthy

Daniel-McCarthy commented Dec 27, 2018 •

Copy link
Copy Markdown
Member Author

Ah, sorry. I had not realized that the tests had failed until today.
Thank you for the feedback!

This failing test is additionally strange to me as the test was passing locally for me after making the suggested changes, however is not when the test runs on the remote. I will have to keep looking into this.

@shiftkey

shiftkey commented Dec 27, 2018 •

Copy link
Copy Markdown
Member

This failing test is additionally strange to me as the test was passing locally for me after making the suggested changes, however is not when the test runs on the remote.

I'm also seeing it fail locally, and I'll try and add some more context as it why this is interesting:

  • adding getRemoveRepoLabel now adds an implicit dependency to having a localStorage global (aka window.localStorage) being set when executing JS. This is fine when the app is running, but we want our tests to avoid dependencies to global state.
  • a different test is failing on my local machine, but with the exact same stack trace
 FAIL  app/test/unit/git/gitignore-test.ts
  ● gitignore › readGitIgnoreAtRoot › reads contents from disk

    TypeError: Cannot read property 'origin' of undefined

      3 |  * boolean or the provided `defaultValue` if the key doesn't exist.
      4 |  *
    > 5 |  * @param key local storage entry to find
        |                   ^
      6 |  * @param defaultValue fallback value if key not found
      7 |  */
      8 | export function getBoolean(key: string): boolean | undefined

      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:256:26)
      at Object.getBoolean (app/src/lib/local-storage.ts:5:19)
      at AppStore.getRemoveRepoLabel (app/src/lib/stores/app-store.ts:915:54)
      at AppStore.updateMenuItemLabels (app/src/lib/stores/app-store.ts:894:35)
      at AppStore._refreshRepository (app/src/lib/stores/app-store.ts:1204:14)
  • this test doesn't explicitly call AppStore._refreshRepository, so chances are a different test for someone else might trigger this same error (or maybe you're lucky enough to not see it)
  • as part of add a localStorage abstraction to tidy up our parsing work #5979 we added tests for interacting with localStorage and we encountered the same problem
  • we fixed this by adding jest-localstorage-mock as a dependency and initialising that as part of setting up the test suite - we didn't have to do any more setup
  • given the lack of any test code in the stack trace, my feeling is that something is running a setInterval/setTimeout to trigger a AppStore._refreshRepository outside a test run, and this fails because jsdom hasn't been initialised correctly

@outofambit
outofambit changed the base branch from master to development December 27, 2018 21:45
@shiftkey

shiftkey commented Jan 8, 2019

Copy link
Copy Markdown
Member

Alright, I've narrowed down the issue but don't really have a solution just yet.

Here's what's happening:

  • jest runs the setup-test-framework.ts which stubs the local storage mock (test environments are sandboxed)

// set test timeout to 10s
jest.setTimeout(10000)
import 'jest-localstorage-mock'

  • this AppStore test is the one affected by this PR change

it('can select a repository', async () => {
const appStore = await createAppStore()
const repo = await setupEmptyRepository()
await appStore._selectRepository(repo)
const state = appStore.getState()
expect(state.selectedState).is.not.null
expect(state.selectedState!.repository.path).to.equal(repo.path)
})

  • Inside AppStore._selectRepository() is an AppStore._refreshRepository() which is not await-ed. I believe we did this because we didn't want to block and wait for the function to complete before continuing, but we can dig into that later

this._refreshRepository(repository)

  • AppStore._selectRepository() completes and the test passes

  • jest tears down the local storage mock because it believes the test is completed

  • some time later, AppStore._refreshRepository() reaches the AppStore.updateMenuItemLabels function which depends on local storage

this.updateMenuItemLabels(repository)

  • this fails because the test completed earlier and there's no global environment for the local storage

@shiftkey

Copy link
Copy Markdown
Member

Dropping myself from reviewing this issue because I haven't had a chance to come back to this, but I think await-ing on this action is the only way to ensure the correct behaviour of the problem test:

this._refreshRepository(repository)

There's potentially some side effects (_refreshRepository queries the underlying Git repository and updates a lot of local state) that we need to be mindful of as part of this change.

In the meantime I've merged development and the changes from #6228 to confirm this still needs work.

@shiftkey shiftkey removed their assignment Jan 24, 2019
@billygriffin

Copy link
Copy Markdown
Contributor

Just following up here. It's a bit hard for me to follow the discussion, but it feels like maybe the complexity potentially introduced here might not be worth the payoff and maybe we should close the PR and issue? If we left it as is, we wouldn't be communicating as much information up front, but removing a repo shouldn't be a super common occurrence and my understanding is that the current behavior will still respect the user's preferences.

Thoughts @shiftkey?

@shiftkey

shiftkey commented Mar 8, 2019

Copy link
Copy Markdown
Member

I'm tentatively 👎 to closing the issue because we've made our context menus follow this pattern when they know a dialog will appear on click:

At the moment this PR is blocked on being able to apply this change, because of how it impacts unit tests. Any objections to me updating #4976 to refer to this PR, summarizing the issue and closing out this PR? cc @Daniel-McCarthy

@Daniel-McCarthy

Daniel-McCarthy commented Mar 8, 2019 •

Copy link
Copy Markdown
Member Author

@shiftkey @billygriffin I am definitely fine with closing out this pull request as it is currently blocked, and the scope involved with fixing the outlying issues would not likely be something that is quite in my domain as of yet.

I would tend to agree with @shiftkey that adding the relevant information to the issue and keeping it open would be a good idea, as well as closing this pull request as it is not likely to be moving forward quite soon.

@billygriffin

Copy link
Copy Markdown
Contributor

Works for me, thanks y'all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Remove" default menu item needs to be aware of user preference

3 participants