-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ledger-browser): refactor routing, improve UI
- Add dynamic routing based on configuration instead of hardcoded one. - Add MUI and configure custom theme. Use this new UI kit to create app better bar and ledger selector. - Cleanup common application code. - Add sample SQL data to quickly test the GUI without running persistence plugins. Signed-off-by: Michal Bajer <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,615 additions
and
579 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ This component allows viewing ledger data in Supabase or other postgreSQL compat | |
## Remarks | ||
|
||
- Plugin requires running Supabase or other database and persistence plugins in order to properly view ledger data. | ||
- Currently, fabric and ethereum based ledgers are supported. | ||
- Currently, fabric and ethereum based ledgers are supported. | ||
|
||
## Getting Started | ||
|
||
|
@@ -31,6 +31,7 @@ In the root of the project, execute the command to install and build the depende | |
```sh | ||
yarn run build | ||
``` | ||
|
||
### Alternative Prerequisites using npm | ||
|
||
In the root of the project, execute the command to install and build the dependencies. It will also build this GUI front-end component: | ||
|
@@ -40,14 +41,25 @@ npm install | |
``` | ||
|
||
### Usage | ||
|
||
- Run Supabase instance (see documentation for detailed instructions). For development purposes, you can use our image located in `tools/docker/supabase-all-in-one`. | ||
- Run one or more persistence plugins: | ||
- [Ethereum](../cacti-plugin-persistence-ethereum) | ||
- [Fabric] (../cacti-plugin-persistence-fabric) | ||
- [Ethereum](../cacti-plugin-persistence-ethereum) | ||
- [Fabric] (../cacti-plugin-persistence-fabric) | ||
- Edit [Supabase configuration file](./src/supabase-client.tsx), set correct supabase API URL and service_role key. | ||
- Execute `yarn run start` or `npm start` in this package directory. | ||
- The running application address: http://localhost:3001/ (can be changed in [Vite configuration](./vite.config.ts)) | ||
|
||
#### Sample Data | ||
|
||
- To preview the GUI without running the persistence plugins you can use historic sample data located at `packages/cacti-ledger-browser/src/test/sql/sample-data.sql`. | ||
- Use `psql` tool to import it to your supabase postgres DB instance. | ||
- example: | ||
|
||
```bash | ||
psql "postgres://postgres.DB_NAME:[email protected]:5432/postgres" -f src/test/sql/sample-data.sql | ||
``` | ||
|
||
## Contributing | ||
|
||
We welcome contributions to Hyperledger Cacti in many forms, and there’s always plenty to do! | ||
|
@@ -58,4 +70,4 @@ Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started. | |
|
||
This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file. | ||
|
||
## Acknowledgments | ||
## Acknowledgments |
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
121 changes: 121 additions & 0 deletions
121
packages/cacti-ledger-browser/src/main/typescript/CactiLedgerBrowserApp.tsx
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { useRoutes, BrowserRouter, RouteObject } from "react-router-dom"; | ||
import CssBaseline from "@mui/material/CssBaseline"; | ||
import { ThemeProvider, createTheme } from "@mui/material/styles"; | ||
|
||
import { themeOptions } from "./theme"; | ||
import ContentLayout from "./components/Layout/ContentLayout"; | ||
import HeaderBar from "./components/Layout/HeaderBar"; | ||
import WelcomePage from "./components/WelcomePage"; | ||
import { AppConfig, AppListEntry } from "./common/types/app"; | ||
import { patchAppRoutePath } from "./common/utils"; | ||
|
||
type AppConfigProps = { | ||
appConfig: AppConfig[]; | ||
}; | ||
|
||
/** | ||
* Get list of all apps from the config | ||
*/ | ||
function getAppList(appConfig: AppConfig[]) { | ||
const appList: AppListEntry[] = appConfig.map((app) => { | ||
return { | ||
path: app.path, | ||
name: app.name, | ||
}; | ||
}); | ||
|
||
appList.unshift({ | ||
path: "/", | ||
name: "Home", | ||
}); | ||
|
||
return appList; | ||
} | ||
|
||
/** | ||
* Create header bar for each app based on app menuEntries field in config. | ||
*/ | ||
function getHeaderBarRoutes(appConfig: AppConfig[]) { | ||
const appList = getAppList(appConfig); | ||
|
||
const headerRoutesConfig = appConfig.map((app) => { | ||
return { | ||
key: app.path, | ||
path: `${app.path}/*`, | ||
element: ( | ||
<HeaderBar | ||
appList={appList} | ||
path={app.path} | ||
menuEntries={app.menuEntries} | ||
/> | ||
), | ||
}; | ||
}); | ||
headerRoutesConfig.push({ | ||
key: "home", | ||
path: `*`, | ||
element: <HeaderBar appList={appList} />, | ||
}); | ||
return useRoutes(headerRoutesConfig); | ||
} | ||
|
||
/** | ||
* Create content routes | ||
*/ | ||
function getContentRoutes(appConfig: AppConfig[]) { | ||
const appRoutes: RouteObject[] = appConfig.map((app) => { | ||
return { | ||
key: app.path, | ||
path: app.path, | ||
children: app.routes.map((route) => { | ||
return { | ||
key: route.path, | ||
path: patchAppRoutePath(app.path, route.path), | ||
element: route.element, | ||
children: route.children, | ||
}; | ||
}), | ||
}; | ||
}); | ||
|
||
// Include landing / welcome page | ||
appRoutes.push({ | ||
index: true, | ||
element: <WelcomePage />, | ||
}); | ||
|
||
return useRoutes([ | ||
{ | ||
path: "/", | ||
element: <ContentLayout />, | ||
children: appRoutes, | ||
}, | ||
]); | ||
} | ||
|
||
const App: React.FC<AppConfigProps> = ({ appConfig }) => { | ||
const headerRoutes = getHeaderBarRoutes(appConfig); | ||
const contentRoutes = getContentRoutes(appConfig); | ||
|
||
return ( | ||
<div> | ||
{headerRoutes} | ||
{contentRoutes} | ||
</div> | ||
); | ||
}; | ||
|
||
const theme = createTheme(themeOptions); | ||
|
||
const CactiLedgerBrowserApp: React.FC<AppConfigProps> = ({ appConfig }) => { | ||
return ( | ||
<BrowserRouter> | ||
<ThemeProvider theme={theme}> | ||
<CssBaseline /> | ||
<App appConfig={appConfig} /> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
}; | ||
|
||
export default CactiLedgerBrowserApp; |
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
Oops, something went wrong.