Skip to content
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

feat: Nx Move and Remove Project in Context Menu #1256

Merged
merged 5 commits into from
Apr 20, 2022

Conversation

ZackDeRose
Copy link
Member

Hey @Cammisuli - wanted to get your thoughts on this approach before going too far in.

You can see the code for yourself, but the idea here is:

  • we'd add the move VsCode command
  • we determine the appropriate move generator (given the URI [stubbed out for now - always does workspace:move])
  • add additional optional parameters to allow this move generator to 'drill down' our existing API

I'm not a fan of the amount of "drilling" this approach takes, but I think it is the minimally invasive approach given our current state. (eventually it'd be nice to rework some of our APIs like we've discussed)

@ZackDeRose ZackDeRose self-assigned this Mar 4, 2022
@nx-cloud
Copy link

nx-cloud bot commented Mar 4, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit e89a9e4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

Copy link
Member

@Cammisuli Cammisuli left a comment

Choose a reason for hiding this comment

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

I just took a quick look, and I see what you mean about the drilling down 😅 that WebView function is doing too much.

Either way, there's a few comments I have as well 😄

"group": "2_workspace"
},
{
"when": "!isNxWorkspace && config.nxConsole.enableGenerateFromContextMenu",
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to use isAngularWorkspace here.

Suggested change
"when": "!isNxWorkspace && config.nxConsole.enableGenerateFromContextMenu",
"when": "isAngularWorkspace && config.nxConsole.enableGenerateFromContextMenu",

@@ -67,6 +75,20 @@ export function registerCliTaskCommands(
selectCliCommandAndPromptForFlags('run', await getCliProjectFromUri(uri))
);

commands.registerCommand(`${cli}.move.fileexplorer`, async (uri: Uri) => {
const getCorrectMoveGenerator = (uri: Uri) => '@nrwl/workspace:move';
Copy link
Member

Choose a reason for hiding this comment

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

We could probably find out the minimum version of Nx that introduced this generator and have that logic here. We have this function here that could be exported and used outside that project:

export function nxVersion(): number | null {

Copy link
Member Author

Choose a reason for hiding this comment

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

Oooh, hadn't considered that. Good point.

For versions younger than we had the move/remove generators, we should probably remove this option from the context menu, right?

Copy link
Member Author

@ZackDeRose ZackDeRose Mar 5, 2022

Choose a reason for hiding this comment

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

Similar note: for when the user right-clicks on a node in the root, my solution would open the webview for the @nrwl/workspace:move generator; without a project set.

I think this is problematic, since we should be using the @nrwl/angular:move generator if the project is ends up being angular :\

@ZackDeRose
Copy link
Member Author

@Cammisuli updates:

  • Added logic for getting the correct generator (choose angular/move if installed, otherwise workspace/move) [comments added for future problems with this]
  • Removed this context menu item for Angular CLI workspaces (move and remove only work for nx projects as I understand it)
  • Added a version check to not add it for older nx versions.
  • Left the "Nx Move...." option in the context menu even when not clicking on a project (this will open the generator webview WITHOUT a project set. I think this is probably the best solution, but I could see a valid argument for removing it unless you click on a project as well.)

Taking off the WIP, lmk if anything looks like it's missing!

@ZackDeRose ZackDeRose changed the title WIP: Nx Move Project in Context Menu [checking approach for Jon's thoughts] feat: Nx Move and Remove Project in Context Menu Apr 10, 2022
@AgentEnder
Copy link
Member

AgentEnder commented Apr 19, 2022

In regards to the @nrwl/angular:move vs @nrwl/workspace:move point, there's also the case of community plugin projects which may require their move generator. e.g., I'm about to add a move generator to nx-dotnet to handle updating .csproj file paths in addition to moving the files ( see nx-dotnet/nx-dotnet#406 ).

Do you think we could check for all installed plugins that have a generator called move, and prompt the user to choose between them?

@ZackDeRose ZackDeRose merged commit ebc2a9c into master Apr 20, 2022
@ZackDeRose ZackDeRose deleted the zack/wip-move-context-menu branch April 20, 2022 18:53
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.

None yet

3 participants