Skip to content

Commit

Permalink
explorer ui - v0 (#33) (#40)
Browse files Browse the repository at this point in the history
* explorer ui - v0

* tweaks

* fix id string split

* Load the c1z once per process, and share it and the store cache across requests

* grant expansion support, group resources by type

* ui redesign, node highlight, dark theme

* serve static html, add hidden dev mode flag for development

* lint error

* dashboard (#37)

* dashboard ui WIP

* dashboard inventory, misc fixes

* UI tweaks

* In non-dev mode, use embed to serve files instead of the filesystem. Build frontend as part of make.

* Commit built js so that go tests don't need npm to run.

* Serve up index.html for 404s.

---------

Co-authored-by: jakcinmarina <[email protected]>
Co-authored-by: Justin Gallardo <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 940df94 commit d528bc3
Show file tree
Hide file tree
Showing 862 changed files with 333,762 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ build/
# Dependency directories (remove the comment below to include it)
# vendor/
dist/

*.map
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ BUILD_DIR = dist/${GOOS}_${GOARCH}
OUTPUT_PATH = ${BUILD_DIR}/$(notdir $(CURDIR))

.PHONY: build
build:
build: frontend
rm -f ${OUTPUT_PATH}
mkdir -p ${BUILD_DIR}
go build -o ${OUTPUT_PATH} ./cmd/baton

.PHONY: frontend
frontend:
cd frontend && npm install && npm run build

.PHONY: update-deps
update-deps:
go get -d -u ./...
Expand All @@ -26,4 +30,4 @@ lint:

.PHONY: protogen
protogen:
buf generate
buf generate
115 changes: 115 additions & 0 deletions cmd/baton/explorer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package main

import (
"fmt"
"log"
"os"
"os/exec"

"github.com/conductorone/baton-sdk/pkg/dotc1z/manager"
"github.com/conductorone/baton/pkg/explorer"
"github.com/spf13/cobra"
)

func explorerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "explorer",
Short: "Run explorer UI in local browser",
RunE: runExplorer,
}

addResourceTypeFlag(cmd)
addSyncIDFlag(cmd)

cmd.Flags().Bool("dev", false, "Runs the frontend in development mode")
err := cmd.Flags().MarkHidden("dev")
if err != nil {
log.Default().Println("error marking dev flag hidden", err)
}

return cmd
}

func runNpmInstallAndStart(projectPath string) error {
installCmd := exec.Command("npm", "install")
installCmd.Stdout = os.Stdout
installCmd.Stderr = os.Stderr
installCmd.Dir = projectPath
if err := installCmd.Run(); err != nil {
return fmt.Errorf("error running 'npm install': %w", err)
}

startCmd := exec.Command("npm", "start")
startCmd.Stdout = os.Stdout
startCmd.Stderr = os.Stderr
startCmd.Dir = projectPath
if err := startCmd.Run(); err != nil {
return fmt.Errorf("error running 'npm start': %w", err)
}

return nil
}

func startFrontendServer() error {
err := runNpmInstallAndStart("frontend")
if err != nil {
return fmt.Errorf("error running npm start: %w", err)
}

return nil
}

func startExplorerAPI(cmd *cobra.Command, devMode bool) {
ctx := cmd.Context()

filePath, err := cmd.Flags().GetString("file")
if err != nil {
log.Fatal("error fetching file path", err)
}

syncID, err := cmd.Flags().GetString("sync-id")
if err != nil {
log.Fatal("error fetching syncID", err)
}

resourceType, err := cmd.Flags().GetString(resourceTypeFlag)
if err != nil {
log.Fatal("error fetching resourceType", err)
}

m, err := manager.New(ctx, filePath)
if err != nil {
log.Fatal("error creating c1z manager", err)
}
defer m.Close(ctx)

store, err := m.LoadC1Z(ctx)
if err != nil {
log.Fatal("error loading c1z", err) //nolint:gocritic // reason: in this case store is nil
}
defer store.Close()

ctrl := explorer.NewController(ctx, store, syncID, resourceType, devMode)
e := ctrl.Run(":8080")
if e != nil {
log.Fatal("error running explorer", err)
}
}

func runExplorer(cmd *cobra.Command, args []string) error {
isDevMode, err := cmd.Flags().GetBool("dev")
if err != nil {
return fmt.Errorf("error getting dev flag: %w", err)
}

if isDevMode {
go startExplorerAPI(cmd, isDevMode)
err = startFrontendServer()
if err != nil {
log.Fatal(err)
}
}
startExplorerAPI(cmd, isDevMode)

return nil
}
1 change: 1 addition & 0 deletions cmd/baton/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func main() {
cliCmd.AddCommand(dumpDBCmd())
cliCmd.AddCommand(syncsCmd())
cliCmd.AddCommand(optimizeDb())
cliCmd.AddCommand(explorerCmd())

err := cliCmd.ExecuteContext(ctx)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Loading

0 comments on commit d528bc3

Please sign in to comment.