Skip to content

Commit

Permalink
Merge pull request #1540 from merico-dev/1538-wrong-viz-config-when-s…
Browse files Browse the repository at this point in the history
…witching-panels

1538 wrong viz config when switching panels
  • Loading branch information
GerilLeto authored Sep 18, 2024
2 parents 0e0da10 + 775b609 commit 1b150d5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/api",
"version": "13.41.0",
"version": "13.41.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/dashboard",
"version": "13.41.0",
"version": "13.41.1",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Box, Flex, Sx } from '@mantine/core';
import { useCallback, useEffect, useMemo, useRef } from 'react';

import { defaults } from 'lodash';
import { observer } from 'mobx-react-lite';
import { useStorageData } from '~/components/plugins/hooks';
import { ReadonlyRichText } from '~/components/widgets';
Expand All @@ -10,7 +9,7 @@ import { useCurrentInteractionManager, useTriggerSnapshotList } from '~/interact
import { VizViewProps } from '~/types/plugin';
import { parseRichTextContent } from '~/utils';
import { ClickStats } from './triggers';
import { DEFAULT_CONFIG, IVizStatsConf } from './type';
import { IVizStatsConf } from './type';

const verticalAlignments = {
top: 'flex-start',
Expand All @@ -31,7 +30,8 @@ function getWrapperSx(triggersCount: number) {
return ret;
}

export const VizStats = observer(({ context, instance }: VizViewProps) => {
type RenderProps = VizViewProps;
export const Render = observer(({ context, instance }: RenderProps) => {
const ref = useRef<HTMLDivElement>(null);
const interactionManager = useCurrentInteractionManager({
vizManager: context.vizManager,
Expand All @@ -41,18 +41,20 @@ export const VizStats = observer(({ context, instance }: VizViewProps) => {
const triggers = useTriggerSnapshotList<IVizStatsConf>(interactionManager.triggerManager, ClickStats.id);

const contentModel = useRenderContentModelContext();
const { value: confValue = DEFAULT_CONFIG } = useStorageData<IVizStatsConf>(context.instanceData, 'config');

const { panel } = useRenderPanelContext();
const conf = panel.viz.conf.config as IVizStatsConf;

const { data, variables } = context;
const { width, height } = context.viewport;

const richTextContent = useMemo(() => {
const conf = defaults({}, confValue, DEFAULT_CONFIG);
const conf = panel.viz.conf.config;
if (!conf.content) {
return '';
}
return parseRichTextContent(conf.content, variables, contentModel.payloadForViz, data);
}, [data, confValue, variables, contentModel.payloadForViz]);
}, [data, panel, variables, contentModel.payloadForViz]);

const handleContentClick = useCallback(() => {
triggers.forEach((t) => {
Expand Down Expand Up @@ -83,7 +85,7 @@ export const VizStats = observer(({ context, instance }: VizViewProps) => {
width,
height,
}}
align={verticalAlignments[confValue.vertical_align]}
align={verticalAlignments[conf.vertical_align]}
direction="row"
>
<Box className="viz-stats--clickable-wrapper" sx={getWrapperSx(triggers.length)} onClick={handleContentClick}>
Expand Down Expand Up @@ -120,3 +122,14 @@ export const VizStats = observer(({ context, instance }: VizViewProps) => {
</Flex>
);
});

export const VizStats = (props: VizViewProps) => {
const { context } = props;
const { value: conf } = useStorageData<IVizStatsConf>(context.instanceData, 'config');

if (!conf) {
return null;
}

return <Render {...props} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ColorMappingControl, ColorMappingMark } from './color-mapping-mark';
import { ColorPickerControl } from './color-picker-control';
import { DynamicColorControl, DynamicColorMark } from './dynamic-color-mark';
import { ChooseFontSize, FontSize } from './font-size-extension';
import { useBoolean } from 'ahooks';

const RTEContentStyle: Sx = {
'dynamic-color': {
Expand Down Expand Up @@ -110,6 +111,7 @@ export const CustomRichTextEditor = forwardRef(
return ret;
}, [inPanelContext]);

const [focused, { setTrue, setFalse }] = useBoolean(false);
const [content, setContent] = useState(value);
const editor = useEditor({
extensions,
Expand All @@ -123,6 +125,8 @@ export const CustomRichTextEditor = forwardRef(
editor.view.dom.setAttribute('autocomplete', 'off');
editor.view.dom.setAttribute('autocapitalize', 'off');
},
onFocus: setTrue,
onBlur: setFalse,
});

useEffect(() => {
Expand All @@ -142,11 +146,11 @@ export const CustomRichTextEditor = forwardRef(
const changed = value !== content;

useEffect(() => {
if (!autoSubmit) {
if (!autoSubmit || !focused) {
return;
}
submit();
}, [autoSubmit, changed]);
}, [autoSubmit, changed, focused]);

const finalStyles = useMemo(() => {
return _.defaultsDeep({}, { content: { ...CommonHTMLContentStyle, ...RTEContentStyle } }, styles);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/root",
"version": "13.41.0",
"version": "13.41.1",
"private": true,
"workspaces": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion settings-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/settings-form",
"version": "13.41.0",
"version": "13.41.1",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@devtable/website",
"private": true,
"license": "Apache-2.0",
"version": "13.41.0",
"version": "13.41.1",
"scripts": {
"dev": "vite",
"preview": "vite preview"
Expand Down

0 comments on commit 1b150d5

Please sign in to comment.