Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate trigger form params to new UI #45270

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
62d5c18
Add flexible form fields to trigger form WIP
jscheffl Dec 29, 2024
72c399b
Add flexible form fields to trigger form WIP
jscheffl Dec 29, 2024
1bb0df6
Fix dropdown issue
jscheffl Dec 30, 2024
afc50b2
Add support for arrays of strings
jscheffl Dec 30, 2024
4cd9802
Add support for advanced arrays
jscheffl Dec 30, 2024
07f0ff1
Remove placeholder for string
jscheffl Dec 30, 2024
b44534b
Add support for proposals in string fields
jscheffl Dec 30, 2024
4bc3909
Add support for multi-select dropdowns
jscheffl Dec 30, 2024
31fb834
Add support for object fields
jscheffl Dec 31, 2024
6754033
Add support for number fields
jscheffl Dec 31, 2024
f9220ca
Add support for multiline text fields
jscheffl Dec 31, 2024
b0b7cda
Use other component for multi-select which displays the values
jscheffl Jan 2, 2025
507a7c6
Implement support for form sections
jscheffl Jan 2, 2025
c589378
Implement support for form sections
jscheffl Jan 2, 2025
3a96f5a
Add an alert that form ist not fully implemented
jscheffl Jan 2, 2025
0b4cc55
Review feedback - safe string handling
jscheffl Jan 4, 2025
030a067
Review feedback, remove reloading warnings, move selector functions t…
jscheffl Jan 4, 2025
9c626e3
Review feedback - rename components for shorter name
jscheffl Jan 8, 2025
2d18410
Review feedback - adjust hard-coded color for boder in CodeMirror
jscheffl Jan 8, 2025
907f11f
Rework default field values
jscheffl Jan 9, 2025
b27ebe9
Move form elements into a common accorion
jscheffl Jan 11, 2025
d73aa62
Review feedback
jscheffl Jan 14, 2025
7028d76
Review feedback, next round
jscheffl Jan 15, 2025
c7a96cf
Remove un-needed placeholders in date-time picker
jscheffl Jan 15, 2025
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
5 changes: 3 additions & 2 deletions airflow/example_dags/example_params_ui_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
# If you want to have a list box with proposals but not enforcing a fixed list
# then you can use the examples feature of JSON schema
"proposals": Param(
"some value",
"Alpha",
type="string",
title="Field with proposals",
description="You can use JSON schema examples's to generate drop down selection boxes "
Expand Down Expand Up @@ -169,6 +169,7 @@
"multiline_text": Param(
"A multiline text Param\nthat will keep the newline\ncharacters in its value.",
description="This field allows for multiline text input. The returned value will be a single with newline (\\n) characters kept intact.",
title="Multiline text",
type=["string", "null"],
format="multiline",
),
Expand Down Expand Up @@ -205,7 +206,7 @@
[schema description (string)](https://json-schema.org/understanding-json-schema/reference/string.html)
for more details""",
minLength=10,
maxLength=20,
maxLength=30,
section="JSON Schema validation options",
),
"checked_number": Param(
Expand Down
52 changes: 52 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FieldAdvancedArray.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { json } from "@codemirror/lang-json";
import { githubLight, githubDark } from "@uiw/codemirror-themes-all";
import CodeMirror from "@uiw/react-codemirror";

import { useColorMode } from "src/context/colorMode";

import type { FlexibleFormElementProps } from ".";

export const FieldAdvancedArray = ({ name, param }: FlexibleFormElementProps) => {
const { colorMode } = useColorMode();

return (
<CodeMirror
basicSetup={{
autocompletion: true,
bracketMatching: true,
foldGutter: true,
lineNumbers: true,
}}
extensions={[json()]}
height="200px"
id={`element_${name}`}
style={{
border: "1px solid var(--chakra-colors-border)",
borderRadius: "8px",
outline: "none",
padding: "2px",
width: "100%",
}}
theme={colorMode === "dark" ? githubDark : githubLight}
value={JSON.stringify(param.value ?? [], undefined, 2)}
/>
);
};
29 changes: 29 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FieldBool.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import type { FlexibleFormElementProps } from ".";
import { Switch } from "../ui";

export const FieldBool = ({ name, param }: FlexibleFormElementProps) => (
<Switch
colorPalette="blue"
defaultChecked={Boolean(param.value)}
id={`element_${name}`}
name={`element_${name}`}
/>
);
31 changes: 31 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FieldDateTime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { Input, type InputProps } from "@chakra-ui/react";

import type { FlexibleFormElementProps } from ".";

export const FieldDateTime = ({ name, param, ...rest }: FlexibleFormElementProps & InputProps) => (
<Input
defaultValue={typeof param.value === "string" ? param.value : undefined}
id={`element_${name}`}
name={`element_${name}`}
size="sm"
type={rest.type}
/>
);
66 changes: 66 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FieldDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { createListCollection } from "@chakra-ui/react/collection";
import { useRef } from "react";

import { Select } from "src/components/ui";

import type { FlexibleFormElementProps } from ".";

const labelLookup = (key: string, valuesDisplay: Record<string, string> | undefined): string => {
if (valuesDisplay && typeof valuesDisplay === "object") {
return valuesDisplay[key] ?? key;
}

return key;
};
const enumTypes = ["string", "number", "integer"];

export const FieldDropdown = ({ name, param }: FlexibleFormElementProps) => {
const selectOptions = createListCollection({
items:
param.schema.enum?.map((value) => ({
label: labelLookup(value, param.schema.values_display),
value,
})) ?? [],
});
const contentRef = useRef<HTMLDivElement>(null);

return (
<Select.Root
collection={selectOptions}
defaultValue={enumTypes.includes(typeof param.value) ? [String(param.value)] : undefined}
id={`element_${name}`}
name={`element_${name}`}
ref={contentRef}
size="sm"
>
<Select.Trigger>
<Select.ValueText placeholder="Select Value" />
</Select.Trigger>
<Select.Content portalRef={contentRef}>
{selectOptions.items.map((option) => (
<Select.Item item={option} key={option.value}>
{option.label}
</Select.Item>
))}
</Select.Content>
</Select.Root>
);
};
60 changes: 60 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FieldMultiSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { Select as ReactSelect } from "chakra-react-select";
import { useState } from "react";

import type { FlexibleFormElementProps } from ".";

const labelLookup = (key: string, valuesDisplay: Record<string, string> | undefined): string => {
if (valuesDisplay && typeof valuesDisplay === "object") {
return valuesDisplay[key] ?? key;
}

return key;
};

export const FieldMultiSelect = ({ name, param }: FlexibleFormElementProps) => {
const [selectedOptions, setSelectedOptions] = useState(
Array.isArray(param.value)
? (param.value as Array<string>).map((value) => ({
label: labelLookup(value, param.schema.values_display),
value,
}))
: [],
);

return (
<ReactSelect
aria-label="Select one or multiple values"
id={`element_${name}`}
isClearable
isMulti
name={`element_${name}`}
onChange={(newValue) => setSelectedOptions([...newValue])}
options={
param.schema.examples?.map((value) => ({
label: labelLookup(value, param.schema.values_display),
value,
})) ?? []
}
size="sm"
value={selectedOptions}
/>
);
};
31 changes: 31 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FieldMultilineText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { Textarea } from "@chakra-ui/react";

import type { FlexibleFormElementProps } from ".";

export const FieldMultilineText = ({ name, param }: FlexibleFormElementProps) => (
<Textarea
defaultValue={String(param.value ?? "")}
id={`element_${name}`}
name={`element_${name}`}
rows={6}
size="sm"
/>
);
34 changes: 34 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FieldNumber.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import type { FlexibleFormElementProps } from ".";
import { NumberInputField, NumberInputRoot } from "../ui/NumberInput";

export const FieldNumber = ({ name, param }: FlexibleFormElementProps) => (
<NumberInputRoot
allowMouseWheel
defaultValue={String(param.value ?? "")}
id={`element_${name}`}
max={param.schema.maximum ?? undefined}
min={param.schema.minimum ?? undefined}
name={`element_${name}`}
size="sm"
>
<NumberInputField />
</NumberInputRoot>
);
52 changes: 52 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FieldObject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { json } from "@codemirror/lang-json";
import { githubLight, githubDark } from "@uiw/codemirror-themes-all";
import CodeMirror from "@uiw/react-codemirror";

import { useColorMode } from "src/context/colorMode";

import type { FlexibleFormElementProps } from ".";

export const FieldObject = ({ name, param }: FlexibleFormElementProps) => {
const { colorMode } = useColorMode();

return (
<CodeMirror
basicSetup={{
autocompletion: true,
bracketMatching: true,
foldGutter: true,
lineNumbers: true,
}}
extensions={[json()]}
height="200px"
id={`element_${name}`}
style={{
border: "1px solid var(--chakra-colors-border)",
borderRadius: "8px",
outline: "none",
padding: "2px",
width: "100%",
}}
theme={colorMode === "dark" ? githubDark : githubLight}
value={JSON.stringify(param.value ?? {}, undefined, 2)}
/>
);
};
Loading