Skip to content

Commit

Permalink
change of names
Browse files Browse the repository at this point in the history
  • Loading branch information
BennuFire committed Nov 28, 2022
1 parent c7f4338 commit a6fe6fc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
29 changes: 18 additions & 11 deletions src/card/view/CardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ const NeoCardView = ({ title, database, query, globalParameters,
const cardHeight = heightPx - CARD_FOOTER_HEIGHT;
const ref = React.useRef();

const getLocalParameters = (parse_string): any => {
let re = /(?:^|\W)\$(\w+)(?!\w)/g, match, localQueryVariables: string[] = [];
while (match = re.exec(parse_string)) {
localQueryVariables.push(match[1]);
}

if (!globalParameters) {
return {};
}
return Object.fromEntries(Object.entries(globalParameters).filter(([local]) => localQueryVariables.includes(local)));
}

// @ts-ignore
const reportHeader = <NeoCardViewHeader
title={title}
Expand All @@ -35,6 +47,7 @@ const NeoCardView = ({ title, database, query, globalParameters,
onDownloadImage={() => downloadComponentAsImage(ref)}
onToggleCardExpand={onToggleCardExpand}
expanded={expanded}
parameters={getLocalParameters(title)}
>
</NeoCardViewHeader>;

Expand All @@ -59,17 +72,11 @@ const NeoCardView = ({ title, database, query, globalParameters,
return globalParameters ? globalParameters[key] : undefined;
}

const getLocalParameters = (): any => {
let re = /(?:^|\W)\$(\w+)(?!\w)/g, match, localQueryVariables: string[] = [];
while (match = re.exec(query)) {
localQueryVariables.push(match[1]);
}
// ONLY if the 'actions' extension is enabled, we send 'actionsRules' to the table visualization.
const filteredSettings = Object.fromEntries(Object.entries(settings).filter(
([k, v]) => !(k == 'actionsRules' && dashboardSettings['extensions'] != null && !dashboardSettings['extensions'].includes('actions')))
);

if (!globalParameters) {
return {};
}
return Object.fromEntries(Object.entries(globalParameters).filter(([local]) => localQueryVariables.includes(local)));
}

// TODO - understand why CardContent is throwing a warning based on this style config.
const cardContentStyle = {
Expand All @@ -83,7 +90,7 @@ const NeoCardView = ({ title, database, query, globalParameters,
<NeoReport
query={query}
database={database}
parameters={getLocalParameters()}
parameters={getLocalParameters(query)}
extensions={extensions}
disabled={settingsOpen}
selection={selection}
Expand Down
27 changes: 25 additions & 2 deletions src/card/view/CardViewHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,41 @@ import ReactMarkdown from "react-markdown";
import gfm from 'remark-gfm';

const NeoCardViewHeader = ({ title, description, editable, onTitleUpdate, fullscreenEnabled, downloadImageEnabled,
onToggleCardSettings, onDownloadImage, onToggleCardExpand, expanded }) => {
onToggleCardSettings, onDownloadImage, onToggleCardExpand, expanded, parameters }) => {

const [text, setText] = React.useState(title);
const [parsedText, setParsedText] = React.useState(title);
const [editing, setEditing] = React.useState(false);
const [descriptionModalOpen, setDescriptionModalOpen] = React.useState(false);

function replaceParamsOnString(s, p){
for (const [key, value] of Object.entries(p)) {
s= s.replace("$"+key+" ", value+" ");
}
return s;
}

// Ensure that we only trigger a text update event after the user has stopped typing.
const debouncedTitleUpdate = useCallback(
debounce(onTitleUpdate, 250),
[],
);

useEffect(() => {
let titleParsed = replaceParamsOnString(`${title}`, parameters);
if(!editing)
setParsedText(titleParsed);

}, [editing,parameters])

useEffect(() => {
// Reset text to the dashboard state when the page gets reorganized.
if (text !== title) {
setText(title);
}
}, [title])


const cardTitle = <>
<table style={{ width: "100%" }}>
<tbody>
Expand All @@ -45,13 +62,19 @@ const NeoCardViewHeader = ({ title, description, editable, onTitleUpdate, fullsc
<td style={{ width: "100%" }}>
<TextField
id="standard-outlined"
onFocus={(e) => {
setEditing(true);
}}
onBlur={(e) => {
setEditing(false);
}}
className={"no-underline large"}
label=""
disabled={!editable}
placeholder="Report name..."
fullWidth
maxRows={4}
value={text}
value={editing ? text : parsedText}
onChange={(event) => {
setText(event.target.value);
debouncedTitleUpdate(event.target.value);
Expand Down
1 change: 0 additions & 1 deletion src/extensions/advancedcharts/chart/radar/RadarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import { NoDrawableDataErrorMessage } from '../../../../component/editor/CodeVie
selection.values.concat([selection['index']]).forEach((k,i) => {
const fieldIndex = r["_fieldLookup"][k];
if(k !== selection['index'] && isNaN(r["_fields"][fieldIndex])){
console.log(k, r["_fields"][fieldIndex])
valid = false;
}
entry[k] = ""+r["_fields"][fieldIndex];
Expand Down

0 comments on commit a6fe6fc

Please sign in to comment.