Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(site): Support list(string) rich parameter field#6653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 3 commits intomainfrombq/multi-string-field
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Add field to reach parameters input
  • Loading branch information
@BrunoQuaresma
BrunoQuaresma committedMar 17, 2023
commit55e272a95a416fdaad02f70b22e4ddd0e79827cc
1 change: 1 addition & 0 deletionssite/src/components/MultiTextField/MultiTextField.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@ const useStyles = makeStyles((theme) => ({
flexWrap: "wrap",
gap: theme.spacing(1),
position: "relative",
margin: theme.spacing(1, 0, 0.5), // Have same margin than TextField

"&:has(input:focus)": {
borderColor: theme.palette.primary.main,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,7 @@ const createTemplateVersionParameter = (
validation_max: 0,
validation_monotonic: "increasing",
description_plaintext: "",
required: true,
...partial,
}
}
Expand DownExpand Up@@ -99,6 +100,17 @@ OptionsType.args = {
}),
}

export const ListStringType = Template.bind({})
ListStringType.args = {
initialValue: JSON.stringify(["first", "second", "third"]),
id: "list_string_parameter",
parameter: createTemplateVersionParameter({
name: "list_string_parameter",
type: "list(string)",
description: "List string parameter",
}),
}

export const IconLabel = Template.bind({})
IconLabel.args = {
initialValue: "initial-value",
Expand Down
27 changes: 27 additions & 0 deletionssite/src/components/RichParameterInput/RichParameterInput.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import { FC, useState } from "react"
import { TemplateVersionParameter } from "../../api/typesGenerated"
import { colors } from "theme/colors"
import { MemoizedMarkdown } from "components/Markdown/Markdown"
import { MultiTextField } from "components/MultiTextField/MultiTextField"

const isBoolean = (parameter: TemplateVersionParameter) => {
return parameter.type === "bool"
Expand DownExpand Up@@ -154,6 +155,32 @@ const RichParameterField: React.FC<RichParameterInputProps> = ({
)
}

if (parameter.type === "list(string)") {
let values: string[] = []

if (parameterValue) {
try {
values = JSON.parse(parameterValue) as string[]
} catch (e) {
console.error("Error parsing list(string) parameter", e)
}
}

return (
<MultiTextField
label={props.label as string}
values={values}
onChange={(values) => {
try {
onChange(JSON.stringify(values))
} catch (e) {
console.error("Error on change of list(string) parameter", e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Do we need to do anything else with error handling here or on line 165?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is something we control but in case it gets an error, I added a message to help a bit more.

}
}}
/>
)
}

// A text field can technically handle all cases!
// As other cases become more prominent (like filtering for numbers),
// we should break this out into more finely scoped input fields.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp