-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
376 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { FC } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { MenuItem, SxProps } from "@mui/material"; | ||
import { TextField } from "@mui/material/"; | ||
import { FormSelectMenuItem } from "./formSelect.tsx"; | ||
|
||
// This component is needed as an intermediate step to refactor borehole input. | ||
// The standard form components are not usable with autosave components as they are now. | ||
// Once the saving mechanism is refactored, this component can be replaced. | ||
|
||
interface SimpleBooleanSelectProps { | ||
fieldName: string; | ||
label: string; | ||
required?: boolean; | ||
disabled?: boolean; | ||
readonly?: boolean; | ||
selected?: number | boolean | null; | ||
sx?: SxProps; | ||
className?: string; | ||
onUpdate?: (value: number | boolean | string | null) => void; | ||
} | ||
|
||
export const SimpleBooleanSelect: FC<SimpleBooleanSelectProps> = ({ | ||
fieldName, | ||
label, | ||
required, | ||
disabled, | ||
readonly, | ||
selected, | ||
sx, | ||
className, | ||
onUpdate, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const menuItems: FormSelectMenuItem[] = []; | ||
if (!required) { | ||
menuItems.push({ key: 0, value: undefined, label: t("reset"), italic: true }); | ||
} | ||
|
||
const value = selected === true ? 1 : selected === false ? 0 : 2; | ||
|
||
const values = [ | ||
{ key: 1, name: t("yes") }, | ||
{ key: 0, name: t("no") }, | ||
{ key: 2, name: t("np") }, | ||
]; | ||
|
||
values.forEach(v => | ||
menuItems.push({ | ||
key: v.key, | ||
value: v.key, | ||
label: v.name, | ||
}), | ||
); | ||
|
||
return ( | ||
<TextField | ||
required={required} | ||
className={`${readonly ? "readonly" : ""} ${className || ""}`} | ||
select | ||
sx={{ ...sx }} | ||
label={t(label)} | ||
name={fieldName} | ||
onChange={e => | ||
onUpdate | ||
? onUpdate(parseInt(e.target.value) === 1 ? true : parseInt(e.target.value) === 0 ? false : null) | ||
: null | ||
} | ||
value={value} | ||
disabled={disabled ?? false} | ||
data-cy={fieldName + "-formSelect"} | ||
InputProps={{ readOnly: readonly, disabled: disabled }}> | ||
{menuItems.map(item => ( | ||
<MenuItem key={item.key} value={item.value}> | ||
{item.italic ? <em>{item.label}</em> : item.label} | ||
</MenuItem> | ||
))} | ||
</TextField> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { FC } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { MenuItem, SxProps } from "@mui/material"; | ||
import { TextField } from "@mui/material/"; | ||
import { useDomains } from "../../api/fetchApiV2"; | ||
import { Codelist } from "../legacyComponents/domain/domainInterface.ts"; | ||
import { FormSelectMenuItem } from "./formSelect.tsx"; | ||
|
||
// This component is needed as an intermediate step to refactor borehole input. | ||
// The standard form components are not usable with autosave components as they are now. | ||
// Once the saving mechanism is refactored, this component can be replaced. | ||
|
||
interface SimpleDomainSelectProps { | ||
fieldName: string; | ||
schemaName: string; | ||
label: string; | ||
required?: boolean; | ||
disabled?: boolean; | ||
readonly?: boolean; | ||
selected?: number | boolean | null; | ||
sx?: SxProps; | ||
className?: string; | ||
onUpdate?: (value: number | boolean | string | null) => void; | ||
} | ||
|
||
export const SimpleDomainSelect: FC<SimpleDomainSelectProps> = ({ | ||
fieldName, | ||
label, | ||
required, | ||
disabled, | ||
readonly, | ||
selected, | ||
schemaName, | ||
sx, | ||
className, | ||
onUpdate, | ||
}) => { | ||
const { t, i18n } = useTranslation(); | ||
const { data: domains } = useDomains(); | ||
|
||
const menuItems: FormSelectMenuItem[] = []; | ||
if (!required) { | ||
menuItems.push({ key: 0, value: undefined, label: t("reset"), italic: true }); | ||
} | ||
domains | ||
?.filter((d: Codelist) => d.schema === schemaName) | ||
.sort((a: Codelist, b: Codelist) => a.order - b.order) | ||
.forEach((d: Codelist) => | ||
menuItems.push({ | ||
key: d.id, | ||
value: d.id, | ||
label: d[i18n.language] as string, | ||
}), | ||
); | ||
|
||
return ( | ||
<TextField | ||
required={required} | ||
className={`${readonly ? "readonly" : ""} ${className || ""}`} | ||
select | ||
sx={{ ...sx }} | ||
label={t(label)} | ||
name={fieldName} | ||
onChange={e => { | ||
if (onUpdate) { | ||
onUpdate(e.target.value); | ||
} | ||
}} | ||
value={selected} | ||
disabled={disabled ?? false} | ||
data-cy={fieldName + "-formSelect"} | ||
InputProps={{ readOnly: readonly, disabled: disabled }}> | ||
{menuItems.map(item => ( | ||
<MenuItem key={item.key} value={item.value}> | ||
{item.italic ? <em>{item.label}</em> : item.label} | ||
</MenuItem> | ||
))} | ||
</TextField> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { FC } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { InputProps, SxProps, TextField } from "@mui/material"; | ||
import { FormValueType } from "./form.ts"; | ||
import { NumericFormatWithThousandSeparator } from "./numericFormatWithThousandSeparator.tsx"; | ||
|
||
interface SimpleInputProps { | ||
label: string; | ||
required?: boolean; | ||
disabled?: boolean; | ||
readonly?: boolean; | ||
type?: FormValueType; | ||
multiline?: boolean; | ||
rows?: number; | ||
value?: string | number | Date | null; | ||
sx?: SxProps; | ||
className?: string; | ||
inputProps?: InputProps; | ||
onUpdate?: (value: string) => void; | ||
withThousandSeparator?: boolean; | ||
} | ||
|
||
// This component is needed as an intermediate step to refactor borehole input. | ||
// The standard form components are not usable with autosave components as they are now. | ||
// Once the saving mechanism is refactored, this component can be replaced. | ||
|
||
export const SimpleFormInput: FC<SimpleInputProps> = ({ | ||
value, | ||
className, | ||
required, | ||
readonly, | ||
rows, | ||
onUpdate, | ||
label, | ||
type, | ||
multiline, | ||
withThousandSeparator, | ||
inputProps, | ||
disabled, | ||
sx, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<TextField | ||
required={required || false} | ||
sx={{ ...sx }} | ||
className={`${readonly ? "readonly" : ""} ${className || ""}`} | ||
type={type || FormValueType.Text} | ||
multiline={multiline || false} | ||
rows={rows} | ||
value={value} | ||
label={t(label)} | ||
data-cy={label + "-formInput"} | ||
onChange={e => { | ||
if (onUpdate) { | ||
onUpdate(e.target.value); | ||
} | ||
}} | ||
InputProps={{ | ||
...inputProps /* eslint-disable @typescript-eslint/no-explicit-any */, | ||
...(withThousandSeparator && { inputComponent: NumericFormatWithThousandSeparator as any }), | ||
readOnly: readonly, | ||
disabled: disabled, | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.