added some initial work on intl

This commit is contained in:
ari committed 2022-08-29 12:51:24 -04:00
1 parent 157efa04b1
commit caad458b48
22 files changed
+588 -155

No files matched your search

@@ -9,6 +9,7 @@ import FormHelperText from "@mui/material/FormHelperText";
import InputAdornment from "@mui/material/InputAdornment";
import { Save } from "@mui/icons-material";
import { ButtonIcon } from "components/Icons/ButtonIcons";
import { useLang } from "lang";
export interface Props<T extends {}> {
label: string;
@@ -34,6 +35,7 @@ export default function InputYaml<T extends {}>({
helperText,
endAdornment,
}: Props<T>) {
const langStore = useLang();
const originalText = yaml.dump(value);
const [{ text, error }, setState] = useState<{
text: string;
@@ -48,7 +50,7 @@ export default function InputYaml<T extends {}>({
yaml.load(t);
setState({ text: t, error: undefined });
} catch (_) {
setState({ text: t, error: "! Invalid Yaml !" });
setState({ text: t, error: langStore.get("ERROR_INVALID_YAML") });
}
};
const onSave = () => {
@@ -94,7 +96,9 @@ export default function InputYaml<T extends {}>({
<ButtonIcon
disabled={!hasChanged}
onClick={() => onSave()}
title={!!error ? "Invalid YAML" : hasChanged ? "Save" : ""}
title={
!!error ? "Invalid YAML" : hasChanged ? langStore.get("SAVE") : ""
}
icon={
<Save
color={hasChanged ? (!!error ? "error" : "success") : "disabled"}
+17 -1
View File
@@ -7,6 +7,7 @@ import FormControl from "@mui/material/FormControl";
import Select from "@mui/material/Select";
import { prettyName } from "utils/formatting";
import { ReactNode } from "react";
import { useLang } from "lang";
export type Props<T extends string | Object> = {
current?: T;
@@ -17,6 +18,7 @@ export type Props<T extends string | Object> = {
className?: string;
prettyOptionLabels?: boolean;
getKey?: (n: T) => string;
getLabel?: (n: T) => string;
getDescription?: (n: T) => string;
placeholder?: any;
title?: string;
@@ -34,6 +36,7 @@ export function InputList<T extends string | Object>({
className,
prettyOptionLabels = true,
getKey = String,
getLabel: _getLabel,
getDescription,
placeholder,
title,
@@ -42,8 +45,17 @@ export function InputList<T extends string | Object>({
disabled,
fullWidth = true,
}: Props<T>) {
const langStore = useLang();
const invalidCurrent =
current && !options.map(getKey).includes(getKey(current));
const getLabel =
_getLabel ??
function (x: T) {
return typeof x === "string"
? prettyName(langStore.get(x.toUpperCase()))
: getKey(x);
};
return (
<FormControl
className={className}
@@ -73,7 +85,11 @@ export function InputList<T extends string | Object>({
>
{options.map((t, i) => (
<MenuItem key={i} value={getKey(t)} className="input-list--menu-item">
{prettyOptionLabels ? prettyName(getKey(t)) : getKey(t)}
{prettyOptionLabels
? prettyName(getKey(t))
: getLabel
? getLabel(t)
: getKey(t)}
{!!getDescription && (
<>
<br />
@@ -5,6 +5,7 @@ import Autocomplete from "@mui/material/Autocomplete";
import TextField from "@mui/material/TextField";
import Checkbox from "@mui/material/Checkbox";
import { useSnackbar } from "notistack";
import { useLang } from "lang";
export interface Props<T extends string> {
label: string;
@@ -23,6 +24,7 @@ export default function InputMultiSelect<T extends string>({
max = 3,
}: Props<T>) {
// alias
const langStore = useLang();
const snackbr = useSnackbar();
return (
<Autocomplete
@@ -31,10 +33,13 @@ export default function InputMultiSelect<T extends string>({
value={selected.map((i) => options[i])}
onChange={(_, newValues: T[] = []) => {
if (newValues.length > max) {
snackbr.enqueueSnackbar("Can only select up to 3 tags", {
variant: "warning",
autoHideDuration: 1500,
});
snackbr.enqueueSnackbar(
langStore.get("VALIDATION_MAX_TAG_SELECTION", { count: "3" }),
{
variant: "warning",
autoHideDuration: 1500,
}
);
}
onChange(
newValues