Skip to content

Commit d950fdf

Browse files
authored
Merge pull request #537 from fahad-aot/bugfix/fwf-sort-modal-fixes
bugfix/fwf-4453:sortmodal and drag and drop fixes
2 parents dc9c8ef + d38eda7 commit d950fdf

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

forms-flow-components/src/components/CustomComponents/DragandDropSort.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from "react";
1+
import React, { useState, useEffect ,useRef} from "react";
22
import { FormVariableIcon, DraggableIcon } from "../SvgIcons/index";
33
import { StyleServices } from "@formsflow/service";
44

@@ -18,7 +18,7 @@ interface DragAndDropFilterProps {
1818
export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpdate }) => {
1919

2020
const darkColor = StyleServices.getCSSVariable('--ff-gray-darkest');
21-
21+
const containerRef = useRef<HTMLDivElement | null>(null);
2222
const [filterItems, setFilterItems] = useState<FilterItem[]>(items);
2323
const [draggingIndex, setDraggingIndex] = useState<number | null>(null);
2424

@@ -34,6 +34,20 @@ export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpd
3434

3535
const onDragOver = (e: React.DragEvent<HTMLLIElement>) => {
3636
e.preventDefault();
37+
const container = containerRef.current;
38+
if (!container) return;
39+
40+
const bounding = container.getBoundingClientRect();
41+
const offset = 40;
42+
const scrollSpeed = 5; //scroll speed can be adjusted here
43+
44+
if (e.clientY < bounding.top + offset) {
45+
// scroll up
46+
container.scrollTop -= scrollSpeed;
47+
} else if (e.clientY > bounding.bottom - offset) {
48+
// scroll down
49+
container.scrollTop += scrollSpeed;
50+
}
3751
};
3852

3953

@@ -72,7 +86,7 @@ export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpd
7286
};
7387

7488
return (
75-
<div className="drag-drop-container">
89+
<div className="drag-drop-container" ref={containerRef}>
7690
<ul>
7791
{filterItems.map((item, index) => (
7892
<li

forms-flow-components/src/components/CustomComponents/SortModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export const SortModal: React.FC<SortModalProps> = React.memo(
6464
}
6565
}, [showSortModal, defaultSortOption, defaultSortOrder]);
6666

67+
const isPrimaryButtonDisabled =
68+
!selectedOption ||
69+
!selectedOrder ||
70+
(selectedOption === defaultSortOption &&
71+
selectedOrder === defaultSortOrder);
6772
return (
6873
<Modal show={showSortModal} onHide={onClose} size="sm" centered={true}>
6974
<Modal.Header>
@@ -119,7 +124,7 @@ export const SortModal: React.FC<SortModalProps> = React.memo(
119124
<CustomButton
120125
variant="primary"
121126
size="md"
122-
disabled={!selectedOption || !selectedOrder}
127+
disabled={isPrimaryButtonDisabled}
123128
label={t(primaryBtnLabel)}
124129
onClick={handlePrimaryAction}
125130
name="applyButton"

forms-flow-service/src/helpers/helperServices.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ class HelperServices {
8484
exactRouteMatches.some((route) => location == route) ||
8585
partOfRouteMatches.some((route) => location.includes(route))
8686
);
87+
}
88+
89+
public static getResetSortOrders(options){
90+
return options.reduce((acc, option) => {
91+
acc[option.value] = {sortOrder:"asc"} // Reset all to ascending
92+
return acc;
93+
}, {});
8794
}
8895
}
8996

forms-flow-theme/scss/_modal.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ $black-color: var(--ff-black);
10051005
align-items: center;
10061006
gap: var(--spacer-100);
10071007
border-radius: var(--radius-sm);
1008-
padding-top: var(--spacer-150);
1008+
padding: var(--spacer-075) 0px;
10091009
transition:
10101010
transform 1s cubic-bezier(0.25, 1, 0.5, 1),
10111011
background-color 1s ease-in-out,
@@ -1034,9 +1034,10 @@ $black-color: var(--ff-black);
10341034

10351035
&.dragging {
10361036
background-color: $gray-medium;
1037+
padding-right: 3px;
10371038
opacity: 1;
10381039
z-index: 1000;
1039-
transform: scale(1.03);
1040+
transform: scale(0.98);
10401041
}
10411042
.checkbox-container{
10421043
display: flex;

0 commit comments

Comments
 (0)