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

fix(Dataspreadsheet): Duplication selection issue #4241 #4333

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const DataSpreadsheetBody = forwardRef(
) => {
const [validStartingPoint, setValidStartingPoint] = useState(false);
const contentScrollRef = useRef();

const previousState = usePreviousValue({
selectionAreaData,
clickAndHoldActive,
Expand Down Expand Up @@ -263,6 +264,27 @@ export const DataSpreadsheetBody = forwardRef(
setSelectionAreas,
visibleColumns,
]);
//selectionAreas will be set when ever a selection area is made.
useEffect(() => {
removeDuplicateSelections();
}, [selectionAreas,removeDuplicateSelections]);

//this method will check for any dupplicate selection area and remove.
//same selections are those have the same height, width, top, left styles. These inline styles are being set in createCellSelection util.
const removeDuplicateSelections = useCallback(() => {
amal-k-joy marked this conversation as resolved.
Show resolved Hide resolved
let uniqueAttrArray = [];
ref.current
.querySelectorAll(`.${blockClass}__selection-area--element`)
.forEach((selectorEl) => {
let { top, left, height, width } = selectorEl.style;
let uniqueAttrstr = `${top}${left}${height}${width}`; // eg: 20px30px70px90px
if (uniqueAttrArray.indexOf(uniqueAttrstr) == -1) {
uniqueAttrArray.push(uniqueAttrstr);
} else {
selectorEl.remove(); // this is identified as duplicate selwction and hence removing.
}
});
}, [ref]);

// onClick fn for each cell in the data spreadsheet body,
// adds the active cell highlight
Expand Down Expand Up @@ -376,6 +398,7 @@ export const DataSpreadsheetBody = forwardRef(
row: cell.row.index,
column: columnIndex,
};

setSelectionAreas((prev) => {
const selectionAreaClone = deepCloneObject(prev);
const indexOfItemToUpdate = selectionAreaClone.findIndex(
Expand Down
Loading