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

Support new React Interface #44

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9b5ef2e
Add basic react / mantine setup
SchrodingersGat Sep 30, 2024
83b14f3
Provide render context to panel
SchrodingersGat Sep 30, 2024
4579e84
Improve rendering of frontend-panel
SchrodingersGat Sep 30, 2024
002bc17
Remove backend rendering
SchrodingersGat Sep 30, 2024
9521223
Add TODO
SchrodingersGat Sep 30, 2024
f628f94
Update README.md
SchrodingersGat Sep 30, 2024
10e23aa
Add context to main.tsx
SchrodingersGat Sep 30, 2024
09df809
Tweak index.html
SchrodingersGat Sep 30, 2024
5c44828
Remove untracked files
SchrodingersGat Sep 30, 2024
aea09fd
Fix static file path
SchrodingersGat Sep 30, 2024
8881dd6
remove custom color switch
SchrodingersGat Sep 30, 2024
264afff
Add simple workflow to build frontend code
SchrodingersGat Sep 30, 2024
48af785
Update node version
SchrodingersGat Sep 30, 2024
9239c89
Remove unused import
SchrodingersGat Sep 30, 2024
01e15b1
Remove unused files
SchrodingersGat Sep 30, 2024
b614025
Restructure
SchrodingersGat Sep 30, 2024
e507c39
setup changes
SchrodingersGat Sep 30, 2024
a378629
Build frontend as part of install script
SchrodingersGat Sep 30, 2024
e33445c
Reorganize again, so that MANIFEST.in works
SchrodingersGat Sep 30, 2024
c429854
Cleanup .gitignore file
SchrodingersGat Sep 30, 2024
5bf6a00
adjust workflows
SchrodingersGat Sep 30, 2024
84818ce
Working, maybe?
SchrodingersGat Sep 30, 2024
abacd35
Adjust workflow files
SchrodingersGat Sep 30, 2024
3406881
Remove compiled files
SchrodingersGat Sep 30, 2024
7751863
Update .gitignore
SchrodingersGat Sep 30, 2024
41c8007
Hack for setup.py
SchrodingersGat Sep 30, 2024
683bdfc
FIx for source file
SchrodingersGat Sep 30, 2024
ff5734a
Fix npm build output dir
SchrodingersGat Sep 30, 2024
9c90623
Add custom settings UI elements
SchrodingersGat Oct 1, 2024
aafff67
Updates to match InvenTree code
SchrodingersGat Oct 16, 2024
8d1b2fd
Fix return data
SchrodingersGat Oct 16, 2024
302bacf
Add icon
SchrodingersGat Nov 19, 2024
22e32c7
Fix typo
SchrodingersGat Nov 19, 2024
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
24 changes: 24 additions & 0 deletions .github/workflows/frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Run CI checks for frontend code
name: Frontend CI

on: ["push", "pull_request"]

jobs:
frontend:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: "18"
- name: Install Deps
run: |
cd src/frontend
npm install
- name: Build Frontend
run: |
cd src/frontend
npm run build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ celerybeat.pid
# SageMath parsed files
*.sage.py

src/frontend/tsconfig.app.tsbuildinfo
2 changes: 1 addition & 1 deletion inventree_wireviz/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version information for the inventree-wireviz plugin"""

PLUGIN_VERSION = "0.6.2"
PLUGIN_VERSION = "0.7.0"
37 changes: 35 additions & 2 deletions inventree_wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.urls import path

from plugin import InvenTreePlugin
from plugin.mixins import PanelMixin, ReportMixin, SettingsMixin, UrlsMixin
from plugin.mixins import PanelMixin, ReportMixin, SettingsMixin, UrlsMixin, UserInterfaceMixin

from build.views import BuildDetail
from part.models import Part, PartCategory
Expand All @@ -26,7 +26,7 @@
logger = logging.getLogger('inventree')


class WirevizPlugin(PanelMixin, ReportMixin, SettingsMixin, UrlsMixin, InvenTreePlugin):
class WirevizPlugin(PanelMixin, ReportMixin, SettingsMixin, UrlsMixin, UserInterfaceMixin, InvenTreePlugin):
""""Wireviz plugin for InvenTree

- Provides a custom panel for rendering wireviz diagrams
Expand Down Expand Up @@ -131,8 +131,14 @@ def get_panel_context(self, view, request, context):
except AttributeError:
return context

return self.panel_context_from_instance(instance)

def panel_context_from_instance(self, instance):

part = self.get_part_from_instance(instance)

context = {}

if part and isinstance(part, Part):

context['part'] = part
Expand Down Expand Up @@ -210,6 +216,33 @@ def get_custom_panels(self, view, request):

return panels

def get_ui_panels(self, instance_type, instance_id, request, **kwargs):
"""Return custom UI panels for the wireviz plugin."""

panels = []
part = None

if instance_type == 'part':
try:
part = Part.objects.get(pk=instance_id)
except Part.DoesNotExist:
part = None

if part and part.get_metadata('wireviz'):

ctx = self.panel_context_from_instance(part)

ctx['part'] = part.pk

panels.append({
'name': 'wireviz',
'label': 'Harness Diagram',
'context': ctx,
'source': f'/static/plugin/{self.SLUG}/WirevizPanel.js',
})

return panels

def get_template_files(self):
"""Return a list of existing WireViz template files which have been uploaded."""

Expand Down
25 changes: 25 additions & 0 deletions src/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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?
*.tsbuildinfo
29 changes: 29 additions & 0 deletions src/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Wireviz Plugin - Frontend Code

This directory contains the frontend code for the Wireviz plugin.

## Development

This project uses [Vite](https://vitejs.dev/) as the build tool. We followed [this guide](https://vitejs.dev/guide/#scaffolding-your-first-vite-project) to scaffold the project.

## Building

To compile the frontend code, run:

```bash
npm run build
```

This will compile the frontend code into the `dist/static` directory.

## Testing

To test the frontend code, run:

```bash
npm run dev
```

This will start a development server (usually on `localhost:5173`) which will automatically reload when changes are made to the source code.

The development server provides some "dummy" harness data to test the frontend code.
28 changes: 28 additions & 0 deletions src/frontend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
12 changes: 12 additions & 0 deletions src/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>InvenTree Wireviz - Developer View</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading
Loading