Giter VIP home page Giter VIP logo

sapling's Introduction


Logo

Sapling

A convenient way to traverse your React application.
Explore the docs »

Report Bug · Request Feature

Visual Studio Marketplace Version Visual Studio Marketplace Installs GitHub Repo stars GitHub forks
master CI/CD workflow status dev CI workflow status Vercel Web deployments


Table of Contents
  1. About The Project
  2. Installation
  3. Getting Started
  4. Usage
  5. Extension Settings
  6. Contributing
  7. License
  8. Creators
  9. Contact
  10. Acknowledgements

About The Project



Sapling is a VS Code extension built with React developers in mind. As your codebase grows, your native file structure becomes less and less intuitive. Wouldn't it be nice to have a file structure that represents the actual relationships between the components and containers in your application? Wouldn't you like a quick reference to your available props, and an indication of routes and conditional rendering?

With Sapling, you don't have to guess at the parent component of your current file. Sapling is an interactive hierarchical dependency tree that lives directly within your VS Code IDE, as accessible as the native file system. You can build your tree by selecting any component file as the root and get information about the available props at any level. It also provides visual indication of Javascript syntax or import errors in your files, and shows you which components are connected to your Redux store.

Built With

Installation

Installing from VS Code Extension Marketplace:

  1. If needed, install Visual Studio Code for Windows (7+), macOS (Sierra+), or Linux (details).

  2. Install the Sapling extension for Visual Studio Code. Search for 'sapling' in the VS Code extensions tab, or click here.

  3. Once complete, you'll see Sapling appear in your sidebar. You can now begin using Sapling! Check out the Getting Started below for information on how to get started.

To install sapling for development, please see the contributing section below.

Getting Started

  1. After installing VSCode Extension, you will see the extension on your sidebar. Click the "Choose a File" button.

  2. Your file explorer window will launch. Select an entrypoint, a file where the parent component for the rest of your application is rendered.

  3. Your sidebar will now display a component tree.

Usage

After installing, click the Sapling tree icon in your extension sidebar (image of icon here). From there, you can either click "Choose a file" to select your root component, or build your tree directly from a file open in your editor with the "Build Tree" button on the right hand side of your status bar. Click the + and - buttons to expand and collapse subsets of your tree, and hover over the information icon (image of icon here) to get a list of props available to that component. You can also press the view file icon (image of icon here) to open the file where the component is defined in your editor window. Below is a quick-reference legend for icon and text format meanings. If you prefer not to view React Router or other third-party components imported to your app, you can disable either of these in the VS Code Extension Settings.

Icon Legend in Sapling Tree View:

  • available props (hover)
  • open file (click)
  • Redux store connection
  • Navbar: error in file (matches the error color of your theme)
  • Navbar: currently open file

Sapling can currently display React apps made with TSX/JSX and ES6 import syntax.

Sapling will detect React components invoked using JSX tag syntax and React-Router component syntax, where React is imported in a file:

    // Navbar will be detected as a child of the current file
    <Navbar />

    // As above
    <Navbar></Navbar>

    // Route and Navbar will be detected as child components of the current file
    <Route component={Navbar} />

    // Route and App will be detected as child components of the current file
    <Route children={App} />

Sapling will detect the names of inline props for JSX components it identifies:

    // props 'userId' and 'userName' will be listed for Navbar in Sapling
    <Navbar userId={...} userName={...} />

Sapling can identify components connected to the Redux store, when 'connect' is imported from 'react-redux', and the component is the export default of the file:

    // App.jsx
    import React from 'react';
    import { connect } from 'react-redux';

    const mapStateToProps = ...
    const mapDispatchToProps = ...

    const App = (props) => {
      return <h1>This is the App</h1>
    }

    // Sapling will detect App as connected to the Redux store
    export default connect(mapStateToProps, mapDispatchToProps)(App);

Note

Sapling prioritizes file dependencies over component dependencies. Consider the following JSX contained in the file App.jsx:

    //App.jsx
    import React from 'react';
    import Home from './Home';
    import Navbar from './Navbar';

    class App extends Component {

      render (
        return {
          <Home>
            <Navbar />
          </Home>
        })
    }

Sapling will display Home and Navbar as siblings, both children of App:


Contributor Usage

  1. Download/clone the project from Github
  2. Open the 'sapling' folder in your VS Code IDE. The outer 'sapling' folder must be the root folder in the workspace.
  3. Open sapling/src/extension.ts
  4. To view the webview, in your terminal navigate into the inner 'sapling' folder and run the following command: npm run watch
  5. Press F5. A new VSCode window will open with the Sapling Extension.
  6. Click the Sapling icon on the left to see the Sapling sidebar.

Note: Ctrl+R (or Cmd+R on Mac) will refresh the extension development host

Extension Settings

This extension contributes the following settings:

  • sapling.view.reactRouter: enable/disable React Router component nodes
  • sapling.view.thirdParty: enable/disable all third party component nodes

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Creators

Contact

Twitter: @TeamSapling | Email: [email protected]

GitHub: https://github.com/oslabs-beta/sapling/

Acknowledgements

sapling's People

Contributors

charlesgutwirth avatar hienqn avatar jboles31 avatar jo-cella avatar labaird avatar plcoster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sapling's Issues

Not support alias yet

Describe the bug
If I use alias in file, the extenstion fail to reach the file: Eg: @/component/index.tsx

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Installation fails with "Incompatible with VSCode v1.51.0" message

Describe the bug
VSCode installation fails with "Incompatible with VSCode v1.51.0" message

To Reproduce
Steps to reproduce the behavior:
Follow href="https://marketplace.visualstudio.com/items?itemName=team-sapling.sapling" Sapling.page on the VS Code Marketplace page at https://javascript.plainenglish.io/introducing-sapling-a-vs-code-extension-for-traversing-your-react-component-hierarchy-3ac94d95887e and click Install

Desktop (please complete the following information):

  • Windows11

Module not processed correctly if directory name in path contains "."

Steps to reproduce the behavior:

A. Module not recognized as file

  1. Load a js/ts file containing a static import statement where the source path contains one or more directories using "." in its name
    e.g. import { foo, bar } from '../example.directory/module';
  2. The imported live bindings show up on the Sapling tree as having been exported from non-files.

Screen Shot 2022-02-08 at 10 48 01

B. Input file node flagged as error

  1. Load js/ts file into Sapling that has a path containing one or more directories "." with in its name.
  2. Root node is flagged with error coloring (but open file icon is functional).

Screen Shot 2022-02-09 at 14 39 46

Expected behavior

File path parsing module handles this edge case correctly and icons for opening source files show up on the relevant Sapling tree nodes with no errors.

Desktop:

  • OS: Darwin Kernel Version 21.3.0; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101
  • Version: v1.2.0

Unable to locate components re-exported from barrel file

When generating a tree for a root component, sub-components that were imported from a barrel file are highlighted in red and their tree is not parsed.

Importing from barrel file:

CleanShot 2022-08-15 at 06 37 19

CleanShot 2022-08-15 at 06 35 53

Importing directly:

CleanShot 2022-08-15 at 06 36 33

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • vscode 1.70.0
  • React 17.0.1
  • Typescript 4.5.4

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Is it possible to get a highlight in the tree of the component that I am currently working on?

Is your feature request related to a problem? Please describe.
I would feel way more inclined to use Sapling more if it would actually highlight what component I am working on currently in the tree. This way I don't really need the regular file-tree anymore but can navigate quickly in the component hierarchy and constantly see what component I am working on. If it also can scroll me to that component in the tree automatically that would be even better.

Describe the solution you'd like
It should CLEARLY highlight (with background + bold text maybe) what component I am currently working on. It should also scroll the view for me to show me that component in the tree.

Getting Error on Opening Sapling extension

Describe the bug
Get this error when trying to click on extension in sidebar. It has always worked previously.

Rebooted macBook and uninstalled and installed multiple times.

Error loading webview: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..

MacBook MacOS 12.6
M1Max

Sapling hangs indefinitely when multiple instances of VSCode are open

Describe the bug
First off, thank you so much for creating this visualization, it's a life saver.

Bug: (maybe not) sapling processing hangs indefinitely when I attempt to generate a tree if more than one instance of VS Code is open (specifically, different projects are open).

It's something I rarely do, so it's not a big deal. Why I decided to post this is because I happened to have two VS Code instances open when I first installed sapling. I couldn't understand why I could see the sapling sidebar icon, the right-click menu 'generate tree' option, and the status bar 'build tree' option, but the hierarchy tree never generated.

To Reproduce
Steps to reproduce the behavior:

  1. Open two instances of VS Code (possibly need to be separate projects)
  2. Click on 'sapling icon', or 'right-click' generate tree, or click status bar 'build tree'
  3. See error

Expected behavior
Sapling sidebar doesn't open when choosing 'generate tree' or 'build tree'. Hierarchy tree doesn't generate/render when sidebar sapling icon is clicked. Notice when the sapling side bar is open, under VS Code '"Sidebar" title, the scrolling graphic renders (left to right) as if it's thinking about it (i.e., still processing).

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Versions: latest sapling and latest stable VS Code

Thanks again for providing a great React tool, keep up the good work!

Does not work with React.lazy imports

Describe the bug
Components imported with React.lazy are not shown in the tree

To Reproduce

const Page1 = lazy(() => import('./pages/page1'));
import Page2 from './pages/page2';

export default function Routes() {
  return (
      <Switch>
        <Suspense fallback={<div></div>}>
          <Route exact path='/' component={Page1} />
          <Route exact path='/profile' component={Page2} />
        </Suspense>
      </Switch>
  );
}

only Page2 is shown in the component tree

Expected behavior
I expect Page1 to be shown as well

Desktop (please complete the following information):

  • OS: OSX 11.5.2

Work with the Remote - SSH extension

Hi,

As far as I can tell, Sapling doesn't work with Microsoft's extension for developing on remote hosts via SSH (Remote - SSH). Specifically, Sapling opens a file selection dialog for the local host's filesystem:

vscode

Please consider expanding Sapling to allow selection of a file on the remote host.

Add collapse / expand all

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Add a collapse / expand buttons or or at least "collapse all" similar to the explorer panel

Screen Shot 2021-11-01 at 11 11 54

Sapling doesn't show up in development mode

Describe the bug
Trying to see if I can add a few features. Unfortunately the Icon didn't show up after running npm run watch, even though the code is compiled successfully.

To Reproduce
Just follow the instruction steps on readme.md

Support openning files in WSL/WSL2 enviornments

Is your feature request related to a problem? Please describe.
Sapling UI can be loaded in a WSL2 aligned workspace, however clicking to open a file to analyze always opens up a linked to the Windows file system which isn't useful if working in a pure Linux file system on WSL.

Describe the solution you'd like
Would like to have the Choose a file... button to open relative to the project, and if in WSL/WSL2 open relative to that environment.

Describe alternatives you've considered
Users could work around this by having projects live on the Windows file system instead of internal to the WSL/WSL2 Linux file system, but with WSL2 in particular this creates slow performance on builds which is likely not a worthwhile trade-off.

Additional context
None

Components exported with "export * from ..." are shown in error in the drawer

Hi, first off thanks for maintaining this really useful extension. I came accross this behaviour :

If your root file imports a child component from an index file that does export * from ..., then the child component appears red in the tree view and you can't expand it.

You can reproduce the issue with the following project :

Folder structure :

App.tsx
home/
├─ index.ts
├─ Home.tsx

Home.tsx :

export const Home = () => (<></>);

index.ts :

export * from './Home';

App.tsx :

import { Home } from './home';
export const App = () => (<Home />);

With this project if you select App.tsx as the root file in sapling then Home appears red and you can't expand it.

I get the issue on the latest version of vscode on Windows.

Thanks

Support for NextJS

Is your feature request related to a problem? Please describe.

  • No it isn't, it's more of a feature extension

Describe the solution you'd like

  • If sapling could support react based frameworks like nextjs, that would be great. This is an amazing tool to have when going through code, especially when working on ongoing projects.

Incompatible with 1.56.2

Describe the bug
Incompatibility with VS Code version 1.56.2.

To Reproduce
Install

Expected behavior
Gets Installed

Screenshots
image

Desktop (please complete the following information):

  • OS: iOS

Not able to traverse more than 1 level of hierarchy

Describe the bug
Sapling is not able to traverse more than one level of my component tree. I have tried it on several of my projects.

To Reproduce
Steps to reproduce the behavior:

  1. Clone this repo: https://github.com/PublicisSapient/accelerated-news
  2. Choose the file src/App.tsx
  3. You will see that only the top level children are shown.

CleanShot 2021-10-11 at 19 34 24@2x

I thought maybe this is because the pages are embedded in routes. So I tried the same thing with a single page: src/Pages/SignUpPage/SignUpPage.tsx. This is what I got:

CleanShot 2021-10-11 at 19 41 44@2x

Note that traversal stopped at TextField, even though there are components under that.

Expected behavior
Full traversal of the component tree.

Screenshots
See above.

Desktop (please complete the following information):

  • OS: [e.g. iOS] MacOS
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] 94

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Redux hooks support

Is your feature request related to a problem? Please describe.

  • Current "Connected to Redux Store" icon implementation only detects connect() function calls, and does not recognize redux hooks.
  • Redux hooks have superseded connect API as the default approach recommended by the react-redux library.

Describe the solution you'd like

  • Display redux store icon for files that use redux hooks:
    1. Check for redux hooks imports.
    2. Check for redux hooks invocation(s).
    3. Check for selector/dispatch/store instance invocation(s). (optional?)

Describe alternatives you've considered
N/A

Additional context

  • Example screenshot:
    Redux store data is being extracted into the component, and redux actions are being dispatched to store, but redux store icon doesn't show up on Sapling tree.

example screenshot

I'd be willing to take a stab at this if it doesn't interfere with core team's plans.

Might a click on component name in the Sapling tree open its code instead of/in addition to a click on the nav button

The Sapling tree is a great way of organising your component tree in VSCode for convenient access. I've been absolutely delighted with it but have one complaint. Whenever I want to open a component I find myself automatically clicking the component name rather than the (near invisible) Nav button

Would it be possible to make a click on a component name open its code instead of/as well as a click on the Nav button?

Keyboard navigation

Is your feature request related to a problem? Please describe.
Currently there is no way to navigate in the tree using the keyboard.

Describe the solution you'd like
Allow navigating in the tree using the keyboard similar to the explorer panel . Up / down moves the focus from file to file. Left / right also opens inner folders

Additional context
I believe that if you'd use the built-in TreeViewProvider you'd get that out of the box as long as more vscode natively experience :)

Thanks

Traverse over active file instead of picking one from the extension panel

When traversing a file that is not the top component in the hierarchy I have to pick a new one in order to inspect it.

So, I would suggest to rather automatically traverse the file I have in open in the active editor.

As an alternative it could be that it can let you pick a file in the current project with a dialog similar to the file switcher dialog of the VSCode editor, that could also be handy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.