Skip to content
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

modal added for delete filter and truncate added for lengthy filter name #1958

Merged
merged 3 commits into from
Mar 26, 2024
Merged
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
7 changes: 5 additions & 2 deletions forms-flow-web/src/components/Form/constants/FormTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,15 @@ function FormTable() {
</button>
</td>
<td>
<Dropdown data-testid={`designer-form-option-${e._id}`}>
<Dropdown
data-testid={`designer-form-option-${e._id}`}
data-bs-toggle="tooltip"
data-bs-placement="bottom"
title={t("More options")}>
<Dropdown.Toggle
data-testid={`designer-form-option-toggle-${e._id}`}
as={CustomToggle}
id="dropdown-basic"
title={t("More options")}
aria-describedby="More-options"
>
<i className="fa-solid fa-ellipsis"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ import TaskAttributeComponent from "./TaskAttributeComponent";
import { toast } from "react-toastify";
import { getUserRoles } from "../../../../apiManager/services/authorizationService";
import { setUserGroups } from "../../../../actions/authorizationActions";
import { Badge, ListGroup, OverlayTrigger, Popover } from "react-bootstrap";
import {
Badge,
ListGroup,
OverlayTrigger,
Popover,
Modal,
Button,
} from "react-bootstrap";
import { trimFirstSlash } from "../../constants/taskConstants";
import { cloneDeep, omitBy } from "lodash";
import {
Expand Down Expand Up @@ -112,6 +119,8 @@ export default function CreateNewFilterDrawer({
const { t } = useTranslation();
const [modalShow, setModalShow] = useState(false);
const [checkboxes, setCheckboxes] = useState(initialValueOfTaskAttribute);
const [showDeleteModal, setShowDeleteModal] = useState(false);
const [showAlert, setShowAlert] = useState(false);

const fetchTasks = (resData) => {
const reqParamData = {
Expand Down Expand Up @@ -503,6 +512,11 @@ export default function CreateNewFilterDrawer({
setOpenFilterDrawer(!openFilterDrawer);
};

const deleteConfirmationModalToggleDrawer = () => {
setOpenFilterDrawer(!openFilterDrawer);
};


const candidateGroups = useSelector(
(state) => state.user?.userDetail?.groups || []
);
Expand Down Expand Up @@ -543,6 +557,38 @@ export default function CreateNewFilterDrawer({
setShowUndefinedVariable(showUndefinedVariable);
};


const hideDeleteConfirmation = () => {
setShowDeleteModal(false);
Ajay-aot marked this conversation as resolved.
Show resolved Hide resolved
deleteConfirmationModalToggleDrawer();
};

const showDeleteConfirmation = () => {
setShowDeleteModal(true);
toggleDrawer();
};

const FilterDelete = () => {
hideDeleteConfirmation();
handleFilterDelete();
};

const textTruncate = (wordLength, targetLength, text) => {
return text?.length > wordLength
? text.substring(0, targetLength) + "..."
: text;
};

const handleFilterName = (e) => {
const value = e.target.value;
setFilterName(value);
if (value.length >= 50) {
setShowAlert(true);
} else {
setShowAlert(false);
}
};

const list = () => (
<div role="presentation">
<List>
Expand All @@ -560,13 +606,18 @@ export default function CreateNewFilterDrawer({
<label htmlFor="filterName">{t("Filter Name")}</label>
<input
type="text"
className="form-control"
className={`form-control ${showAlert ? 'is-invalid' : ''}`}
id="filterName"
placeholder={t("Enter your text here")}
value={filterName}
onChange={(e) => setFilterName(e.target.value)}
title={t("Add filter name")}
onChange={handleFilterName}
title={t("Add fliter name")}
/>
{showAlert && (
<p className="text-danger mt-2 fs-6">
{t("Filter name should be less than 50 characters")}
</p>
)}
</div>
</List>

Expand Down Expand Up @@ -835,8 +886,7 @@ export default function CreateNewFilterDrawer({
<button
className="btn btn-link text-danger cursor-pointer"
onClick={() => {
toggleDrawer();
handleFilterDelete();
showDeleteConfirmation();
}}
>
<Translation>{(t) => t("Delete Filter")}</Translation>
Expand All @@ -853,7 +903,7 @@ export default function CreateNewFilterDrawer({
</button>
<button
className="btn btn-primary submitButton text-decoration-none truncate-size "
disabled={!permissions || !filterName}
disabled={!permissions || !filterName || filterName.length >= 50}
onClick={() => {
handleSubmit();
}}
Expand Down Expand Up @@ -921,6 +971,37 @@ export default function CreateNewFilterDrawer({
{list()}
</Drawer>
</React.Fragment>

{/* Delete confirmation modal */}
<Modal show={showDeleteModal} onHide={hideDeleteConfirmation}>
<Modal.Header>
<Modal.Title>
<Translation>{(t) => t("Delete Confirmation")}</Translation>
</Modal.Title>
</Modal.Header>
<Modal.Body>
<Translation>{(t) => t("Are you sure to delete")}</Translation>
{" "}
<span className="fw-bold">
{filterName.includes(" ")
? filterName
: textTruncate(40, 30, filterName)}
</span>{" "}
<Translation>{(t) => t("filter?")}</Translation>
</Modal.Body>
<Modal.Footer>
<Button
variant=""
className="btn-link text-dark"
onClick={hideDeleteConfirmation}
>
<Translation>{(t) => t("Cancel")}</Translation>
</Button>
<Button variant="danger" onClick={FilterDelete}>
<Translation>{(t) => t("Delete")}</Translation>
</Button>
</Modal.Footer>
</Modal>
</div>
);
}
9 changes: 8 additions & 1 deletion forms-flow-web/src/containers/TaskHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ function TaskHead() {

const count = isTaskListLoading ? "" : `(${itemCount})`;

const textTruncate = (wordLength, targetLength, text) => {
return text?.length > wordLength
? text.substring(0, targetLength) + "..."
: text;
};

return (
<div>
<div className="d-flex flex-md-row flex-column align-items-md-center justify-content-between">
Expand All @@ -55,7 +61,8 @@ function TaskHead() {
<span className="h4 fw-bold">
<i className="fa fa-list-ul me-2" />
{selectedFilter?.name ?
`${selectedFilter?.name} ${count}` : filterListLoading() }
textTruncate(25, 23, `${selectedFilter?.name} ${count}`) :
filterListLoading() }
</span>
}
onClick={goToTask}
Expand Down
Loading