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

Platform UI - React integration #5011

Merged
merged 73 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
eb793b7
Add SPA views for react #2789
matmair Jun 9, 2023
b5c0b26
split up frontend urls
matmair Jun 9, 2023
d7c4baa
Add settings for frontend url loading
matmair Jun 9, 2023
4c507dc
add new UI scaffold
matmair Jun 9, 2023
abf7309
remove tracking insert
matmair Jun 9, 2023
0f2f51f
add platform app
matmair Jun 9, 2023
61ff33a
ensure static indexes work too
matmair Jun 9, 2023
bcc28b0
add lingui
matmair Jun 9, 2023
205399f
add lingui config
matmair Jun 9, 2023
623d23e
add mgmt tasks
matmair Jun 9, 2023
eb0f392
add base locales
matmair Jun 9, 2023
f2799ef
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Jun 10, 2023
f98a5d4
settings for frontend dev
matmair Jun 11, 2023
aea6d8f
fix typo
matmair Jun 11, 2023
c2b8954
update deps
matmair Jun 11, 2023
aab7759
add pre-commit
matmair Jun 11, 2023
ccbe3d4
add eslint
matmair Jun 12, 2023
8bcb4f8
add testing scaffold
matmair Jun 12, 2023
de4f024
fix paths
matmair Jun 12, 2023
f7d9a93
remove error - tests trip correctly
matmair Jun 12, 2023
188c4c3
Merge branch 'inventree:master' into plattform
matmair Jun 14, 2023
0aea007
Merge branch 'inventree:master' into plattform
matmair Jun 16, 2023
4353fac
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Jun 26, 2023
9816ec0
merge workflow
matmair Jun 26, 2023
e379320
cleanup samples
matmair Jun 26, 2023
eab41a4
use name inline with other tests
matmair Jun 26, 2023
3030496
Add real worl frontend tests
matmair Jun 26, 2023
36c117c
setup env
matmair Jun 26, 2023
c0ea1db
tun migrations first
matmair Jun 26, 2023
c249717
optimize setup time
matmair Jun 26, 2023
204cc55
setup demo dataset
matmair Jun 26, 2023
515c1bc
optimize run setup
matmair Jun 26, 2023
cd54f59
add test for class ui
matmair Jun 26, 2023
f3ee654
rename
matmair Jun 26, 2023
7a258b2
fix typo
matmair Jun 26, 2023
b7aba13
and another typo
matmair Jun 26, 2023
5eb035f
do install
matmair Jun 26, 2023
29772d9
run migrations first
matmair Jun 26, 2023
ef2d6ed
fix name
matmair Jun 26, 2023
dceeea9
cleanup
matmair Jun 26, 2023
f1f8051
use other credentials
matmair Jun 26, 2023
7ef6878
use other credentials
matmair Jun 26, 2023
4aec179
fix qc
matmair Jun 26, 2023
a454258
move envs to qc
matmair Jun 26, 2023
8638d8f
remove create_site
matmair Jun 26, 2023
7aa040a
reduce testing env
matmair Jun 26, 2023
eb69869
fix test
matmair Jun 26, 2023
9bfe7db
fix test call
matmair Jun 26, 2023
36e271a
allaccess user
matmair Jun 26, 2023
ae9467a
add ui plattform check
matmair Jun 26, 2023
2f0f622
add better check
matmair Jun 26, 2023
441719c
remove unneeded env
matmair Jun 26, 2023
ce0880a
enable debug
matmair Jun 26, 2023
fb49dfe
reduce wait time
matmair Jun 26, 2023
a520e57
also build frontend on static
matmair Jun 26, 2023
0078e7d
add sort plugin
matmair Jul 2, 2023
f3ca199
fix order
matmair Jul 2, 2023
f5019ef
run pre-commit fixes
matmair Jul 6, 2023
ec539f0
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Jul 6, 2023
c3c998b
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Jul 6, 2023
42bdf70
add node min version
matmair Jul 7, 2023
24d7460
Docker container (#129)
SchrodingersGat Jul 8, 2023
79b1b6b
Merge branch 'inventree:master' into plattform
matmair Jul 8, 2023
6d1fd97
add import order settings
matmair Jul 8, 2023
fe4a1b2
cleanout built ui
matmair Jul 9, 2023
719e321
remove default arg from build
matmair Jul 9, 2023
d10e764
remove eslint
matmair Jul 9, 2023
c1b7af0
optimize svg
matmair Jul 9, 2023
84a24a0
add build step for plattform UI
matmair Jul 9, 2023
a0308fe
fix install command
matmair Jul 9, 2023
efc0251
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Jul 10, 2023
4be39a6
use alpine commands
matmair Jul 10, 2023
29c22fb
do not use cache when creating image
matmair Jul 11, 2023
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
ARG WORKSPACE="/workspaces/InvenTree"

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
ARG NODE_VERSION="18"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ python3 -m venv dev/venv
pip install invoke
invoke update
invoke setup-dev
invoke frontend-install
matmair marked this conversation as resolved.
Show resolved Hide resolved

# remove existing gitconfig created by "Avoiding Dubious Ownership" step
# so that it gets copied from host to the container to have your global
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/qc_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
outputs:
server: ${{ steps.filter.outputs.server }}
migrations: ${{ steps.filter.outputs.migrations }}
frontend: ${{ steps.filter.outputs.frontend }}

steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # [email protected]
Expand All @@ -43,6 +44,8 @@ jobs:
migrations:
- '**/migrations/**'
- '.github/workflows**'
frontend:
- 'src/frontend/**'

pep_style:
name: Style [Python]
Expand Down Expand Up @@ -387,3 +390,38 @@ jobs:
cp test-db/stable_0.12.0.sqlite3 /home/runner/work/InvenTree/db.sqlite3
chmod +rw /home/runner/work/InvenTree/db.sqlite3
invoke migrate

plattform_ui:
name: Tests - UI Platform
runs-on: ubuntu-20.04
timeout-minutes: 60
needs: paths-filter
if: needs.paths-filter.outputs.frontend == 'true'
env:
INVENTREE_DB_ENGINE: sqlite3
INVENTREE_DB_NAME: /home/runner/work/InvenTree/db.sqlite3
INVENTREE_DEBUG: True
INVENTREE_PLUGINS_ENABLED: false

steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # [email protected]
- name: Environment Setup
uses: ./.github/actions/setup
with:
npm: true
install: true
update: true
- name: Set up test data
run: invoke setup-test -i
- name: Install dependencies
run: cd src/frontend && yarn install
- name: Install Playwright Browsers
run: cd src/frontend && npx playwright install --with-deps
- name: Run Playwright tests
run: cd src/frontend && npx playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: src/frontend/playwright-report/
retention-days: 30
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,23 @@ repos:
docs/docs/javascripts/.*|
docs/docs/webfonts/.*
)$
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.9-for-vscode"
hooks:
- id: prettier
files: ^src/frontend/.*\.(js|jsx|ts|tsx)$
additional_dependencies:
- "prettier@^2.4.1"
- "@trivago/prettier-plugin-sort-imports"
matmair marked this conversation as resolved.
Show resolved Hide resolved
- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v8.42.0"
hooks:
- id: eslint
additional_dependencies:
- eslint@^8.41.0
- eslint-config-google@^0.14.0
- [email protected]
- [email protected]
- "@typescript-eslint/eslint-plugin@latest"
- "@typescript-eslint/parser"
files: ^src/frontend/.*\.(js|jsx|ts|tsx)$
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ The HEAD of the "stable" branch represents the latest stable release code.
## Environment
### Target version
We are currently targeting:
| Name | Minimum version |
|---|---|
| Python | 3.9 |
| Django | 3.2 |
| Name | Minimum version | Note |
|---|---| --- |
| Python | 3.9 | |
| Django | 3.2 | |
| Node | 18 | Only needed for frontend development |

### Auto creating updates
The following tools can be used to auto-upgrade syntax that was depreciated in new versions:
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ RUN chmod +x init.sh

ENTRYPOINT ["/bin/sh", "./init.sh"]

# Frontend builder

FROM inventree_base as frontend
matmair marked this conversation as resolved.
Show resolved Hide resolved

RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -y nodejs npm && apt-get autoclean && apt-get autoremove && \
matmair marked this conversation as resolved.
Show resolved Hide resolved
npm install -g yarn
COPY InvenTree ${INVENTREE_HOME}/InvenTree
COPY src ${INVENTREE_HOME}/src
COPY tasks.py ${INVENTREE_HOME}/tasks.py
RUN cd ${INVENTREE_HOME}/InvenTree && inv frontend-compile

# InvenTree production image:
# - Copies required files from local directory
# - Starts a gunicorn webserver
Expand All @@ -111,6 +122,7 @@ ENV INVENTREE_COMMIT_DATE="${commit_date}"

# Copy source code
COPY InvenTree ./InvenTree
COPY --from=frontend ${INVENTREE_HOME}/InvenTree/web/static/web ./InvenTree/web/static/web

# Launch the production server
# TODO: Work out why environment variables cannot be interpolated in this command
Expand All @@ -120,6 +132,11 @@ CMD gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8000 --chdir ./Inve

FROM inventree_base as dev

# Install nodejs / npm / yarn
RUN apt install -y curl nodejs npm
RUN npm cache clean -f && npm install -g n && n stable
RUN npm install -g yarn

# The development image requires the source code to be mounted to /home/inventree/
# So from here, we don't actually "do" anything, apart from some file management

Expand Down
6 changes: 5 additions & 1 deletion InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
INVENTREE_NEWS_URL = 'https://inventree.org/news/feed.atom'

# Determine if we are running in "test" mode e.g. "manage.py test"
TESTING = 'test' in sys.argv
TESTING = 'test' in sys.argv or 'TESTING' in os.environ

if TESTING:

Expand Down Expand Up @@ -76,6 +76,9 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_boolean_setting('INVENTREE_DEBUG', 'debug', True)

ENABLE_CLASSIC_FRONTEND = get_boolean_setting('INVENTREE_CLASSIC_FRONTEND', 'classic_frontend', True)
ENABLE_PLATFORM_FRONTEND = get_boolean_setting('INVENTREE_PLATFORM_FRONTEND', 'platform_frontend', True)

# Configure logging settings
log_level = get_setting('INVENTREE_LOG_LEVEL', 'log_level', 'WARNING')

Expand Down Expand Up @@ -203,6 +206,7 @@
'stock.apps.StockConfig',
'users.apps.UsersConfig',
'plugin.apps.PluginAppConfig',
'web',
'generic',
'InvenTree.apps.InvenTreeConfig', # InvenTree app runs last

Expand Down
18 changes: 17 additions & 1 deletion InvenTree/InvenTree/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from stock.api import stock_api_urls
from stock.urls import stock_urls
from users.api import user_urls
from web.urls import urlpatterns as platform_urls

from .api import APISearchView, InfoView, NotFoundView
from .social_auth_urls import SocialProvierListView, social_auth_urlpatterns
Expand Down Expand Up @@ -155,7 +156,7 @@
re_path(r'^api-doc/', SpectacularRedocView.as_view(url_name='schema'), name='api-doc'),
]

frontendpatterns = [
classic_frontendpatterns = [

# Apps
re_path(r'^build/', include(build_urls)),
Expand Down Expand Up @@ -198,6 +199,21 @@
re_path(r'^accounts/', include('allauth.urls')), # included urlpatterns
]


new_frontendpatterns = [
# Platform urls
re_path(r'^platform/', include(platform_urls)),

]

# Load patterns for frontend according to settings
frontendpatterns = []
if settings.ENABLE_CLASSIC_FRONTEND:
frontendpatterns.append(re_path('', include(classic_frontendpatterns)))
if settings.ENABLE_PLATFORM_FRONTEND:
frontendpatterns.append(re_path('', include(new_frontendpatterns)))


# Append custom plugin URLs (if plugin support is enabled)
if settings.PLUGINS_ENABLED:
frontendpatterns.append(get_plugin_urls())
Expand Down
6 changes: 6 additions & 0 deletions InvenTree/config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ database:
# Use the environment variable INVENTREE_DEBUG
debug: True

# Set enabled frontends
# Use the environment variable INVENTREE_CLASSIC_FRONTEND
# classic_frontend: True
# Use the environment variable INVENTREE_PLATFORM_FRONTEND
# platform_frontend: True

# Configure the system logging level
# Use environment variable INVENTREE_LOG_LEVEL
# Options: DEBUG / INFO / WARNING / ERROR / CRITICAL
Expand Down
18 changes: 18 additions & 0 deletions InvenTree/web/templates/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% load spa_helper %}
{% load inventree_extras %}

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{% inventree_instance_name %}</title>
</head>

<body>
<div id="root"></div>
{% spa_bundle %}
</body>

</html>
36 changes: 36 additions & 0 deletions InvenTree/web/templatetags/spa_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Template tag to render SPA imports."""
import json
from logging import getLogger
from pathlib import Path

from django import template
from django.conf import settings
from django.utils.safestring import mark_safe

logger = getLogger("gwaesser_backend")
register = template.Library()


@register.simple_tag
def spa_bundle():
"""Render SPA bundle."""
manifest = Path(__file__).parent.parent.joinpath("static/web/manifest.json")

if not manifest.exists():
logger.error("Manifest file not found")
return

manifest_data = json.load(manifest.open())
index = manifest_data.get("index.html")

dynmanic_files = index.get("dynamicImports", [])
imports_files = "".join(
[
f'<script type="module" src="{settings.STATIC_URL}web/{manifest_data[file]["file"]}"></script>'
for file in dynmanic_files
]
)

return mark_safe(
f"""<script type="module" src="{settings.STATIC_URL}web/{index['file']}"></script>{imports_files}"""
)
26 changes: 26 additions & 0 deletions InvenTree/web/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""URLs for web app."""
from django.conf import settings
from django.shortcuts import redirect
from django.urls import path, re_path
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import TemplateView


class RedirectAssetView(TemplateView):
"""View to redirect to static asset."""

def get(self, request, *args, **kwargs):
"""Redirect to static asset."""
return redirect(
f"{settings.STATIC_URL}web/assets/{kwargs['path']}", permanent=True
)


spa_view = ensure_csrf_cookie(TemplateView.as_view(template_name="web/index.html"))


urlpatterns = [
path("assets/<path:path>", RedirectAssetView.as_view()),
re_path(r"^(?P<path>.*)/$", spa_view),
path("", spa_view),
matmair marked this conversation as resolved.
Show resolved Hide resolved
]
8 changes: 8 additions & 0 deletions src/frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"@babel/preset-react"
],
"plugins": [
"macros"
]
}
7 changes: 7 additions & 0 deletions src/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
};
29 changes: 29 additions & 0 deletions src/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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?

# Testing
/test-results/
/playwright-report/
/playwright/.cache/
19 changes: 19 additions & 0 deletions src/frontend/.linguirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"locales": ["en", "de", "hu", "pseudo-LOCALE"],
"catalogs": [{
"path": "src/locales/{locale}/messages",
"include": ["src"],
"exclude": ["**/node_modules/**"]
}],
"format": "po",
"orderBy": "origin",
"sourceLocale": "en",
"pseudoLocale": "pseudo-LOCALE",
"fallbackLocales": {
"default": "en",
"pseudo-LOCALE": "en"
},
"extractBabelOptions": {
"presets": ["@babel/preset-typescript"]
}
}
9 changes: 9 additions & 0 deletions src/frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"trailingComma": "none",
"singleQuote": true,
"printWidth": 80,
"importOrder": ["<THIRD_PARTY_MODULES>", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
Loading
Loading