Skip to content

1904 lib create port #1973

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ import { FormValidationError } from '@/types';
import { Footer } from './Footer';
import { Header } from './Header';
import { Row } from './Row';
import { Checkbox, Divider, Label, Summary, Text, TextArea } from './fields';
import {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not forget the changeset file in the PR

Checkbox,
Divider,
Integer,
Label,
Radio,
Summary,
Text,
TextArea,
} from './fields';

interface WfoPydanticFormProps {
processName: string;
Expand Down Expand Up @@ -209,6 +218,32 @@ export const WfoPydanticForm = ({
return field.type === PydanticFormFieldType.BOOLEAN;
},
},
{
id: 'radio',
ElementMatch: {
Element: Radio,
isControlledElement: true,
},
matcher(field) {
// We are looking for a single value from a set list of options. With less than 4 options, use radio buttons.
return (
field.type === PydanticFormFieldType.STRING &&
field.options.length > 0 &&
field.options.length <= 3
);
},
},
{
id: 'integerfield',
ElementMatch: {
Element: Integer,
isControlledElement: true,
},
matcher(field) {
return field.type === PydanticFormFieldType.INTEGER;
},
validator: zodValidationPresets.integer,
},
...currentMatchers.filter((matcher) => matcher.id !== 'text'),
{
id: 'text',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';

import type { PydanticFormControlledElement } from 'pydantic-forms';

import { EuiFieldNumber } from '@elastic/eui';
import { css } from '@emotion/react';

import type { WfoTheme } from '@/hooks';
import { useWithOrchestratorTheme } from '@/hooks';

const getFormFieldsBaseStyle = ({ theme }: WfoTheme) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider to move this one to its own styles file. Either one specific for this field or just one for all fields

const formFieldBaseStyle = css({
backgroundColor: theme.colors.body,
color: theme.colors.text,
'&:focus': {
backgroundColor: theme.colors.emptyShade,
},
});

return {
formFieldBaseStyle,
};
};

export const Integer: PydanticFormControlledElement = ({
pydanticFormField,
onChange,
value,
disabled,
}) => {
const { formFieldBaseStyle } = useWithOrchestratorTheme(
getFormFieldsBaseStyle,
);

return (
<EuiFieldNumber
css={formFieldBaseStyle}
name={pydanticFormField.id}
onChange={(event) => onChange(parseInt(event.target.value))}
value={value}
disabled={disabled}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

import type { PydanticFormControlledElement } from 'pydantic-forms';

import { EuiRadioGroup } from '@elastic/eui';

export const Radio: PydanticFormControlledElement = ({
pydanticFormField,
onChange,
value,
disabled,
}) => {
const radioOptions = pydanticFormField.options.map((option) => ({
id: option.value,
label: option.label,
}));

return (
<EuiRadioGroup
options={radioOptions}
idSelected={value}
onChange={(id) => onChange(id)}
name={pydanticFormField.id}
disabled={disabled}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export * from './Label';
export * from './Divider';
export * from './Checkbox';
export * from './Summary';
export * from './Radio';
export * from './Integer';
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"nodePort": {
"loadingNodes": "Loading Node subscriptions...",
"loadingPorts": "Loading IMS ports...",
"noPorts": "NO PORTS FOUND FOR THIS NODE",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the screaming needed?

"selectNode": "Select node",
"selectPort": "Select port",
"selectNodeFirst": "Select a node first"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"loadingPorts": "IMS poorten laden...",
"selectNode": "Selecteer node",
"selectPort": "Selecteer poort",
"noPorts": "GEEN POORTEN GEVONDEN VOOR DEZE NODE",
"selectNodeFirst": "Selecteer eerst een node"
},
"fileUpload": {
Expand Down