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

UI 2.0 Implement GenericView component #3626

Conversation

norbert-mieczkowski-codilime
Copy link
Collaborator

@norbert-mieczkowski-codilime norbert-mieczkowski-codilime commented Apr 20, 2023

Closes: #3529

What's Changed

  • Add global height: 100%; width 100%; styles to html, body and #root elements.
  • Change Layout component content and style to allow better scrolling experience.
  • Implement GenericView component providing all the basic components needed for a generic layout.
  • Use newly implemented GenericView component in ObjectCreate, ObjectList and ObjectRetrieve views.

image

TODO

@norbert-mieczkowski-codilime norbert-mieczkowski-codilime changed the title UI 2.0 implement GenericView component UI 2.0 Implement GenericView component Apr 20, 2023
@bryanculver bryanculver linked an issue Apr 21, 2023 that may be closed by this pull request
@glennmatthews
Copy link
Contributor

Taking a look now. When you get a chance, could you do another merge to pull in #3632?

Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled it down locally and the object-list views look great. I couldn't get any content to appear in the object-detail or object-create views but I think this is expected currently?


const breadcrumbs = useMemo(
() =>
(menu?.data ?? []).reduce((breadcrumbs, root) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education - what would be the pattern for a view that wanted to override the below breadcrumbs due to some unique set of inheritance? Would they need to replicate this entire function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the data structure created here is very component-specific, so I wouldn't move it anywhere outside. if so required, perhaps it would be a good idea to split it into functions returning one menu item and/or breadcrumb at a time, e.g. getUIMenuItem(pathname, level), getBreadcrumb(uiMenuItem), and composing according to specific requirements. also, enabling breadcrumbs overrides through GenericView props of course, but that's the simplest thing to do. would that work for you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I think. Certainly not critical at this time, and I like having the breadcrumbs be generally automatic/deterministic for now. I'm just thinking of some of the legacy UI where for example IP address breadcrumbs might include an intermediate entry for/linking to the VRF that the IP address belongs within. In the legacy templates we have an extra_breadcrumbs block that can be used to insert such intermediate breadcrumbs, as well as having the ability to override the entire set of breadcrumbs if so desired. I don't know if either of these features is necessarily needed/applicable in the new UI, just thinking aloud at this time.

nautobot/ui/src/views/generic/GenericView.js Outdated Show resolved Hide resolved
@bryanculver bryanculver merged commit 9cbbb5a into next-ui-2.0 Apr 24, 2023
18 checks passed
@bryanculver bryanculver deleted the u/norbert-mieczkowski-codilime-ui-2.0-implement-generic-view branch April 24, 2023 21:37
bryanculver added a commit that referenced this pull request Apr 25, 2023
* create list templete

* create add form view templete

* refactor and create NautobotInput Component

* move sites/ to dcim/sites/

* move react back one folder

* move react back one folder

* new changes

* new changes

* get model fields

* copy react files from plugin into nautobot frontend

* fix menu

* Work in progress on table

* json api

* Add get table fields

* fix table header

* Use absolte path

* slugify python

* Field groups

* Account for status and tags

* add react to example plugin

* push all code

* nautobot.2319 React UI components update

* add docker-compose.nodejs.yml to run an nginx reverse proxy for nautobot and nodejs

* remove unused ui prototype

* update to work with nextjs

* Revert "remove unused ui prototype"

This reverts commit 7bccab7.

* make react work?

* add object detail view

* remove comment

* remove comments

* add links to object detail view

* fix region

* Implement basic module federation for webpack

- Publishes `nautobot` module as `remoteEntry.js`
- Implemented webpack `config-overrides.js` using `react-app-rewired` as a dev dependency

* remove nextjs ui

* remove plugin file copy

* optimize dev docker environment

* Update react app build output paths

Output js to static/reactjs
Output css to static/reactcss

* use global router

* add postbuild script to move files to nautobot

* add navmenu headers

* convert prototype to nextjs

* fix some imports

* update to use cross site api calls

* remove nginx config

* update nautobot dev server to use uwsgi instead of runserver

* consolidate frontend pages, update django routing for react

* add plugin full width html fragment support

* fix detail page layout

* add plugin routes

* expose django's login/logout routes

* YEET

* Fixing some lints and bugs.

- Removed bad import in router
- Fixed linting errors for unused imports
- Fixed URL route on table item
- Improved Docker compose file to mount node_modules as a separate volume

* fix permissions issue on docker-compose in linux

* fix linux docker nodejs permissions (really)

* Make detail view generic

* stashing

* add paginator for list view

* yolo

* fix nautobot brand image, add some better looking icons

* stashing

* stashing

* replace react views with base.html that's derived from the react app's index.html

* Something broke but this is progress

* CustomViews and Plugin Components

* fix bug in detail view when json key name starts with underscore

* basic management command to generate ui

* tweaks

* Tweaks and update

* fixes and starts

* update dockerfile to match next

* update poetry lockfile

* linting and minor bug fixes

* clean up imports

* fix bug

* added nginx container in nodejs.yml and made nodejs serve up /static/js/bundle.js (#3057)

Co-authored-by: Hanlin Miao <hanlinmiao@Hanlins-MBP-2.home>

* fix runserver database exhaustion with nginx

* increase keepalive timeout on nginx connection

* Revert "increase keepalive timeout on nginx connection"

This reverts commit d3aabdd.

* increase keepalive timeout on nginx connection

* clean up api for plugin react components

* add web_url to all valid serializers

* remove debug logging

* add login view

* fix js error

* Implemented generic create view for React app.

- Requires the nested serialization changes.
- Implemented nested serialization using `?depth=`
    - Revert nested serializer and `brief=True` pattern
    - Replace it with `depth=?` arguments to views and rendering forms from JSON schema using `drf-react-template-framework`
    - Commented out all `brief=` and associated code
- Updated `RegionSerializer` to have `parent` field fallback to default.

* First pass at #3204 (#3252)

* Some low-hanging fruit fixes to get us closer back to next

* next-ui-2.0 cleanup and commenting (#3285)

* Remove unused code added to example_plugin

* Add a bunch of TODO comments

* More TODO comments

* Black

* Flake8

* Markdownlint

* Pylint

* Removing some more stuff that's not needed at present

* Revert a few things back to baseline

* One more deletion

* Fixes to example_plugin and example_plugin_with_view_override

* Update comments and address a couple of TODOs

* More TODO updates

* web_url fixup

* Added a `nautobot-server build_ui` command (#3306)

- This command does the following from the `nautobot/ui` directory
  - Generates the `app_imports.js` file from any installed plugins
  - Runs `npm install` when `--npm-install` is passed
  - Runs `npm run build`
- This command is now also called by `nautobot-server post_upgrade`, which calls it with `--npm-install`
- Updated the `config-overrides.js` to not hash JS or CSS files so that their raw filename can be stored in static files and referenced using `{% static %}` (e.g. `{% static 'js/main.js %}`) without having to overload the `base.html` template for the web UI
- Updated `nautobot/core/templates/base.html` to link directly to the static files for JS and CSS that get pulled in from the UI build environment by `nautobot-server collectstatic` 
- Parameterized the API key needed for now to read from `NAUTOBOT_API_TOKEN` environment variable
- `app_imports.js` now renders with relative paths vs. absolute paths making commits that happen compatible across Docker-local and production use-cases.
- Restored the `/plugins/` route and the `InstalledPlugins.jsx` module
- The `build` command runs `npm` silently by default to hide the debug/warn/error messages unless `-v 2` or `-v 3` are passed.
- There is some `console.log` output that is now not displayed unless `NAUTOBOT_DEBUG` environment variable is set. The `build_ui` command will also set this if verbosity is desired.
- Implemented a new `invoke version` task to align versions of core with UI apps.
  - Will bump both `pyproject.toml` and `package.json` to keep them in sync.
  - If no argument is provided, displays the versions instead.
- Also added `NAUTOBOT_UI_DIR` into `nautobot.core.settings` so that it can be easily reused
- Moved `nautobot_ui` to `nautobot/ui`
- `nautobot/ui` is now included in the package build
- Added a basic README file back to `nautobot/ui`
- Renamed all UI references of "plugin" to "app"

After using `build_ui` it's possible to serve the entire application using Django now without requiring `node`. Of course for development `node` will still be desirable due to live rendering.

* setState for islogged in

* Revert "setState for islogged in"

This reverts commit 596d9c1.

* remove ourrunserver reference in docker compose (#3366)

* UI 2.0 remove nginx container (#3367)

* Initial removal of react-bootstrap and addition of nautobot-ui

* Clean up devDependencies

* Simplify tasks.py

* Updates from feedback

* Add node_modules ignore

* move 'api/' ui related urls under 'api/ui/' (#3385)

* move 'api/' ui related urls under 'api/ui/'

* flake8

* address PR feedback

* exclude get-menu api endpoint from OpenAPI schema and add documentation for UI-related API endpoints

* flake8

* mdlint

* elaborate UI-related endpoints documentation

* update mkdocs.yml

---------

Co-authored-by: Hanlin Miao <hanlinmiao@Hanlins-MBP-2.home>

* Logged in state for nautobot-ui (#3356)

* Update from fix nautobot/nautobot-ui#9

* Black

* Hadolint

* More hadolint

* UI docker dev environment tweaks (#3408)

* Don't copy node_modules and UI build when rebuilding docker image

* Capture npm output and print it in case of failures

* Create docker volume for node_modules, change container startup, update docs

* nautobot-ui is public now; can use node:18-slim

* Add TODO comments

* Add unittest for all react components (#3404)

* Add test for component common

* common test case

* Done testing core

* Add test for BSTableItem Component

* Add partial views test

* Add test for views

* add doc

* run ui unittest

* Apply suggestions from code review

Co-authored-by: Hanlin Miao <46973263+HanlinMiao@users.noreply.github.com>

* fix markdown

* update ReadMe

* Update nautobot/ui/README.md

Co-authored-by: Bryan Culver <31187+bryanculver@users.noreply.github.com>

* Merge conflicts

* Update README.md

---------

Co-authored-by: Hanlin Miao <46973263+HanlinMiao@users.noreply.github.com>
Co-authored-by: Bryan Culver <31187+bryanculver@users.noreply.github.com>
Co-authored-by: Bryan Culver <bryan.culver@networktocode.com>

* UI 2.0 Cleanup (#3444)

* Provide a way to refresh CSRF without shortcutting CSRF protections

* Session endpoint

* Stashing to switch between computers

* more stashing

* yeeet

* This is going to be a lot

* Updates

* Updates from feedback

* Black & flake8

* Fix indention

* Remove top-level package lock

* Revert bad merge

* UI 2.0: Cleanup Router Links, Import Font as Source (#3482)

* Cleanup Router Links

* Move font to built-in instead of served via Google Fonts.

* Remove unneccessary import

* UI 2.0: Introduce Prettier, Use ESLint for Formatting and Linting (#3531)

* Move to craco (#3546)

Fix Jest testing

Remove should be ignored paths file as this is autogenerated

Scope creep avoid get tests passing so we can demonstrate it's working.

Prettier...

Add base paths for testing

No cached example, just copy the template in CI

Mock would prefer a file exists for app_imports.js

* Add New UI Toggle (#3615)

* Add New UI Toggle

* Add changelog fragment.

* Prettier

* Fix corrupted package-lock.json (#3618)

* Fix corrupted package-lock.json

* Add changelog fragment.

* Remove duplicate package for nautbot-ui

* Get tests passing for UI 2.0 (#3632)

* Get tests passing for UI 2.0

* Add changelog fragment.

* Updates from feedback

* Exception handling

* Fix CI step merge

* Pylint

* Fix changes from next

* UI 2.0 Implement GenericView component (#3626)

* [UI 2.0] Implement GenericView component

* [UI 2.0] Add missing objectData prop to GenericView in ObjectRetrieve view

* [UI 2.0] Remove Current route is ... debug message

* Move popover to it's own component.

---------

Co-authored-by: Bryan Culver <bryan.culver@networktocode.com>
Co-authored-by: Bryan Culver <me@bryanculver.com>

* 👟

---------

Co-authored-by: Timizuo <timizuoebideri@gmail.com>
Co-authored-by: Chris Thant <chris.thant@networktocode.com>
Co-authored-by: Gary Snider <gary.snider@networktocode.com>
Co-authored-by: jathanism <jathan@gmail.com>
Co-authored-by: Hanlin Miao <46973263+HanlinMiao@users.noreply.github.com>
Co-authored-by: Hanlin Miao <hanlinmiao@Hanlins-MBP-2.home>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com>
Co-authored-by: Timizuo <94907097+timizuoebideri1@users.noreply.github.com>
Co-authored-by: Norbert Mieczkowski <117445994+norbert-mieczkowski-codilime@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI 2.0: GenericView Base
3 participants