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

GEP-161 Add example/blueprint about how to setup multiple independent flex-layout manager in an app #542

Merged
merged 9 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions examples/multiple-layout-manager-playground/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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*

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
51 changes: 51 additions & 0 deletions examples/multiple-layout-manager-playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Getting Started with Create React App

This project was bootstrapped with [Vite](https://vitejs.dev/guide/) using React template.

To start develop, you need to setup yalc to link geppetto libraries to the current project.

To do so, run

```
yarn install && yarn link:yalc
```
# Project Description

The Multiple Layout Manager Playground enables the creation of one or more workspaces, providing a flexible environment for managing various layouts.

## Available Scripts

You can run the project in dev or preview mode using `yarn dev` and `yarn preview`.
To build the project, use `yarn build`.

Here is a description of what each command is doing.

### `yarn dev`

Runs the app in the development mode.
Open [http://localhost:5143](http://localhost:5143) to view it in the browser (the port might be different on your machine, check the logs displayed by vite to be sure you are targeting the right address).

The page will reload if you make edits.
You will also see any lint errors in the console.

If you are developping at the same time on any of the geppetto.js lib (core, ui, client), you can run:

```
bash watch-geppettojs-updates.sh
```

This command will launch a `watch` on all the geppetto.js libraries and hot-reload the application if any of the source code of those dependencies changes.


### `yarn preview`

Runs the app in preview mode.
This means that a local webserver is launched to serve the app, but hot-reloading is not avaiable and the application is served from the `dist` directory where the application have been compiled/built.


### `yarn build`

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

Your app is ready to be deployed!
71 changes: 71 additions & 0 deletions examples/multiple-layout-manager-playground/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import json from 'eslint-plugin-json'


export default tseslint.config(
{ ignores: [
'dist',
'node_modules',
'.yalc',
'src/rest/*' // do not lint generated code
] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx,js,jsx}'],
languageOptions: {
ecmaVersion: "latest",
globals: globals.browser,
sourceType: "module"
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
indent: ["error", 2, {
SwitchCase: 1,
}],
curly: "error", // enforce braces for one-line blocks
"no-tabs": "error", // enforce no tabs
"no-console": ["warn", {
allow: ["warn", "error", "debug"],
}],
"consistent-return": "warn", // https://eslint.org/docs/latest/rules/consistent-return
"prefer-arrow-callback": ["warn"],
"object-curly-spacing": ["warn", "always"], // enforce consistent spacing inside braces
"func-style": "off", // function expressions or arrow functions are equally valid
"no-unneeded-ternary": "warn", // disallow unnecessary ternary expressions
// React rules: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules
"react/prop-types": "off", // PropTypes are not forced
"react/forbid-prop-types": "off", // all PropTypes are allowed
"react-hooks/rules-of-hooks": "error", // https://react.dev/reference/rules/rules-of-hooks
"react-hooks/exhaustive-deps": "warn", // Hooks dependency array, sometimes it's better to ignore
},
},
{ // Linting for tsconfig.json files allows comments
files: ["tsconfig*.json"],
plugins: { json },
processor: "json/json",
rules: {
...json.configs["recommended-with-comments"].rules,
}
},
{ // Linting for *.json files do now allow comments
files: ["**/*.json"],
ignores: ["tsconfig*.json"],
plugins: { json },
processor: "json/json",
rules: {
...json.configs.recommended.rules,
}
}
)
15 changes: 15 additions & 0 deletions examples/multiple-layout-manager-playground/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="manifest" href="/manifest.json" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#000000" />
<title>Geppetto Multiple Layout Manager Playground</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
62 changes: 62 additions & 0 deletions examples/multiple-layout-manager-playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "multiple-layout-manager-playground",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"prepare": "yarn link:yalc",
"link:yalc": "yalc link @metacell/geppetto-meta-core && yalc link @metacell/geppetto-meta-ui && yalc link @metacell/geppetto-meta-client",
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fortawesome/fontawesome-free": "^6.4.0",
"@material-ui/core": "^4.11.4",
"@metacell/geppetto-meta-client": "^2.0.0",
"@metacell/geppetto-meta-core": "^2.0.0",
"@metacell/geppetto-meta-ui": "^2.0.0",
"@mui/icons-material": "^5.14.0",
"@mui/material": "^5.14.0",
"@reduxjs/toolkit": "^2.2.7",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.38",
"file-saver": "^2.0.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-redux": "^7.2.0",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.9.0",
"eslint-plugin-json": "^4.0.1",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"sass": "^1.32.12",
"typescript": "^5.5.4",
"typescript-eslint": "^8.4.0",
"vite": "^5.4.3",
"yalc": "^1.0.0-pre.53"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"short_name": "Layout Manager Playground",
"name": "Simple App Playground for Layout Manager",
"icons": [],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions examples/multiple-layout-manager-playground/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/multiple-layout-manager-playground/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Trick to have folder relative to the script, not CWD
PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "${PARENT_PATH}"

# Install the libraries (if not already installed)
GEPPETTO_JS="../../geppetto.js"
(bash "${GEPPETTO_JS}/dev-install.sh")

yarn install
70 changes: 70 additions & 0 deletions examples/multiple-layout-manager-playground/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { ThemeProvider, createTheme } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import { Provider } from 'react-redux';
import HomePage from "./pages/HomePage";
import { useState } from 'react';
import { Workspace } from './workspace';
import { Box } from '@mui/material';

const darkTheme = createTheme({
palette: {
mode: 'dark',
},
});

function App() {
const [workspaces, setWorkspaces] = useState<Record<string, Workspace>>({});
const [selectedWorkspacesIds, setSelectedWorkspacesIds] = useState<Set<string>>(new Set<string>());

const updateWorkspace = (workspace: Workspace) => {
setWorkspaces((prev) => ({
...prev,
[workspace.id]: workspace,
}));
};

const createWorkspace = (id: string, name: string) => {
const newWorkspace = new Workspace(id, name, updateWorkspace);
setWorkspaces((prev) => ({ ...prev, [id]: newWorkspace }));
};

const handleCreateClick = () => {
const workspaceId = `workspace-${Date.now()}`;
const workspaceName = `Workspace ${Object.keys(workspaces).length + 1}`;

createWorkspace(workspaceId, workspaceName);
setSelectedWorkspacesIds(prevSelectedIds => {
const updatedSet = new Set(prevSelectedIds);
updatedSet.add(workspaceId); // Add the new workspace ID
return updatedSet;
});
};

const renderCompareMode = (workspaceIds: string[]) => (
<Box sx={{ display: "grid", gridTemplateColumns: "auto auto" }}>
{workspaceIds.map((id) => (
<Provider key={id} store={workspaces[id].store}>
<HomePage />
</Provider>
))}
</Box>
);

const renderWorkspaces = () => {
return renderCompareMode(Array.from(selectedWorkspacesIds));
};

return (
<ThemeProvider theme={darkTheme}>
<CssBaseline />
<div className="App">
<header className="App-header">
<button onClick={handleCreateClick} style={{ margin: "10px" }}>Create workspace</button>
{renderWorkspaces()}
</header>
</div>
</ThemeProvider>
);
}

export default App;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FC } from 'react';

// Define the props type for MyComponent
type MyComponentProps = {
name: string;
color: string;
};

// Define MyComponent as a functional component
const MyComponent: FC<MyComponentProps> = ({ name, color }) => {
return <h1 style={{ width: "100%", backgroundColor: color }}>{name}</h1>;
};

export default MyComponent;
Loading