diff --git a/packages/pluggableWidgets/web-view-native/CHANGELOG.md b/packages/pluggableWidgets/web-view-native/CHANGELOG.md index 3ed7b5059..b926e862c 100644 --- a/packages/pluggableWidgets/web-view-native/CHANGELOG.md +++ b/packages/pluggableWidgets/web-view-native/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Added + +- We added GET and POST request method selection for the url +- We added the option to pass a list of headers with the request + ## [4.1.0] - 2024-12-3 ### Changed diff --git a/packages/pluggableWidgets/web-view-native/package.json b/packages/pluggableWidgets/web-view-native/package.json index cd2bf99a4..50d4e1484 100644 --- a/packages/pluggableWidgets/web-view-native/package.json +++ b/packages/pluggableWidgets/web-view-native/package.json @@ -1,7 +1,7 @@ { "name": "web-view-native", "widgetName": "WebView", - "version": "4.1.0", + "version": "4.2.0", "license": "Apache-2.0", "repository": { "type": "git", diff --git a/packages/pluggableWidgets/web-view-native/src/WebView.tsx b/packages/pluggableWidgets/web-view-native/src/WebView.tsx index b32681e88..d4d7aa353 100644 --- a/packages/pluggableWidgets/web-view-native/src/WebView.tsx +++ b/packages/pluggableWidgets/web-view-native/src/WebView.tsx @@ -27,10 +27,25 @@ export class WebView extends Component { ); } + const source = html + ? { html } + : { + uri: uri!, + method: this.props.requestMethod, + ...(this.props.requestMethod === "POST" && + this.props.postBody && { body: this.props.postBody.value }), + ...(this.props.headerList.length && { + headers: Object.assign( + {}, + ...this.props.headerList.map(h => ({ [h.headerName.value!]: h.headerValue.value })) + ) + }) + }; + return ( On load - + On error - + @@ -34,11 +34,41 @@ Message attribute The attribute where the input message will be stored. This can be used to read the input in the onMessage event. - + + + Request method + The method verb for the request + + GET + POST + + + + POST Body + The body that will be send in the POST request + + + Header list + On Android, header pass-through is only supported with the GET method + + + + Header name + Name of the header + + + + Header value + Value of the header + + + + + User agent A custom user agent string will be included with the request. diff --git a/packages/pluggableWidgets/web-view-native/src/__tests__/WebView.spec.tsx b/packages/pluggableWidgets/web-view-native/src/__tests__/WebView.spec.tsx index 8255903c8..a4163042a 100644 --- a/packages/pluggableWidgets/web-view-native/src/__tests__/WebView.spec.tsx +++ b/packages/pluggableWidgets/web-view-native/src/__tests__/WebView.spec.tsx @@ -19,6 +19,8 @@ describe("WebView", () => { name: "webview-test", style: [], url: dynamicValue("https://mendix.com"), + requestMethod: "GET", + headerList: [], userAgent: "", openLinksExternally: false }; @@ -29,6 +31,26 @@ describe("WebView", () => { expect(component.toJSON()).toMatchSnapshot(); }); + it("renders a web view when a url with POST method and body is provided", () => { + const component = render( + + ); + expect(component.toJSON()).toMatchSnapshot(); + }); + + it("renders a web view when a url with headers is provided", () => { + const component = render( + + ); + expect(component.toJSON()).toMatchSnapshot(); + }); + it("renders a web view when html content is provided", () => { const component = render(); expect(component.toJSON()).toMatchSnapshot(); diff --git a/packages/pluggableWidgets/web-view-native/src/__tests__/__snapshots__/WebView.spec.tsx.snap b/packages/pluggableWidgets/web-view-native/src/__tests__/__snapshots__/WebView.spec.tsx.snap index 635295219..b890956a7 100644 --- a/packages/pluggableWidgets/web-view-native/src/__tests__/__snapshots__/WebView.spec.tsx.snap +++ b/packages/pluggableWidgets/web-view-native/src/__tests__/__snapshots__/WebView.spec.tsx.snap @@ -48,6 +48,7 @@ exports[`WebView renders a web view when a url is provided 1`] = ` setSupportMultipleWindows={true} source={ { + "method": "GET", "uri": "https://mendix.com", } } @@ -73,7 +74,7 @@ exports[`WebView renders a web view when a url is provided 1`] = ` `; -exports[`WebView renders a web view when html content is provided 1`] = ` +exports[`WebView renders a web view when a url with POST method and body is provided 1`] = ` + + +`; + +exports[`WebView renders a web view when a url with headers is provided 1`] = ` + + + + + +`; + +exports[`WebView renders a web view when html content is provided 1`] = ` + + + - + diff --git a/packages/pluggableWidgets/web-view-native/typings/WebViewProps.d.ts b/packages/pluggableWidgets/web-view-native/typings/WebViewProps.d.ts index c13486857..aeeeae2ad 100644 --- a/packages/pluggableWidgets/web-view-native/typings/WebViewProps.d.ts +++ b/packages/pluggableWidgets/web-view-native/typings/WebViewProps.d.ts @@ -6,6 +6,18 @@ import { CSSProperties } from "react"; import { ActionValue, DynamicValue, EditableValue } from "mendix"; +export type RequestMethodEnum = "GET" | "POST"; + +export interface HeaderListType { + headerName: DynamicValue; + headerValue: DynamicValue; +} + +export interface HeaderListPreviewType { + headerName: string; + headerValue: string; +} + export interface WebViewProps