Skip to content

Commit

Permalink
fix: pull develop, fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Psami-wondah committed Oct 1, 2024
2 parents 4d892bb + 6e45abc commit 0aa24c8
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ test("clicking duplicate button should duplicate chart", async () => {
const mockedAxios = axios.get as jest.Mock;
mockedAxios
.mockResolvedValueOnce({
data: { id: "chart-id" },
data: { data: { id: "chart-id" } },
} as AxiosResponse<any>)
.mockResolvedValueOnce({ data: mockChartList });
jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export function ChartSubheaderToolbar(
storeInCrudData: true,
filterString: "filter[order]=updatedDate desc",
});
setDuplicatedChartId(response.data.id);
setDuplicatedChartId(response.data?.data?.id);
setSnackbarState({
...snackbarState,
open: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default function DatasetSubHeaderToolbar(
onTryAgain: () => {},
});
}
setDuplicatedDatasetId(response.data.id);
setDuplicatedDatasetId(response.data?.data?.id);
setSnackbarState({
...snackbarState,
open: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ describe("Tests for tablet and desktop view", () => {
const axiosMock = axios.get as jest.Mock;

axiosMock
.mockResolvedValueOnce({ data: { id: "12345" } } as AxiosResponse<any>)
.mockResolvedValueOnce({ data: [] });
.mockResolvedValueOnce({
data: { data: { id: "12345" } },
} as AxiosResponse<any>)
.mockResolvedValueOnce({ data: { data: [] } });
jest
.spyOn(Router, "useParams")
.mockReturnValue({ page: "12345", view: undefined });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export function ReportSubheaderToolbar(
storeInCrudData: true,
filterString: "filter[order]=updatedDate desc",
});
setDuplicatedReportId(response.data.id);
setDuplicatedReportId(response.data?.data?.id);
setSnackbarState({
...snackbarState,
open: true,
Expand Down
50 changes: 0 additions & 50 deletions src/app/modules/report-module/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import AITemplate from "app/modules/report-module/views/ai-template";
import { EditorState, convertToRaw } from "draft-js";
import { useStoreActions, useStoreState } from "app/state/store/hooks";
import { ReportModel, emptyReport } from "app/modules/report-module/data";
import ReportCreateView from "app/modules/report-module/views/create";
import { ReportPreviewView } from "app/modules/report-module/views/preview";
import ReportInitialView from "app/modules/report-module/views/initial";
import { IFramesArray } from "app/modules/report-module/views/create/data";
Expand All @@ -26,10 +25,8 @@ import {
Redirect,
} from "react-router-dom";
import {
persistedReportStateAtom,
planDialogAtom,
reportRightPanelViewAtom,
unSavedReportPreviewModeAtom,
} from "app/state/recoil/atoms";
import { ReportSubheaderToolbar } from "app/modules/report-module/components/reportSubHeaderToolbar";
import { ToolbarPluginsType } from "app/modules/report-module/components/reportSubHeaderToolbar/staticToolbar";
Expand All @@ -48,37 +45,12 @@ export default function ReportModule() {
}>({ isAutoSaveEnabled: false });

const setPlanDialog = useSetRecoilState(planDialogAtom);

/** static toolbar states */
const [plugins, setPlugins] = React.useState<ToolbarPluginsType>([]);
/** end of static toolbar states */

const token = useStoreState((state) => state.AuthToken.value);

const [_rightPanelView, setRightPanelView] = useRecoilState(
reportRightPanelViewAtom
);

const [_reportPreviewMode, setReportPreviewMode] = useRecoilState(
unSavedReportPreviewModeAtom
);

const [persistedReportState, setPersistedReportState] = useRecoilState(
persistedReportStateAtom
);
const [isPreviewView, setIsPreviewView] = React.useState(false);

const localReportState = JSON.parse(persistedReportState.framesArray);

let localPickedCharts: string[] = [];
localReportState.map((data: any) => {
return data.contentTypes.map((item: any, index: number) => {
if (item === "chart") {
localPickedCharts.push(data.content[index]);
}
});
});

const [rightPanelOpen, setRightPanelOpen] = React.useState(true);
const [reportName, setReportName] = React.useState("Untitled report");
const [hasReportNameFocused, setHasReportNameFocused] = React.useState(false);
Expand Down Expand Up @@ -300,26 +272,6 @@ export default function ReportModule() {

const resetReport = () => {
updateFramesArray(initialFramesArray);
setPersistedReportState({
reportName: "Untitled report",
headerDetails: {
title: "",
heading: JSON.stringify(
convertToRaw(EditorState.createEmpty().getCurrentContent())
),
description: JSON.stringify(
convertToRaw(EditorState.createEmpty().getCurrentContent())
),
showHeader: true,
backgroundColor: "#252c34",
titleColor: "#ffffff",
descriptionColor: "#ffffff",
dateColor: "#ffffff",
},

framesArray: JSON.stringify([]),
});

setHeaderDetails({
title: "",
heading: EditorState.createEmpty(),
Expand All @@ -333,7 +285,6 @@ export default function ReportModule() {
setReportName("Untitled report");
setRightPanelView("charts");
setRightPanelOpen(true);
setReportPreviewMode(false);
setAutoSave({ isAutoSaveEnabled: false });
};

Expand Down Expand Up @@ -500,7 +451,6 @@ export default function ReportModule() {
setHasChangesBeenMade={setHasChangesBeenMade}
setReportName={setReportName}
reportName={reportName}
localPickedCharts={localPickedCharts}
framesArray={framesArray}
headerDetails={headerDetails}
updateFramesArray={updateFramesArray}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
chartFromReportAtom,
reportContentIsResizingAtom,
reportContentContainerWidth,
unSavedReportPreviewModeAtom,
isChartDraggingAtom,
} from "app/state/recoil/atoms";
import { IFramesArray } from "../../views/create/data";
Expand Down Expand Up @@ -62,17 +61,14 @@ interface RowStructureDisplayProps {
forceSelectedType: string | undefined;
}

export default function RowstructureDisplay(props: RowStructureDisplayProps) {
export default function RowstructureDisplay(
props: Readonly<RowStructureDisplayProps>
) {
const ref = useRef(null);
const location = useLocation();
const { page } = useParams<{ page: string }>();
const [handleDisplay, setHandleDisplay] = React.useState(false);
const [reportPreviewMode] = useRecoilState(unSavedReportPreviewModeAtom);
const smScreen = useMediaQuery("(max-width: 850px)");
const viewOnlyMode =
(page !== "new" &&
get(location.pathname.split("/"), "[3]", "") !== "edit") ||
reportPreviewMode;
const viewOnlyMode = location.pathname === `/report/${page}`;

const handlers = viewOnlyMode
? {}
Expand Down Expand Up @@ -381,15 +377,10 @@ const Box = (props: {
};

const containerWidth = useRecoilValue(reportContentContainerWidth);
const [reportPreviewMode] = useRecoilState(unSavedReportPreviewModeAtom);
const [_isResizing, setIsResizing] = useRecoilState(
reportContentIsResizingAtom
);

const viewOnlyMode =
(page !== "new" &&
get(location.pathname.split("/"), "[3]", "") !== "edit") ||
reportPreviewMode;
const viewOnlyMode = location.pathname === `/report/${page}`;

const elementTypes = [
ReportElementsType.TEXT,
Expand Down
1 change: 0 additions & 1 deletion src/app/modules/report-module/views/edit/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface ReportEditViewProps {
setHasReportNameFocused: React.Dispatch<React.SetStateAction<boolean>>;
updateFramesArray: Updater<IFramesArray[]>;
framesArray: IFramesArray[];
localPickedCharts: string[];
setReportName: React.Dispatch<React.SetStateAction<string>>;
autoSave: boolean;
setAutoSave: React.Dispatch<
Expand Down
30 changes: 11 additions & 19 deletions src/app/modules/report-module/views/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRecoilState } from "recoil";
import { useParams } from "react-router-dom";
import useResizeObserver from "use-resize-observer";
import Container from "@material-ui/core/Container";
import { EditorState, RawDraftContentState, convertFromRaw } from "draft-js";
import { EditorState, convertFromRaw } from "draft-js";
import { useTitle } from "react-use";
import { useAuth0 } from "@auth0/auth0-react";
import { PlaceHolder } from "app/modules/report-module/views/create";
Expand All @@ -21,7 +21,6 @@ import { GridColumns } from "app/modules/report-module/components/grid-columns";

import {
IRowFrameStructure,
persistedReportStateAtom,
reportContentContainerWidth,
} from "app/state/recoil/atoms";
import { IFramesArray } from "app/modules/report-module/views/create/data";
Expand All @@ -37,7 +36,7 @@ import {
compareHeaderDetailsState,
} from "app/modules/report-module/views/edit/compareStates";

function ReportEditView(props: ReportEditViewProps) {
function ReportEditView(props: Readonly<ReportEditViewProps>) {
useTitle("DX Dataxplorer - Edit Report");

const { page } = useParams<{ page: string }>();
Expand All @@ -53,7 +52,6 @@ function ReportEditView(props: ReportEditViewProps) {
);
const [isReportHeadingModified, setIsReportHeadingModified] =
React.useState(false);
const [persistedReportState] = useRecoilState(persistedReportStateAtom);
const [rowStructureType, setRowStructuretype] =
React.useState<IRowFrameStructure>({
index: 0,
Expand Down Expand Up @@ -112,15 +110,13 @@ function ReportEditView(props: ReportEditViewProps) {
if (reportData.id !== page) {
return;
}
if (props.localPickedCharts.length === 0) {
const items = reportData.rows.map((rowFrame, index) =>
rowFrame.items.filter((item) => typeof item === "string")
) as string[][];
let pickedItems: string[] = [];

for (const element of items) {
pickedItems = [...pickedItems, ...element];
}
const items = reportData.rows.map((rowFrame, index) =>
rowFrame.items.filter((item) => typeof item === "string")
) as string[][];
let pickedItems: string[] = [];

for (const element of items) {
pickedItems = [...pickedItems, ...element];
}
}, [reportData]);

Expand Down Expand Up @@ -197,15 +193,11 @@ function ReportEditView(props: ReportEditViewProps) {
showHeader: reportData.showHeader,
heading: reportData?.heading
? EditorState.moveFocusToEnd(
EditorState.createWithContent(
convertFromRaw(reportData?.heading as RawDraftContentState)
)
EditorState.createWithContent(convertFromRaw(reportData?.heading))
)
: EditorState.moveFocusToEnd(EditorState.createEmpty()),
description: reportData?.description
? EditorState.createWithContent(
convertFromRaw(reportData?.description as RawDraftContentState)
)
? EditorState.createWithContent(convertFromRaw(reportData?.description))
: EditorState.createEmpty(),
backgroundColor: reportData.backgroundColor,
titleColor: reportData.titleColor,
Expand Down
10 changes: 1 addition & 9 deletions src/app/modules/report-module/views/initial/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
} from "app/modules/report-module/views/initial/data";
import { ReportModel, emptyReport } from "app/modules/report-module/data";
import ReportsGrid from "app/modules/home-module/components/AssetCollection/Reports/reportsGrid";
import { persistedReportStateAtom } from "app/state/recoil/atoms";
import { useResetRecoilState } from "recoil";
import { useHistory } from "react-router-dom";
import { useStoreActions, useStoreState } from "app/state/store/hooks";
import { useMount, useTitle, useUpdateEffect } from "react-use";
Expand Down Expand Up @@ -50,12 +48,7 @@ function ReportInitialView(props: Readonly<ReportInitialViewProps>) {
props.handleSetButtonActive(option.value);
};

const clearPersistedReportState = useResetRecoilState(
persistedReportStateAtom
);

React.useEffect(() => {
clearPersistedReportState();
props.resetReport();
}, []);

Expand All @@ -66,8 +59,7 @@ function ReportInitialView(props: Readonly<ReportInitialViewProps>) {

useUpdateEffect(() => {
if (reportCreateSuccess && !isEmpty(reportCreateData?.id)) {
const id = reportCreateData.id;
history.push(`/report/${id}/edit`);
history.push(`/report/${reportCreateData.id}/edit`);
}
}, [reportCreateSuccess, reportCreateData]);

Expand Down
Loading

0 comments on commit 0aa24c8

Please sign in to comment.