Skip to content

Commit

Permalink
refactor(ui): remove unused fillPatternRef
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia committed Sep 10, 2024
1 parent 7e8e8be commit 85db05f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
20 changes: 2 additions & 18 deletions webapp/src/components/common/MatrixGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DataEditor, {
Item,
} from "@glideapps/glide-data-grid";
import { useGridCellContent } from "./useGridCellContent";
import { useMemo, useRef, useState } from "react";
import { useMemo, useState } from "react";
import { type CellFillPattern, type EnhancedGridColumn } from "./types";
import { darkTheme, readOnlyDarkTheme } from "./utils";
import { useColumnMapping } from "./useColumnMapping";
Expand Down Expand Up @@ -47,8 +47,6 @@ function MatrixGrid({
rows: CompactSelection.empty(),
});

const fillPatternRef = useRef<CellFillPattern | null>(null);

const { gridToData } = useColumnMapping(columns);

const theme = useMemo(() => {
Expand Down Expand Up @@ -119,27 +117,14 @@ function MatrixGrid({
}

if (onMultipleCellsEdit) {
onMultipleCellsEdit(updates, fillPatternRef.current || undefined);
onMultipleCellsEdit(updates);
}

// Reset fillPatternRef after use
fillPatternRef.current = null;

// Return true to prevent calling `onCellEdit`
// for each cell after`onMultipleCellsEdit` is called
return true;
};

// Used for fill handle updates to send one batch update object
// instead of an array of updates using `onCellsEdited` callback
const handleFillPattern = ({
patternSource,
fillDestination,
}: CellFillPattern) => {
fillPatternRef.current = { patternSource, fillDestination };
// Don't prevent default, allow the grid to apply the fill pattern
};

////////////////////////////////////////////////////////////////
// JSX
////////////////////////////////////////////////////////////////
Expand All @@ -160,7 +145,6 @@ function MatrixGrid({
getCellsForSelection // Enable copy support
onPaste
fillHandle
onFillPattern={handleFillPattern}
rowMarkers="both"
/>
<div id="portal" />
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/common/MatrixGrid/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const ColumnDataType = {
////////////////////////////////////////////////////////////////

export const darkTheme: Theme = {
accentColor: "#6366F1",
accentColor: "rgba(255, 184, 0, 0.9)",
accentLight: "rgba(255, 184, 0, 0.2)",
accentFg: "#FFFFFF",
accentLight: "rgba(99, 102, 241, 0.2)",
textDark: "#FFFFFF",
textMedium: "#C1C3D9",
textLight: "#A1A5B9",
Expand Down

0 comments on commit 85db05f

Please sign in to comment.