Skip to content

Commit

Permalink
Add flexible form fields to trigger form WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jscheffl committed Dec 29, 2024
1 parent a22faa5 commit 26853c3
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 9 deletions.
34 changes: 34 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FlexibleFormFieldBool.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 { Switch } from "../ui";

export const isFieldBool = (fieldType: string) => fieldType === "boolean";

export const FlexibleFormFieldBool = ({
key,
param,
}: FlexibleFormElementProps) => (
<Switch
colorPalette="blue"
defaultChecked={param.value as boolean}
id={`element_${key}`}
name={`element_${key}`}
/>
);
38 changes: 38 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FlexibleFormFieldDate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*!
* 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 } from "@chakra-ui/react";

import type { FlexibleFormElementProps } from ".";

export const isFieldDate = (fieldType: string, fieldFormat: string | null) =>
fieldType === "string" && fieldFormat === "date";

export const FlexibleFormFieldDate = ({
key,
param,
}: FlexibleFormElementProps) => (
<Input
defaultValue={param.value as string}
id={`element_${key}`}
name={`element_${key}`}
placeholder="yyyy-mm-dd"
size="sm"
type="date"
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*!
* 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 } from "@chakra-ui/react";

import type { FlexibleFormElementProps } from ".";

export const isFieldDateTime = (
fieldType: string,
fieldFormat: string | null,
) => fieldType === "string" && fieldFormat === "date-time";

export const FlexibleFormFieldDateTime = ({
key,
param,
}: FlexibleFormElementProps) => (
<Input
defaultValue={param.value as string}
id={`element_${key}`}
name={`element_${key}`}
placeholder="yyyy-mm-ddThh:mm"
size="sm"
type="datetime-local"
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*!
* 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 { Select } from "src/components/ui";

import type { FlexibleFormElementProps } from ".";

export const isFieldDropdown = (
fieldType: string,
fieldEnum: Array<string> | null,
) => {
const enumTypes = ["string", "number", "integer"];

return enumTypes.includes(fieldType) && Array.isArray(fieldEnum);
};

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

return key;
};

export const FlexibleFormFieldDropdown = ({
key,
param,
}: FlexibleFormElementProps) => {
const selectOptions = createListCollection({
items:
param.schema.enum?.map((value) => ({
label: labelLookup(value, param.schema.values_display),
value,
})) ?? [],
});

// TODO - somehow the dropdown is not working, does not give options :-(
return (
<Select.Root
collection={selectOptions}
defaultValue={[param.value as string]}
id={`element_${key}`}
name={`element_${key}`}
size="sm"
>
<Select.Trigger>
<Select.ValueText placeholder="Select Value" />
</Select.Trigger>
<Select.Content>
{selectOptions.items.map((option) => (
<Select.Item item={option} key={option.value}>
{option.label}
</Select.Item>
))}
</Select.Content>
</Select.Root>
);
};
37 changes: 37 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FlexibleFormFieldString.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*!
* 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 } from "@chakra-ui/react";

import type { FlexibleFormElementProps } from ".";

export const FlexibleFormFieldString = ({
key,
param,
}: FlexibleFormElementProps) => (
<Input
defaultValue={param.value as string}
id={`element_${key}`}
name={`element_${key}`}
placeholder={JSON.stringify(param.value)}
size="sm"
/>
// TODO: Add features missing from the current implementation
// - Maximum Length / Minimum Length
// - Examples as proposal
);
38 changes: 38 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FlexibleFormFieldTime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*!
* 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 } from "@chakra-ui/react";

import type { FlexibleFormElementProps } from ".";

export const isFieldTime = (fieldType: string, fieldFormat: string | null) =>
fieldType === "string" && fieldFormat === "date";

export const FlexibleFormFieldTime = ({
key,
param,
}: FlexibleFormElementProps) => (
<Input
defaultValue={param.value as string}
id={`element_${key}`}
name={`element_${key}`}
placeholder="hh:mm"
size="sm"
type="time"
/>
);
40 changes: 40 additions & 0 deletions airflow/ui/src/components/FlexibleForm/FlexibleFormHidden.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*!
* 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 { VisuallyHidden } from "@chakra-ui/react";

import type { ParamSpec } from "src/queries/useDagParams";

import type { FlexibleFormElementProps } from ".";

export const isHidden = (param: ParamSpec) => Boolean(param.schema.const);

/** Render a "const" field where user can not change data as hidden */
export const FlexibleFormHidden = ({
key,
param,
}: FlexibleFormElementProps) => (
<VisuallyHidden asChild>
<input
id={`element_${key}`}
name={`element_${key}`}
type="hidden"
value={param.value as string}
/>
</VisuallyHidden>
);
Loading

0 comments on commit 26853c3

Please sign in to comment.