Skip to content

Commit

Permalink
Merge pull request #429 from Hexastack/423-feature-ux-enhancement-on-…
Browse files Browse the repository at this point in the history
…repeatable-fieldsets

feat: ux enhancement on repeatable fieldsets
  • Loading branch information
marrouchi authored Dec 11, 2024
2 parents 3a558df + e18fcb1 commit cdb8cd1
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 184 deletions.
7 changes: 7 additions & 0 deletions frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"block_event_type": "Type of event",
"patterns": "Patterns",
"no_patterns": "- No triggers -",
"no_quick_replies": "- No quick replies -",
"text_patterns": " Text Patterns",
"triggers": "Triggers",
"payloads": "Payloads",
Expand Down Expand Up @@ -558,6 +559,12 @@
"manage_roles": "Manage Roles",
"connect_with_sso": "Connect with SSO",
"add_pattern": "New Trigger",
"postback": "Postback",
"url": "Url",
"add_button": "New Button",
"add_quick_reply": "New Quick Reply",
"text": "Text",
"location": "Location",
"mark_as_default": "Mark as Default",
"toggle": "Toggle button"
},
Expand Down
7 changes: 7 additions & 0 deletions frontend/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"patterns": "Motifs",
"text_patterns": "Motifs textuels",
"no_patterns": "- Aucun motif -",
"no_quick_replies": "- Aucune réponse rapide -",
"triggers": "Déclencheurs",
"payloads": "Payloads",
"general_payloads": "Payloads généraux",
Expand Down Expand Up @@ -559,6 +560,12 @@
"manage_roles": "Gérer les rôles",
"connect_with_sso": "Se connecter avec SSO",
"add_pattern": "Ajouter un déclencheur",
"postback": "Valeur de retour",
"url": "Url",
"add_button": "Ajouter un bouton",
"add_quick_reply": "Ajouter une réponse rapide",
"text": "Texte",
"location": "Emplacement",
"mark_as_default": "Par Défaut",
"toggle": "Bouton de bascule"
},
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/app-components/buttons/DropdownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface AddPatternProps {
label?: string;
icon?: React.ReactNode;
sx?: SxProps<Theme> | undefined;
disabled?: boolean;
}

const DropdownButton: React.FC<AddPatternProps> = ({
Expand All @@ -40,10 +41,13 @@ const DropdownButton: React.FC<AddPatternProps> = ({
label = "Add",
icon,
sx,
disabled = false,
}) => {
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const handleOpen = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
if (!disabled) {
setAnchorEl(event.currentTarget);
}
};
const handleClose = () => {
setAnchorEl(null);
Expand All @@ -61,6 +65,7 @@ const DropdownButton: React.FC<AddPatternProps> = ({
onClick={handleOpen}
startIcon={icon}
endIcon={<ArrowDropDown />}
disabled={disabled}
>
{label}
</Button>
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/app-components/inputs/MultipleInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { RemoveCircleOutline } from "@mui/icons-material";
import AddIcon from "@mui/icons-material/Add";
import DeleteIcon from "@mui/icons-material/Delete";
import {
Box,
Button,
Expand Down Expand Up @@ -130,12 +130,6 @@ const MultipleInput = forwardRef<HTMLDivElement, MultipleInputProps>(
gap={1}
mb={1}
>
<IconButton
onClick={() => handleRemoveInput(input.id)}
disabled={inputs.length <= minInput}
>
<DeleteIcon />
</IconButton>
<Input
{...(getInputProps ? getInputProps(idx) : null)}
{...rest}
Expand All @@ -146,6 +140,13 @@ const MultipleInput = forwardRef<HTMLDivElement, MultipleInputProps>(
}}
fullWidth
/>
<IconButton
color="error"
onClick={() => handleRemoveInput(input.id)}
disabled={inputs.length <= minInput}
>
<RemoveCircleOutline />
</IconButton>
</Box>
))}
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { Grid, MenuItem } from "@mui/material";
import { Grid } from "@mui/material";
import { FC } from "react";
import { FieldPath, useFormContext } from "react-hook-form";

Expand All @@ -15,11 +15,7 @@ import { ToggleableInput } from "@/app-components/inputs/ToggleableInput";
import { useTranslate } from "@/hooks/useTranslate";
import { useValidationRules } from "@/hooks/useValidationRules";
import { IBlockAttributes } from "@/types/block.types";
import {
AnyButton,
ButtonType,
WebviewHeightRatio,
} from "@/types/message.types";
import { AnyButton, ButtonType } from "@/types/message.types";

const buildFieldPath = (
fieldPath: FieldPath<IBlockAttributes>,
Expand All @@ -45,45 +41,15 @@ const ButtonInput: FC<ButtonInputProps> = ({
fieldPath,
}) => {
const { t } = useTranslate();
const types: { value: ButtonType; label: string }[] = [
{ value: ButtonType.postback, label: t("label.postback") },
{ value: ButtonType.web_url, label: t("label.web_url") },
];
const rules = useValidationRules();
const setButtonType = (type: ButtonType) => {
if (type === ButtonType.postback) {
onChange({
type: ButtonType.postback,
title: button.title,
payload: button.title,
});
} else {
onChange({ type: ButtonType.web_url, title: button.title, url: "" });
}
};
const {
register,
formState: { errors },
} = useFormContext<IBlockAttributes>();

return (
<>
<Grid item xs={2}>
<Input
select
value={button.type}
onChange={(e) => {
setButtonType(e.target.value as ButtonType);
}}
>
{types.map((item) => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Input>
</Grid>
<Grid item xs={3}>
<Grid item xs={5}>
<Input
fullWidth
required
Expand All @@ -107,7 +73,7 @@ const ButtonInput: FC<ButtonInputProps> = ({
}
/>
</Grid>
<Grid item xs={4}>
<Grid item xs={6}>
{button.type === ButtonType.postback ? (
<ToggleableInput
defaultValue={button.payload}
Expand Down Expand Up @@ -163,29 +129,6 @@ const ButtonInput: FC<ButtonInputProps> = ({
/>
)}
</Grid>
<Grid item xs={2}>
{button.type === ButtonType.postback ? null : (
<Input
select
value={button.webview_height_ratio || "none"}
onChange={(e) => {
const value = e.target.value;

onChange({
...button,
messenger_extensions: e.target.value !== "none",
webview_height_ratio:
value !== "none" ? (value as WebviewHeightRatio) : undefined,
});
}}
>
<MenuItem value="none">{t("label.none")}</MenuItem>
<MenuItem value="compact">{t("label.compact")}</MenuItem>
<MenuItem value="tall">{t("label.tall")}</MenuItem>
<MenuItem value="full">{t("label.full")}</MenuItem>
</Input>
)}
</Grid>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { KeyboardReturn, Link, RemoveCircleOutline } from "@mui/icons-material";
import AddIcon from "@mui/icons-material/Add";
import DeleteIcon from "@mui/icons-material/Delete";
import { Box, Button, Grid, IconButton } from "@mui/material";
import { FC, Fragment, useEffect, useState } from "react";
import { Box, Grid, IconButton } from "@mui/material";
import { FC, Fragment, useEffect, useMemo, useState } from "react";
import { FieldPath } from "react-hook-form";

import DropdownButton, {
DropdownButtonAction,
} from "@/app-components/buttons/DropdownButton";
import { useTranslate } from "@/hooks/useTranslate";
import { IBlockAttributes } from "@/types/block.types";
import { AnyButton, ButtonType } from "@/types/message.types";
Expand Down Expand Up @@ -40,11 +43,31 @@ const ButtonsInput: FC<ButtonsInput> = ({
const [buttons, setButtons] = useState<ValueWithId<AnyButton>[]>(
value.map((button) => createValueWithId(button)),
);
const addInput = () => {
setButtons([
...buttons,
createValueWithId({ type: ButtonType.postback, title: "", payload: "" }),
]);
const actions: DropdownButtonAction[] = useMemo(
() => [
{
icon: <KeyboardReturn />,
name: t("button.postback"),
defaultValue: {
type: ButtonType.postback,
title: "",
payload: "",
},
},
{
icon: <Link />,
name: t("button.url"),
defaultValue: {
type: ButtonType.web_url,
title: "",
url: "",
},
},
],
[t],
);
const addInput = (defaultValue: AnyButton) => {
setButtons([...buttons, createValueWithId(defaultValue)]);
};
const removeInput = (index: number) => {
const updatedButtons = [...buttons];
Expand Down Expand Up @@ -75,51 +98,44 @@ const ButtonsInput: FC<ButtonsInput> = ({
return (
<Box>
<Grid container spacing={2}>
<Grid item xs={1}>
&nbsp;
</Grid>
<Grid item xs={2}>
{t("label.type")}
</Grid>
<Grid item xs={3}>
<Grid item xs={5}>
{t("label.title")}
</Grid>
<Grid item xs={4}>
<Grid item xs={6}>
{t("label.payload")} / {t("label.url")}
</Grid>
<Grid item xs={2}>
{t("label.webview")}
<Grid item xs={1}>
&nbsp;
</Grid>
{buttons.map(({ value, id }, idx) => (
<Fragment key={id}>
<Grid item xs={1}>
<IconButton
onClick={() => removeInput(idx)}
disabled={buttons.length <= minInput}
>
<DeleteIcon />
</IconButton>
</Grid>
<ButtonInput
fieldPath={fieldPath}
idx={idx}
button={value}
onChange={updateInput(idx)}
disablePayload={disablePayload}
/>
<Grid item xs={1}>
<IconButton
color="error"
onClick={() => removeInput(idx)}
disabled={buttons.length <= minInput}
>
<RemoveCircleOutline />
</IconButton>
</Grid>
</Fragment>
))}
</Grid>
<Button
variant="contained"
color="primary"
onClick={addInput}
startIcon={<AddIcon />}
sx={{ m: 1, float: "right" }}
<DropdownButton
sx={{ m: 1, float: "right", padding: "16px" }}
label={t("button.add_button")}
actions={actions}
onClick={(action) => addInput(action.defaultValue)}
icon={<AddIcon />}
disabled={buttons.length >= maxInput}
>
{t("button.add")}
</Button>
/>
</Box>
);
};
Expand Down
Loading

0 comments on commit cdb8cd1

Please sign in to comment.