Skip to content

Commit

Permalink
chore: folder restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
okorie2 committed Sep 13, 2024
1 parent c9372f8 commit 13319c7
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 149 deletions.
10 changes: 2 additions & 8 deletions src/app/modules/report-module/__test__/headerBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
act,
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import HeaderBlock from "app/modules/report-module/sub-module/components/headerBlock/";
import HeaderBlock from "app/modules/report-module/components/headerBlock";
import { ContentState, EditorState } from "draft-js";
import { ToolbarPluginsType } from "app/modules/report-module/components/reportSubHeaderToolbar/staticToolbar";
import Router from "react-router-dom";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { reportRightPanelViewAtom } from "app/state/recoil/atoms";
import { RichEditor } from "app/modules/common/RichEditor";
import { ReactComponent as EditIcon } from "app/modules/report-module/asset/editIcon.svg";
import { ReactComponent as DeleteIcon } from "app/modules/report-module/asset/deleteIcon.svg";
import { headerBlockcss } from "app/modules/report-module/sub-module/components/headerBlock/style";
import { headerBlockcss } from "app/modules/report-module/components/headerBlock/style";
import { ReactComponent as HeaderHandlesvg } from "app/modules/report-module/asset/header-handle.svg";
import { Tooltip } from "@material-ui/core";
import useDebounce from "react-use/lib/useDebounce";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useUpdateEffect } from "react-use";
import IconButton from "@material-ui/core/IconButton";
import { useHistory, useLocation, useParams } from "react-router-dom";
import { itemSpacing, containerGap } from "app/modules/report-module/data";
import RowstructureDisplay from "app/modules/report-module/sub-module/rowStructure/rowStructureDisplay";
import RowstructureDisplay from "app/modules/report-module/components/rowStructure/rowStructureDisplay";
import { ReactComponent as CloseIcon } from "app/modules/report-module/asset/closeIcon.svg";
import { ReactComponent as DeleteIcon } from "app/modules/report-module/asset/deleteIcon.svg";
import {
Expand All @@ -15,7 +15,7 @@ import {
import {
blockcss,
containercss,
} from "app/modules/report-module/sub-module/rowStructure/style";
} from "app/modules/report-module/components/rowStructure/style";
import { IFramesArray } from "app/modules/report-module/views/create/data";
import { useOnClickOutside } from "usehooks-ts";
import { ToolbarPluginsType } from "app/modules/report-module/components/reportSubHeaderToolbar/staticToolbar";
Expand Down
141 changes: 6 additions & 135 deletions src/app/modules/report-module/views/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import React from "react";
import { v4 } from "uuid";
import { useDrop } from "react-dnd";
import Box from "@material-ui/core/Box";
import Container from "@material-ui/core/Container";
import useResizeObserver from "use-resize-observer";
import { useRecoilState, useRecoilValue } from "recoil";
import { useRecoilState } from "recoil";
import { GridColumns } from "app/modules/report-module/components/grid-columns";
import HeaderBlock from "app/modules/report-module/sub-module/components/headerBlock";
import HeaderBlock from "app/modules/report-module/components/headerBlock";
import { ItemComponent } from "app/modules/report-module/components/order-container";
import { ReportElementsType } from "app/modules/report-module/components/right-panel-create-view";
import AddRowFrameButton from "app/modules/report-module/sub-module/rowStructure/addRowFrameButton";
import RowFrame from "app/modules/report-module/sub-module/rowStructure";
import {
ReportCreateViewProps,
PlaceholderProps,
} from "app/modules/report-module/views/create/data";
import AddRowFrameButton from "app/modules/report-module/components/rowStructure/addRowFrameButton";
import RowFrame from "app/modules/report-module/components/rowStructure";
import { ReportCreateViewProps } from "app/modules/report-module/views/create/data";
import {
IRowFrameStructure,
reportContentContainerWidth,
isDividerOrRowFrameDraggingAtom,
} from "app/state/recoil/atoms";
import TourGuide from "app/components/Dialogs/TourGuide";
import { useTitle } from "react-use";
import PlaceHolder from "app/modules/report-module/components/placeholder";

function ReportCreateView(props: Readonly<ReportCreateViewProps>) {
useTitle("DX Dataxplorer - Create Report");
Expand Down Expand Up @@ -197,127 +192,3 @@ function ReportCreateView(props: Readonly<ReportCreateViewProps>) {
}

export default ReportCreateView;

export const PlaceHolder = (props: PlaceholderProps) => {
const moveCard = React.useCallback((itemId: string) => {
props.updateFramesArray((draft) => {
const dragIndex = draft.findIndex((frame) => frame.id === itemId);

const dropIndex =
props.index ?? draft.findIndex((frame) => frame.id === props.rowId) + 1;

const fakeId = v4();
const tempItem = draft[dragIndex];
draft[dragIndex].id = fakeId;

draft.splice(dropIndex, 0, tempItem);
const fakeIndex = draft.findIndex((frame) => frame.id === fakeId);
draft.splice(fakeIndex, 1);
});
}, []);
const [{ isOver, handlerId, item: dragItem }, drop] = useDrop(() => ({
// The type (or types) to accept - strings or symbols
accept: [
ReportElementsType.DIVIDER,
ReportElementsType.ROWFRAME,
ReportElementsType.ROW,
],
// Props to collect
collect: (monitor) => ({
isOver: monitor.isOver(),
canDrop: monitor.canDrop(),
item: monitor.getItem(),
handlerId: monitor.getHandlerId(),
}),
drop: (item: any, monitor) => {
if (item.type === ReportElementsType.ROW) {
moveCard(item.id);
} else {
props.updateFramesArray((draft) => {
const tempIndex =
props.index ??
draft.findIndex((frame) => frame.id === props.rowId) + 1;

const id = v4();
draft.splice(tempIndex, 0, {
id,
frame: {
rowId: id,
rowIndex: tempIndex,

type: item.type,
},
content:
item.type === ReportElementsType.ROWFRAME ? [] : ["divider"],
contentWidths: [],
contentHeights: [],
contentTypes:
item.type === ReportElementsType.ROWFRAME ? [] : ["divider"],
structure: null,
});
});
}
},
}));

const isItemDragging = useRecoilValue(isDividerOrRowFrameDraggingAtom);

const itemDragIndex = props.framesArray.findIndex(
(frame) => frame.id === isItemDragging.rowId
);

const placeholderIndex =
props.index ??
props.framesArray.findIndex((frame) => frame.id === props.rowId) + 1;

const dragIndex = props.framesArray.findIndex(
(frame) => frame.id === (dragItem as any)?.id
);

const placeholderActive = () => {
if (isOver) {
if (dragIndex === -1) {
return true;
}
if (placeholderIndex === dragIndex) {
return false;
}
if (placeholderIndex - 1 === dragIndex) {
return false;
}
return true;
}
return false;
};

const isDroppable = () => {
if (isItemDragging.state) {
if (itemDragIndex === -1) {
return true;
}
if (placeholderIndex === itemDragIndex) {
return false;
}
if (placeholderIndex - 1 === itemDragIndex) {
return false;
}
return true;
}
return false;
};

return (
<div
data-cy="report-row-placeholder"
data-handler-id={handlerId}
ref={drop}
css={`
width: 100%;
height: 4px;
display: ${isItemDragging.state ? "block" : "none"};
background-color: ${placeholderActive() ? "#6061E5" : "#262c34"};
opacity: ${isDroppable() ? 1 : 0.5};
`}
/>
);
};
1 change: 0 additions & 1 deletion src/app/modules/report-module/views/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ function ReportEditView(props: Readonly<ReportEditViewProps>) {
height: 20px;
`}
/>
{/* <Box height={8} /> */}

<PlaceHolder
rowId={frame.id}
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/report-module/views/preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Container from "@material-ui/core/Container";
import { EditorState, convertFromRaw } from "draft-js";
import { useStoreActions, useStoreState } from "app/state/store/hooks";
import { ReportModel, emptyReport } from "app/modules/report-module/data";
import RowFrame from "app/modules/report-module/sub-module/rowStructure";
import HeaderBlock from "app/modules/report-module/sub-module/components/headerBlock";
import RowFrame from "app/modules/report-module/components/rowStructure";
import HeaderBlock from "app/modules/report-module/components/headerBlock";
import { NotAuthorizedMessageModule } from "app/modules/common/not-authorized-message";
import { ReportElementsType } from "app/modules/report-module/components/right-panel-create-view";
import {
Expand Down

0 comments on commit 13319c7

Please sign in to comment.