Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hlomzik committed Dec 13, 2024
1 parent fb65a2a commit a166400
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { Tooltip } from "../../Common/Tooltip/Tooltip";
import styles from "./GridPreview.module.scss";

type Task = {
id: number,
data: Record<string, string>,
id: number;
data: Record<string, string>;
};

type GridViewContextType = {
tasks: Task[],
imageField: string | undefined,
currentTaskId: number | null,
setCurrentTaskId: (id: number | null) => void,
tasks: Task[];
imageField: string | undefined;
currentTaskId: number | null;
setCurrentTaskId: (id: number | null) => void;
};

type TaskModalProps = GridViewContextType & { view: any };
Expand All @@ -30,9 +30,9 @@ export const GridViewContext = createContext<GridViewContextType>({
});

const TaskModal = observer(({ view, tasks, imageField, currentTaskId, setCurrentTaskId }: TaskModalProps) => {
const index = tasks.findIndex(task => task.id === currentTaskId);
const index = tasks.findIndex((task) => task.id === currentTaskId);
const task = tasks[index];
const src = imageField ? (task?.data?.[imageField] || "") : "";
const src = imageField ? task?.data?.[imageField] || "" : "";

const goToNext = useCallback(() => {
if (index < tasks.length - 1) {
Expand Down Expand Up @@ -129,13 +129,13 @@ const TaskModal = observer(({ view, tasks, imageField, currentTaskId, setCurrent
type GridViewProviderProps = PropsWithChildren<{
data: Task[];
view: any;
fields: { alias: string, currentType: string }[];
fields: { alias: string; currentType: string }[];
}>;

export const GridViewProvider: React.FC<GridViewProviderProps> = ({ children, data, view, fields }) => {
const [currentTaskId, setCurrentTaskId] = useState<number | null>(null);
const modalRef = useRef<{ update: (props: object) => void, close: () => void } | null>(null);
const imageField = fields.find(f => f.currentType === "Image")?.alias;
const modalRef = useRef<{ update: (props: object) => void; close: () => void } | null>(null);
const imageField = fields.find((f) => f.currentType === "Image")?.alias;

const onClose = useCallback(() => {
modalRef.current = null;
Expand All @@ -150,7 +150,15 @@ export const GridViewProvider: React.FC<GridViewProviderProps> = ({ children, da

if (!imageField) return;

const children = <TaskModal view={view} tasks={data} imageField={imageField} currentTaskId={currentTaskId} setCurrentTaskId={setCurrentTaskId} />;
const children = (
<TaskModal
view={view}
tasks={data}
imageField={imageField}
currentTaskId={currentTaskId}
setCurrentTaskId={setCurrentTaskId}
/>
);

if (!modalRef.current) {
modalRef.current = modal({
Expand Down
17 changes: 10 additions & 7 deletions web/libs/datamanager/src/components/MainView/GridView/GridView.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { observer } from "mobx-react";
import { useCallback, useContext, useMemo, useState } from "react";
import { useCallback, useContext, useMemo } from "react";
import AutoSizer from "react-virtualized-auto-sizer";
import { FixedSizeGrid } from "react-window";
import InfiniteLoader from "react-window-infinite-loader";
Expand Down Expand Up @@ -59,12 +59,15 @@ const GridDataGroup = observer(({ type, value, field, row }) => {
const GridCell = observer(({ view, selected, row, fields, onClick, ...props }) => {
const { setCurrentTaskId, imageField } = useContext(GridViewContext);

const handleBodyClick = useCallback((e) => {
if (!isFF(FF_GRID_PREVIEW) || !imageField) return;
// @todo skip this interaction if there are no images in the task
e.stopPropagation();
setCurrentTaskId(row.id);
}, [imageField, row.id]);
const handleBodyClick = useCallback(
(e) => {
if (!isFF(FF_GRID_PREVIEW) || !imageField) return;
// @todo skip this interaction if there are no images in the task
e.stopPropagation();
setCurrentTaskId(row.id);
},
[imageField, row.id],
);

return (
<Elem {...props} name="cell" onClick={onClick} mod={{ selected: selected.isSelected(row.id) }}>
Expand Down

0 comments on commit a166400

Please sign in to comment.