add url input for url jdd argument
Summary: Ref T2859 Reviewers: kuba-orlik Reviewed By: kuba-orlik Subscribers: jenkins-user Maniphest Tasks: T2859 Differential Revision: https://hub.sealcode.org/D1386
This commit is contained in:
parent
ec457ebd76
commit
20ae31bff8
@ -1,4 +1,4 @@
|
|||||||
import { Enum, Image, List, Structured, Table, TableData } from "@sealcode/jdd";
|
import { ComponentArguments, Enum, Image, List, Structured, Table, TableData } from "@sealcode/jdd";
|
||||||
import { ComponentArgument } from "@sealcode/jdd";
|
import { ComponentArgument } from "@sealcode/jdd";
|
||||||
import { StatefulPage } from "@sealcode/sealgen";
|
import { StatefulPage } from "@sealcode/sealgen";
|
||||||
import { TempstreamJSX } from "tempstream";
|
import { TempstreamJSX } from "tempstream";
|
||||||
@ -10,6 +10,9 @@ import { ComponentInputStructured } from "./component-input-structured.js";
|
|||||||
import { ComponentInputTable } from "./component-input-table.js";
|
import { ComponentInputTable } from "./component-input-table.js";
|
||||||
import { printArgPath } from "./print-arg-path.js";
|
import { printArgPath } from "./print-arg-path.js";
|
||||||
|
|
||||||
|
export const actionName = "Components";
|
||||||
|
const absoluteUrlPattern = "http(s?)(://)((www.)?)(([^.]+).)?([a-zA-z0-9-_]+)";
|
||||||
|
|
||||||
export function ComponentInput<State extends ComponentPreviewState, T>({
|
export function ComponentInput<State extends ComponentPreviewState, T>({
|
||||||
state,
|
state,
|
||||||
arg_path,
|
arg_path,
|
||||||
@ -30,6 +33,12 @@ export function ComponentInput<State extends ComponentPreviewState, T>({
|
|||||||
return ComponentInputList({ state, arg_path, arg, value: value as T[], page });
|
return ComponentInputList({ state, arg_path, arg, value: value as T[], page });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const argType = arg.getTypeName();
|
||||||
|
const isUrlAbsolute =
|
||||||
|
arg instanceof ComponentArguments.URL &&
|
||||||
|
arg.urlType === "absolute";
|
||||||
|
const inputType = isUrlAbsolute ? "url" : "text";
|
||||||
|
|
||||||
if (arg instanceof Structured) {
|
if (arg instanceof Structured) {
|
||||||
return ComponentInputStructured({
|
return ComponentInputStructured({
|
||||||
state,
|
state,
|
||||||
@ -74,7 +83,7 @@ export function ComponentInput<State extends ComponentPreviewState, T>({
|
|||||||
<div>
|
<div>
|
||||||
<label>
|
<label>
|
||||||
{arg_path.at(-1) || ""}
|
{arg_path.at(-1) || ""}
|
||||||
{arg.getTypeName() == "markdown" ? (
|
{argType == "markdown" ? (
|
||||||
<textarea
|
<textarea
|
||||||
name={`$.component_args${printArgPath(arg_path)}`}
|
name={`$.component_args${printArgPath(arg_path)}`}
|
||||||
onblur={page.rerender()}
|
onblur={page.rerender()}
|
||||||
@ -84,10 +93,11 @@ export function ComponentInput<State extends ComponentPreviewState, T>({
|
|||||||
</textarea>
|
</textarea>
|
||||||
) : (
|
) : (
|
||||||
<input
|
<input
|
||||||
type="text"
|
type={inputType}
|
||||||
name={`$.component_args${printArgPath(arg_path)}`}
|
name={`$.component_args${printArgPath(arg_path)}`}
|
||||||
value={value as string}
|
value={value as string}
|
||||||
size="40"
|
size="40"
|
||||||
|
pattern={isUrlAbsolute ? absoluteUrlPattern : undefined}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</label>
|
</label>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user