Git Product home page Git Product logo

generator-ui5-react-nest's Introduction

Yeoman Generator for UI5 Nest React

In the dynamic world of business, we never know what requirements may come our way. While UI5 is already a powerful framework, there are times you need to integrate it with other UI technologies when business demands.

In this blog post, we'll explore the blending of React application with UI5 by leveraging a custom UI5 control (UI5Nest) which effortlessly handles loading and embedding React applications. Unlike traditional solutions that rely on iframes, this integration takes advantage of native loading to HTML div elements, ensuring that your React app seamlessly blends with other UI5 controls, acting like any other UI5 control.

Workzone%20view

Above Image taken from CF Workzone . Below is the code for this,
<mvc:View
	controllerName="nest.controller.Main"
	displayBlock="true"
	xmlns:custom="nest.ExtApp"
	xmlns="sap.m"
	xmlns:mvc="sap.ui.core.mvc">
  <VBox
    justifyContent="Center" 
    alignItems="Center" 
    height="100%" >
  	<VBox>
    	<Title text="UI5"  titleStyle="H1" />
      <Button
        text="count is {/count}"  press=".onIncrement" />
    </VBox>
    <custom:UI5Nest id="react" />
  </VBox>
</mvc:View>​

Managed Router, HTML5 Repository and Build Workzone

You can deploy to HTML5 Repository like you do it with your UI5 application. UI5Nest control integration with Workzone or Fiori Launchpad (on-prem)  is seamless. This means that your React application receives real-time updates for localization and theme changes when events occur. You will receive initial values of the theme and locale in your React app. You will receive these updates again if they change , ensuring you don't miss any updates.

function onThemeChanged (sTheme) {  
  //Call central theme change function on App.jsx so it will serve standalone app and nested app
}

function onLocalizationChanged (sLocal) {  
  //Call central local change function on App.jsx so it will serve standalone app and nested app
 
}​

It ensures that your application maintains consistency and synchronicity and delivering a cohesive user experience. generator-ui5-react-nest scaffolds the necessary files and configurations for managed router. So it is ready to deploying the Workzone service on Cloud Foundry.

UI5 Generator: generator-ui5-react-nest

To further simplify the process, I have created an UI5 generator for this purpose. This generator is based on pnpm monorepo, which allows for scaffolding UI5 and React applications and local test launchpad such as launchpad.html and other necessary files.

The scaffolded React application uses Vite,  It is modern , easy and fast . React team no longer recommends CRA also . While react-router-dom is not included in UI5 generator project, I use it in my projects ( with some modifications for launchpad integration ) and it works fine.

You should also use UI5 Web Components in your React app, but I chose not to include them in the generator to avoid making it overly opinionated.

As you will notice, the React application has 2 modes. The first one is standalone. It will act like any other React app. The second mode is UI5 mode. When you use pnpm script start:ui5 or build:ui5, it will make the adjustments in the React app to be available to work in a UI5 app.

Although I usually prefer using TypeScript, I have opted for JavaScript in this case for the sake of simplicity and clarity. However, TypeScript is the way I used this method in my projects for both UI5 and React. So it can be easily integrated if desired.

You can install the ui5 react nest generator and yeoman (if you haven"t already)

npm i -g yo generator-ui5-react-nest
yo ui5-react-nest
​

By using the generator-ui5-react-nest and following the steps outlined in the blog post Nest React applications natively alongside UI5, you can achieve a smooth integration of React applications with SAP UI5, enabling a consistent and powerful user experience across your projects.

generator-ui5-react-nest's People

Contributors

aydin-ozcan avatar gregorwolf avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gregorwolf

generator-ui5-react-nest's Issues

exception when trying to close sapui5 application with id / adding object "component" with duplicate id

Hi @aydin-ozcan,

I've used the generator to create ui5-react-nest-hello-world. Unfortunately it seems that the lifecycle required to make the react app run correctly inside the launchpad isn't yet supported.

Please try this steps to replicate the issue:

In the console you will see this error:

2023-07-31 22:33:12.102699 exception when trying to close sapui5 application with id 'application-helloworldui-display'. This error must be fixed in order for FLP to operate properly.
 - TypeError: lr.unmountComponentAtNode is not a function
    at p.unloadApp (http://localhost:8080/ExtApp/react.js:40:57757)
    at p.destroy (http://localhost:8080/ExtApp/UI5Nest.js:48:12)
    at y.destroyAggregation (https://sapui5.hana.ondemand.com/1.108.19/resources/sap-ui-core.js:326:15902)
    at y.destroy (https://sapui5.hana.ondemand.com/1.108.19/resources/sap-ui-core.js:326:20064)
    at d.destroy (https://sapui5.hana.ondemand.com/1.108.19/resources/sap-ui-core.js:404:3433)
    at u.destroy (https://sapui5.hana.ondemand.com/1.108.19/resources/sap/ui/core/Control.js:6:4343)
    at y.destroyAggregation (https://sapui5.hana.ondemand.com/1.108.19/resources/sap-ui-core.js:326:15902)
    at y.destroy (https://sapui5.hana.ondemand.com/1.108.19/resources/sap-ui-core.js:326:20064)
    at d.destroy (https://sapui5.hana.ondemand.com/1.108.19/resources/sap-ui-core.js:404:3433)
    at u.destroy (https://sapui5.hana.ondemand.com/1.108.19/resources/sap/ui/core/Control.js:6:4343)

I think this is also the reason why the app can't be started a second time. When clicking on the tile I see this error in the console:

Log-dbg.js:452 2023-07-31 22:37:07.290300 adding object "component" with duplicate id 'application-helloworldui-display-component' -

CU
Gregor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.