Create parent container 1 and activity container components
Introduction
The Oracle JavaScript Extension Toolkit (Oracle JET) virtual DOM app that you will have developed at the end of this learning path series will be composed of the components shown in the following image. That is, the ParentContainer1
component contains an ActivityContainer
component that displays a list of activities. Once an activity is selected, a second parent component (ParentContainer2
) renders that includes a component (ActivityItemContainer
) to display the list of items associated with the selected activity. Finally, on selection of an activity item, the app renders an ItemDetailContainer
component that displays pricing and stock level information about the selected activity item.
Objectives
In this tutorial, you will compose some of the foundational components of your Oracle JET virtual DOM app. To aid in the visualization of the app layout, you will also add the Oracle JET oj-panel
and oj-bg
style classes to display borders and color around the containers. You can remove these style classes from the final app.
Prerequisites
- A development environment set up to create Oracle JET virtual DOM apps that includes an installation of Node.js
- Access to the Oracle JET Cookbook
- (Option 1) Completion of the final tutorial in the previous learning path in this series: Prepare to Deploy an Oracle JET Virtual DOM App
- (Option 2) If you haven’t completed the previous learning path in this series: The
jet_virtual_dom_app_temp.zip
downloaded
Task 1: Download the Starter Virtual DOM App
Skip this task if you’re continuing to work in an app that you created in the previous learning path.
-
Rename
jet_virtual_dom_app_temp.zip
asJET-Virtual-DOM-app.zip
. Extract the contents to theJET-Virtual-DOM-app
directory. -
Navigate to the
JET-Virtual-DOM-app
directory, and restore the Oracle JET virtual DOM app.npm install
Your virtual DOM app is ready to use.
Task 2: Create the Item Detail Component
The Content
component was created when you scaffolded the virtual DOM app in the last learning path. Rename and refactor this component as ItemDetailContainer
, a child component that will be rendered by the ParentContainer2
component that you will create in the next tutorial.
-
In the
JET-Virtual-DOM-app/src/components
directory, rename thecontent
directory toItemDetail
. Then rename theindex.tsx
file within it toItemDetailContainer.tsx
.Note: If your editor brings up a prompt asking whether imports should be updated in the renamed file or directory, as in the message from Visual Studio Code below, click No and continue.
.
-
In
ItemDetailContainer.tsx
, change the lineexport function Content() {
toconst ItemDetailContainer = () => {
. Then add anexport
statement for theItemDetailContainer
component to the end of the file.const ItemDetailContainer = () => { . . . }; export default ItemDetailContainer;
-
Replace the beginning of the
return
statement in theItemDetailContainer
component with the following code, up to but not including theoj-label
element. Thediv
includes an Oracle JEToj-bg
style class to add a gray background color to the container.return ( <div id="itemDetailsContainer" class="oj-bg-neutral-30"> <h3>Item Details</h3> <oj-label for="basicSelect">Select Chart:</oj-label> . . .
-
Delete the
renderListItem
function and remove the last closing</div>
tag from the end of thereturn
statement. -
Save and close the file.
Your code should look similar to
item-detail-container-tsx.txt
Task 3: Create the Content Component
Recreate the Content
component, which renders a title for your app and a Preact element for the ParentContainer1
component that you will create in the following task.
-
In the
JET-Virtual-DOM-app/src/components
directory, create aContent
directory with an emptyContent.tsx
file inside it. -
Add the following import statements to the top of the file. You will create the
ParentContainer1
component later in this tutorial.import { h } from "preact"; import ParentContainer1 from "../ParentContainer1";
-
Create the
Content
component’s function definition.const Content = () => { return ( ); }
-
In the function’s
return
statement, add adiv
containing theh1
header Product Information and aParentContainer1
element to access the component you will create.const Content = () => { return ( <div class="oj-web-applayout-max-width oj-web-applayout-content"> <h1>Product Information</h1> <ParentContainer1 /> </div> ); };
-
At the end of the file, add an
export
statement for theContent
component.export default Content;
-
Save and close the file. Your code should look similar to content-tsx.txt.
-
In the
JET-Virtual-DOM-app/src/components
directory, open theapp.tsx
file in your editor. At the top of the file, find the line of code whereimport { Content } from "./content/index";
, then edit it to readimport Content from "./Content/Content";
. -
Save and close the file.
Task 4: Create the Parent Container 1 Component
Create the ParentContainer1
component, which is the parent container component for the rest of the components you will create.
-
In the
JET-Virtual-DOM-app/src/components
directory, create aParentContainer1.tsx
file. -
Add the following
import
statements to the top of the file. You will create theActivityContainer
component later in this tutorial.import { h } from "preact"; import ActivityContainer from "./Activity/ActivityContainer";
-
Create the
ParentContainer1
component’s function definition, which returns adiv
that contains theActivityContainer
element. Thediv
element includes an Oracle JEToj-bg
style class to add a yellow background color to the container and anoj-panel
style class to create a border.const ParentContainer1 = () => { return ( <div id="parentContainer1" class="oj-panel oj-bg-warning-20"> <ActivityContainer /> </div> ); };
-
At the end of the file, add an
export
statement for theParentContainer1
component.export default ParentContainer1;
-
Save and close the file.
Your code should look similar to parent-container1-tsx.txt.
Task 5: Create the Activity Container Component
Create the ActivityContainer
component, a child component that is rendered by the ParentContainer1
component. The ActivityContainer
component renders a header and a list of activities.
-
In the
JET-Virtual-DOM-app/src/components
directory, create anActivity
directory and anActivityContainer.tsx
file inside it. -
At the top of the file, add the following
import
statement.import { h, ComponentProps } from "preact";
-
Create the
ActivityContainer
component’s function definition, which returns adiv
element containing anh3
HTML header Activities and a list of activities. Thediv
includes an Oracle JEToj-bg
style class to add a blue background color to the container.const ActivityContainer = () => { return ( <div id="activitiesContainer" class="oj-bg-info-30"> <h3 id="activitiesHeader">Activities</h3> <div id="activitiesItems" class="item-display no-wrap"> <ul> <li class="li-item">Baseball</li> <li class="li-item">Bicycling</li> <li class="li-item">Skiing</li> <li class="li-item">Soccer</li> </ul> </div> </div> ); };
-
At the end of the file, add an
export
statement for theActivityContainer
component.export default ActivityContainer;
-
Save and close the file.
Your code should look similar to
activity-container-tsx.txt
. -
Navigate to the
JET-Virtual-DOM-app/src/styles
directory and open theapp.css
file in an editor. Add theitem-display
,no-wrap
, andli-item
style classes to the end of the file..item-display { width: 100%; height: 100%; max-height: 500px; overflow-x: hidden; overflow-y: auto; } .no-wrap { flex-wrap: nowrap; } .li-item { list-style-type: none; font-size: 1rem; font-weight: 500; }
-
Save and close the file.
Your code should look similar to
app-css.txt
.
Task 6: Run the Virtual DOM App
-
In the terminal window, run the app from the
JET-Virtual-DOM-app
directory.npx ojet serve
The Activity Container (blue) inside of Parent Container 1 (yellow) displays the list of activity names. Note that the Item Detail Container is not displayed because it has not yet been rendered inside another component (it will be added to the Parent Container 2 component, created in the next tutorial).
-
Close the browser window or tab that displays your running virtual DOM app.
-
In the terminal window, press Ctrl+C, and if prompted, enter
y
to exit the Oracle JET tooling batch job.
Next Step
To proceed to the next tutorial in this learning path, click here.
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Create parent container 1 and activity container components
F72917-04
December 2024