Skip to content

Commit 34c8f55

Browse files
authored
feat: Modules (#2344)
## Description Provide a concise summary of the changes made in this pull request - ## Pull request type Check the appropriate box: - [ ] Review Fixes - [ ] Documentation Overhaul - [ ] Feature/Story - Link one or more Engineering Tickets * - [ ] A-Force - [ ] Error in documentation - [ ] Maintenance ## Documentation tickets Link to one or more documentation tickets: - ## Checklist From the below options, select the ones that are applicable: - [ ] Checked for Grammarly suggestions. - [ ] Adhered to the writing checklist. - [ ] Adhered to the media checklist. - [ ] Verified and updated cross-references or added redirect rules. - [ ] Tested the redirect rules on deploy preview. - [ ] Validated the modifications made to the content on the deploy preview. - [ ] Validated the CSS modifications on different screen sizes.
1 parent a96f2c8 commit 34c8f55

21 files changed

+645
-242
lines changed

website/docs/advanced-concepts/custom-authentication.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sidebar_position: 1
44
description: In this guide, you'll learn how to implement a custom Auth flow using an API with JWTs.
55
---
66

7+
78
# Integrate Custom Authentication
89

910
This guide walks you through the process of building custom authentication and integrating your Appsmith applications with any authentication provider.

website/docs/packages/how-to-guides/create-js-module.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ tags={[
2020
This guide demonstrates how to use JS modules to refresh OAuth tokens across all apps, enabling you to renew and extend your authentication access.
2121

2222
## Create JS module
23+
2324
<div style={{ position: "relative", paddingBottom: "calc(50.520833333333336% + 41px)", height: "0", width: "100%" }}>
2425
<iframe src="https://demo.arcade.software/3sTHVS5YLf5WTA05iplD?embed" frameborder="0" loading="lazy" webkitallowfullscreen mozallowfullscreen allowfullscreen style={{ position: "absolute", top: "0", left: "0", width: "100%", height: "100%", colorScheme: "light" }} title="Appsmith | Connect Data">
2526
</iframe>
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: Pass data between modules
3+
hide_title: true
4+
---
5+
<!-- vale off -->
6+
7+
<div className="tag-wrapper">
8+
<h1>Pass data between modules</h1>
9+
10+
<Tags
11+
tags={[
12+
{ name: "Business", link: "https://www.appsmith.com/pricing", additionalClass: "business" }
13+
]}
14+
/>
15+
16+
</div>
17+
18+
<!-- vale on -->
19+
20+
This page shows how to pass data between a query and a JS module, which allows you to handle and manipulate data efficiently within your JS code.
21+
22+
23+
24+
## Prerequisites
25+
26+
A package that has already been created. For more information, see [Package and query modules tutorials](/packages/tutorial/query-module).
27+
28+
## Configure package
29+
30+
Follow these steps to set up JS and query modules within the package.
31+
32+
<div style={{ position: "relative", paddingBottom: "calc(50.520833333333336% + 41px)", height: "0", width: "100%" }}>
33+
<iframe src="https://demo.arcade.software/xA1AYQZs2KIdFl5qwWD9?embed" frameborder="0" loading="lazy" webkitallowfullscreen mozallowfullscreen allowfullscreen style={{ position: "absolute", top: "0", left: "0", width: "100%", height: "100%", colorScheme: "light" }} title="Appsmith | Connect Data">
34+
</iframe>
35+
</div>
36+
37+
38+
1. Create a new Query module to fetch data by clicking on the **+** icon in the top-left corner.
39+
40+
41+
<dd>
42+
43+
*Example:* If you want to display product details in a chart widget based on the category selected by the user, you can create a SQL query like:
44+
45+
```sql
46+
SELECT * FROM public."product"
47+
WHERE category = `Apparel`;
48+
```
49+
50+
</dd>
51+
52+
2. Create an **Input** from the right-side property pane to dynamically pass data to the query.
53+
54+
<dd>
55+
56+
*Example:* To dynamically pass category information to your query, use the `inputs` property as shown below:
57+
58+
```sql
59+
SELECT * FROM public."product"
60+
WHERE category = {{inputs.category}};
61+
```
62+
63+
</dd>
64+
65+
66+
3. Create a new JS module to run the query module and manipulate the query data:
67+
68+
69+
<dd>
70+
71+
* To access the **Query module data in the JS module**, use the reference properties of the query module, like: `productData.data`.
72+
73+
* To pass data from the **JS module to Query modules**, you can pass parameters at runtime using `run()`, like `{{ productData.run({ id: product.category }) }}`.
74+
75+
* To access the **JS module data in the Query module**, create input parameters and use them inside the query, like `{{inputs.category}}`.
76+
77+
78+
79+
*Example:* If you want to visualize inventory data in a chart widget, this JS module fetches product details based on the selected category.
80+
81+
```js
82+
export default {
83+
async fetchProductsByCategory(categoryName) {
84+
try {
85+
// Pass category name to Query module
86+
const productsData = await fetchProductsByCategoryQuery.run({ category: categoryName });
87+
88+
// Format product data for display
89+
const formattedProductsData = productsData.map(product => {
90+
return {
91+
x: product.product_name,
92+
y: product.stock,
93+
// Add more fields as needed
94+
};
95+
});
96+
97+
return formattedProductsData; // Return formatted product data
98+
} catch (error) {
99+
console.error('Error fetching product data:', error);
100+
throw error; // Propagate the error for handling elsewhere if needed
101+
}
102+
},
103+
};
104+
```
105+
106+
</dd>
107+
108+
109+
110+
3. Publish the package.
111+
112+
4. Open your App from the homepage and ensure that both the app and modules share the same workspace.
113+
114+
5. Select the *JS* tab on the Entity Explorer, add the JS module, and configure it to **Run on page load**.
115+
116+
6. Drag a Chart widget and configure the **Series data** property to display data from the JS module.
117+
118+
<dd>
119+
120+
*Example:*
121+
122+
```js
123+
{{productModule1.fetchProductsByCategory.data}}
124+
```
125+
126+
</dd>
127+
128+
7. Drag a Select widget and configure the **Source data** property to display a list of product categories.
129+
130+
131+
8. Configure the **onOptionChange** event of the Select widget to run the JS module function when an option is selected.
132+
133+
<dd>
134+
135+
*Example:*
136+
137+
```js
138+
{{productModule1.fetchProductsByCategory(Select1.selectedOptionValue);}}
139+
```
140+
141+
</dd>
142+
143+
144+
145+

0 commit comments

Comments
 (0)