Skip to content

Commit

Permalink
Merge pull request #148 from zimmerman-team/feat/base-report
Browse files Browse the repository at this point in the history
Feat/base report DX-1420
  • Loading branch information
Psami-wondah authored Jun 7, 2024
2 parents 1ab2153 + a3c973c commit 252e430
Show file tree
Hide file tree
Showing 32 changed files with 689 additions and 327 deletions.
1 change: 0 additions & 1 deletion src/app/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function Providers(props: ProviderProps) {
<Router>
<div
css={`
position: relative;
min-height: calc(100vh - 60px);
`}
>
Expand Down
63 changes: 60 additions & 3 deletions src/app/modules/chart-module/components/common-chart/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from "react";
import { useStoreState } from "app/state/store/hooks";
import { useStoreActions, useStoreState } from "app/state/store/hooks";
import { PageLoader } from "app/modules/common/page-loader";
import { useDataThemesEchart } from "app/hooks/useDataThemesEchart";
import { useUpdateEffectOnce } from "app/hooks/useUpdateEffectOnce";
import GeomapLegend from "../geomap-legend";
import GeomapLegend from "app/modules/chart-module/components/geomap-legend";
import { ChartAPIModel } from "app/modules/chart-module/data";
import { DatasetListItemAPIModel } from "app/modules/dataset-module/data";

export type ChartType =
| "echartsBarchart"
Expand Down Expand Up @@ -44,14 +46,42 @@ interface Props {

export function CommonChart(props: Readonly<Props>) {
const { render } = useDataThemesEchart();
const token = useStoreState((state) => state.AuthToken.value);

const domRef = React.useRef<HTMLDivElement>(null);
const chartTypeFromState = useStoreState(
(state) => state.charts.chartType.value
);

const chartType = props.renderedChartType ?? chartTypeFromState;
const loadedChart =
useStoreState((state) => state.charts.ChartGet.crudData as ChartAPIModel) ??
useStoreState(
(state) => state.charts.ChartGetInReport.crudData as ChartAPIModel
);
const datasetId = loadedChart?.datasetId;
const loadDataset = useStoreActions(
(actions) => actions.dataThemes.DatasetGet.fetch
);
const datasetDetails = useStoreState(
(state) =>
(state.dataThemes.DatasetGet.crudData ?? {}) as DatasetListItemAPIModel
);

React.useEffect(() => {
if (token) {
loadDataset({
token,
getId: datasetId as string,
});
} else {
loadDataset({
token,
getId: datasetId as string,
nonAuthCall: !token,
});
}
}, [token, datasetId]);
useUpdateEffectOnce(() => {
if (props.containerRef.current) {
const tmpVisualOptions = {
Expand Down Expand Up @@ -160,7 +190,6 @@ export function CommonChart(props: Readonly<Props>) {
props.renderedChartSsr,
props.renderedChartMappedData,
]);

let content;
let contentHeight;
if (!props.chartPreviewInReport && props.renderedChartType !== "bigNumber") {
Expand Down Expand Up @@ -274,6 +303,34 @@ export function CommonChart(props: Readonly<Props>) {
}
`}
/>

<p
css={`
color: #70777e;
font-family: "GothamNarrow-Bold", sans-serif;
font-size: 12px;
position: absolute;
bottom: 0;
left: 0;
a {
font-family: "GothamNarrow-Bold", sans-serif;
color: #70777e;
text-decoration: none;
border-bottom: 1px solid #70777e;
}
`}
>
Source:{" "}
<a
href={datasetDetails.sourceUrl}
target="_blank"
rel="noopener noreferrer"
>
{datasetDetails.source} - Data file: {datasetDetails.sourceUrl}
</a>
</p>
{chartType === "echartsGeomap" && props.visualOptions?.showLegend ? (
<div
css={`
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/chart-module/routes/chart-type/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ function ChartBuilderChartType(props: Readonly<ChartBuilderChartTypeProps>) {
margin-bottom: 0px;
span {
color: #359c96;
font-family: "GothamNarrow-Bold", sans-serif;
}
`}
>
Expand Down
52 changes: 51 additions & 1 deletion src/app/modules/chart-module/routes/preview-theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import get from "lodash/get";
import isEmpty from "lodash/isEmpty";
import useTitle from "react-use/lib/useTitle";
import { useStoreState } from "app/state/store/hooks";
import { useStoreActions, useStoreState } from "app/state/store/hooks";
import { useHistory, useParams } from "react-router-dom";
/* project */
import Skeleton from "@material-ui/lab/Skeleton";
Expand All @@ -14,9 +14,12 @@ import WarningDialog from "app/modules/chart-module/components/dialog/warningDia
import { ReactComponent as AIIcon } from "app/modules/chart-module/assets/ai-icon.svg";
import GeomapLegend from "app/modules/chart-module/components/geomap-legend";
import ErrorComponent from "app/modules/chart-module/components/dialog/errrorComponent";
import { ChartAPIModel } from "app/modules/chart-module/data";
import { DatasetListItemAPIModel } from "app/modules/dataset-module/data";

export function ChartBuilderPreviewTheme(props: ChartBuilderPreviewThemeProps) {
useTitle("DX DataXplorer - Preview Chart");
const token = useStoreState((state) => state.AuthToken.value);

const domRef = React.useRef<HTMLDivElement>(null);

Expand All @@ -32,6 +35,27 @@ export function ChartBuilderPreviewTheme(props: ChartBuilderPreviewThemeProps) {
(state) => state.charts.chartType.value
);

const loadDataset = useStoreActions(
(actions) => actions.dataThemes.DatasetGet.fetch
);
const datasetDetails = useStoreState(
(state) =>
(state.dataThemes.DatasetGet.crudData ?? {}) as DatasetListItemAPIModel
);
React.useEffect(() => {
if (token) {
loadDataset({
token,
getId: dataset as string,
});
} else {
loadDataset({
token,
getId: dataset as string,
nonAuthCall: !token,
});
}
}, [token, dataset]);
React.useEffect(() => {
//if dataset is empty and not loading, redirect to data page
//doing this for only new chart because existing chart will have data (gotten from page id)
Expand Down Expand Up @@ -243,7 +267,33 @@ export function ChartBuilderPreviewTheme(props: ChartBuilderPreviewThemeProps) {
>
<AIIcon />
</div>
<p
css={`
color: #70777e;
font-family: "GothamNarrow-Bold", sans-serif;
font-size: 12px;
position: absolute;
bottom: 0;
left: 0;
a {
font-family: "GothamNarrow-Bold", sans-serif;
color: #70777e;
text-decoration: none;
border-bottom: 1px solid #70777e;
}
`}
>
Source:{" "}
<a
href={datasetDetails.sourceUrl}
target="_blank"
rel="noopener noreferrer"
>
{datasetDetails.source} - Data file:{" "}
{datasetDetails.sourceUrl}
</a>
</p>
{selectedChartType === "echartsGeomap" &&
props.visualOptions?.showLegend ? (
<div
Expand Down
127 changes: 127 additions & 0 deletions src/app/modules/common/RichEditor/FontSizeController/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { EditorState, RichUtils, ContentState, Modifier } from "draft-js";
import { set } from "lodash";
import React, { useEffect } from "react";

interface Props {
getEditorState: () => EditorState;
setEditorState: (value: EditorState) => void;
theme: any;
}
export default function FontSizeController(props: Props) {
const [fontSize, setFontSize] = React.useState(10);

const reduceFontSize = () => {
const editorState = props.getEditorState();

const currentStyle = editorState.getCurrentInlineStyle();

let newEditorState = editorState;
if (currentStyle.has(`font-size-${fontSize - 1}`)) {
newEditorState = RichUtils.toggleInlineStyle(
editorState,
`font-size-${fontSize - 1}`
); // reset the font size
}

props.setEditorState(
RichUtils.toggleInlineStyle(newEditorState, `font-size-${fontSize - 1}`)
);
setFontSize((prev) => prev - 1);
};
const increaseFontSize = () => {
const editorState = props.getEditorState();
const currentStyle = editorState.getCurrentInlineStyle();
let newEditorState = editorState;

if (currentStyle.has(`font-size-${fontSize + 1}`)) {
// reset the font size
newEditorState = RichUtils.toggleInlineStyle(
editorState,
`font-size-${fontSize + 1}`
);
}
props.setEditorState(
RichUtils.toggleInlineStyle(newEditorState, `font-size-${fontSize + 1}`)
);
setFontSize((prev) => prev + 1);
};

useEffect(() => {
const currentStyle = props.getEditorState().getCurrentInlineStyle();
const nfontSize = currentStyle.findLast((style: any) =>
style.includes("font-size")
);
if (nfontSize) {
const size = nfontSize.split("-")[2];
setFontSize(Number(size));
}
}, [props.getEditorState().getCurrentInlineStyle()]);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.value === "" || /^[0-9\b]+$/.test(e.target.value)) {
const editorState = props.getEditorState();
const currentStyle = editorState.getCurrentInlineStyle();
let newEditorState = editorState;

if (currentStyle.has(`font-size-${e.target.value}`)) {
// reset the font size
newEditorState = RichUtils.toggleInlineStyle(
editorState,
`font-size-${e.target.value}`
);
}
props.setEditorState(
RichUtils.toggleInlineStyle(
newEditorState,
`font-size-${e.target.value}`
)
);
setFontSize(Number(e.target.value));
}
};

return (
<>
<div
css={`
width: 57px;
height: 24px;
display: flex;
align-items: center;
justify-content: space-evenly;
border-radius: 8px;
background: #f4f4f4;
span {
font-size: 14px;
color: #70777e;
font-family: "GothamNarrow-Bold", sans-serif;
cursor: pointer;
}
input {
width: 20px;
height: 100%;
text-align: center;
background: transparent;
border: none;
font-size: 14px;
font-family: "GothamNarrow-Bold", sans-serif;
color: #70777e;
outline: none;
}
`}
>
<span onClick={() => reduceFontSize()}>-</span>
<input
type="text"
name="font-size"
id=""
onChange={handleInputChange}
value={fontSize}
min={1}
/>
<span onClick={() => increaseFontSize()}>+</span>
</div>
</>
);
}
11 changes: 11 additions & 0 deletions src/app/modules/common/RichEditor/FontSizeController/styleMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fontSizeStyleMap = {
"font-size-1": { fontSize: "1px" },
};

for (let i = 1; i <= 100; i++) {
fontSizeStyleMap[`font-size-${i}` as keyof typeof fontSizeStyleMap] = {
fontSize: `${i}px`,
};
}

export default fontSizeStyleMap;
11 changes: 6 additions & 5 deletions src/app/modules/common/RichEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import createUndoPlugin from "@draft-js-plugins/undo";
import createTextAlignmentPlugin from "@draft-js-plugins/text-alignment";
import { RedoIcon } from "app/assets/icons/Redo";
import { UndoIcon } from "app/assets/icons/Undo";
import { EmojiButton } from "./buttons";
import { EmojiButton } from "app/modules/common/RichEditor/buttons";

/* stylesheets */
import "@draft-js-plugins/anchor/lib/plugin.css";
Expand All @@ -24,6 +24,7 @@ import alignmentStyles from "./alignmentStyles.module.css";
import "@draft-js-plugins/inline-toolbar/lib/plugin.css";
import "@draft-js-plugins/static-toolbar/lib/plugin.css";
import "@draft-js-plugins/emoji/lib/plugin.css";
import fontSizeStyleMap from "app/modules/common/RichEditor/FontSizeController/styleMap";

export const RichEditor = (props: {
editMode: boolean;
Expand Down Expand Up @@ -130,9 +131,9 @@ export const RichEditor = (props: {
.public-DraftEditorPlaceholder-inner {
position: absolute;
color: #dfe3e5;
font-weight: bold;
font-size: 16px;
color: #adb5bd;
font-size: 14px;
font-family: "GothamNarrow-Book", "Helvetica Neue", sans-serif;
}
`}
data-cy="rich-text-editor-container"
Expand All @@ -142,10 +143,10 @@ export const RichEditor = (props: {
customStyleMap={{
...bgPicker.bgColorStyleMap,
...picker.colorStyleMap,
...fontSizeStyleMap,
BOLD: {
fontFamily: "GothamNarrow-Bold",
fontWeight: "bold",
fontSize: "14px",
lineHeight: "normal",
},
}}
Expand Down
2 changes: 2 additions & 0 deletions src/app/modules/dataset-module/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface DatasetListItemAPIModel {
category: string;
createdDate: Date;
owner: string;
source: string;
sourceUrl: string;
}
export const tHeadData = [
{
Expand Down
Loading

0 comments on commit 252e430

Please sign in to comment.