Skip to content

Commit

Permalink
fix: DX-745; DX-743; bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
okorie2 committed Oct 30, 2023
1 parent 66d023f commit 66939c3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function FinishedFragment(props: Props) {
justify-content: flex-end;
`}
>
<Link to="/chart/new/data">
<Link to={`/chart/new/preview-data`}>
<button
css={`
color: #fff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,6 @@ export function ChartToolBoxSelectDataset(
history.push(`/chart/${page}/preview-data`);
});
};

React.useEffect(() => {
if (dataset) {
history.push(`/chart/${page}/preview-data`);
}
}, []);

return (
<div
css={`
Expand Down
26 changes: 15 additions & 11 deletions src/app/modules/chart-module/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ export default function ChartModule() {
{}
);
const [rawViz, setRawViz] = React.useState<any>(null);
const [chartName, setChartName] = React.useState("Untitled Report");
const [chartName, setChartName] = React.useState("Untitled Chart");
const [isPreviewView, setIsPreviewView] = React.useState(false);
const [hasSubHeaderTitleFocused, setHasSubHeaderTitleFocused] =
React.useState(false);

const chartType = useStoreState((state) => state.charts.chartType.value);
const mapping = useStoreState((state) => state.charts.mapping.value);
Expand Down Expand Up @@ -146,14 +148,22 @@ export default function ChartModule() {
setChartFromAPI(null);
}, [chartType, dataTypes]);

//set chart name to selected dataset if chart name is "Untitled Report"
//set chart name to selected dataset if chart name has not been focused
React.useEffect(() => {
if (page === "new" && dataset) {
if (page === "new" && !hasSubHeaderTitleFocused && dataset) {
const datasetName = datasets.find((d) => d.id === dataset)?.name;
setChartName(datasetName as string);
}
}, [dataset]);

React.useEffect(() => {
if (loadedChart.name.length > 0) {
setChartName(loadedChart.name);
} else {
setChartName("Untitled Chart");
}
}, [loadedChart]);

const mappedData = React.useMemo(
() => get(chartFromAPI, "mappedData", ""),
[chartFromAPI]
Expand Down Expand Up @@ -212,8 +222,8 @@ export default function ChartModule() {

async function clear() {
sessionStorage.setItem("visualOptions", JSON.stringify({}));
resetActivePanels();
resetDataset();
resetActivePanels();
resetMapping();
resetChartType();
resetAppliedFilters();
Expand Down Expand Up @@ -298,13 +308,6 @@ export default function ChartModule() {
};
}, [page, token]);

React.useEffect(() => {
if (loadedChart && loadedChart.id !== "") {
if (loadedChart.name.length > 0) {
setChartName(loadedChart.name);
}
}
}, [loadedChart]);
const errorComponent = () => {
return (
<div css={commonStyles.container}>
Expand Down Expand Up @@ -359,6 +362,7 @@ export default function ChartModule() {
name={chartName}
setName={setChartName}
rawViz={rawViz}
setHasSubHeaderTitleFocused={setHasSubHeaderTitleFocused}
forceEnablePreviewSave={getForceEnabledPreviewValue(view)}
appliedHeaderDetails={{} as IHeaderDetails}
framesArray={[]}
Expand Down
38 changes: 24 additions & 14 deletions src/app/modules/report-module/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export default function ReportModule() {

const [rightPanelOpen, setRightPanelOpen] = React.useState(true);
const [reportName, setReportName] = React.useState("Untitled report");
const [hasReportNameFocused, setHasReportNameFocused] = React.useState(false);
const [hasSubHeaderTitleFocused, setHasSubHeaderTitleFocused] =
React.useState(false);

const [isPreviewSaveEnabled, setIsPreviewSaveEnabled] = React.useState(false);
const [reportType, setReportType] = React.useState<
Expand Down Expand Up @@ -302,9 +303,16 @@ export default function ReportModule() {
const clearChart = useStoreActions(
(actions) => actions.charts.ChartGet.clear
);

const resetDataset = useStoreActions(
(actions) => actions.charts.dataset.reset
);
const resetChartType = useStoreActions(
(actions) => actions.charts.chartType.reset
);
const resetMapping = useStoreActions(
(actions) => actions.charts.mapping.reset
);

const reportGetData = useStoreState(
(state) => (state.reports.ReportGet.crudData ?? emptyReport) as ReportModel
Expand Down Expand Up @@ -347,6 +355,19 @@ export default function ReportModule() {
get(state.reports.ReportGet.errorData, "data.error.statusCode", 0) === 401
);

React.useEffect(() => {
return () => {
resetDataset();
resetChartType();
reportEditClear();
reportCreateClear();
resetMapping();
clearChart();
setRightPanelView("elements");
setFramesArray([]);
};
}, []);

//get current value of states for handlePersistReportState function
headerDetailsRef.current = headerDetails;
AppliedHeaderDetailsRef.current = appliedHeaderDetails;
Expand Down Expand Up @@ -435,17 +456,6 @@ export default function ReportModule() {
});
};

React.useEffect(() => {
return () => {
reportEditClear();
reportCreateClear();
clearChart();
resetDataset();
setRightPanelView("elements");
setFramesArray([]);
};
}, []);

React.useEffect(() => {
if (view === "edit" && !rightPanelOpen) {
setRightPanelOpen(true);
Expand Down Expand Up @@ -490,7 +500,7 @@ export default function ReportModule() {
pageType="report"
onReportSave={onSave}
setName={setReportName}
setHasReportNameFocused={setHasReportNameFocused}
setHasSubHeaderTitleFocused={setHasSubHeaderTitleFocused}
forceEnablePreviewSave={isPreviewSaveEnabled}
name={page !== "new" && !view ? reportGetData.name : reportName}
reportName={reportName}
Expand Down Expand Up @@ -544,7 +554,7 @@ export default function ReportModule() {
setReportName={setReportName}
reportName={reportName}
deleteFrame={deleteFrame}
hasReportNameFocused={hasReportNameFocused}
hasSubHeaderTitleFocused={hasSubHeaderTitleFocused}
reportType={reportType}
framesArray={framesArray}
headerDetails={headerDetails}
Expand Down

0 comments on commit 66939c3

Please sign in to comment.