Skip to content

Commit

Permalink
fix: chat & pure renderer with multi info
Browse files Browse the repository at this point in the history
  • Loading branch information
islxyqwe committed May 22, 2024
1 parent aa4672c commit a459054
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
22 changes: 21 additions & 1 deletion packages/graphic-walker/src/components/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { useReporter } from '@/utils/reportError';
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible';
import { Textarea } from '../ui/textarea';
import LoadingLayer from '../loadingLayer';
import { transformMultiDatasetFields } from '@/utils/route';
import { viewEncodingKeys } from '@/models/visSpec';
import { emptyEncodings } from '@/utils/save';

async function fetchQueryChat(api: string, metas: IViewField[], messages: IChatMessage[], headers: Record<string, string>) {
const res = await fetch(api, {
Expand Down Expand Up @@ -116,6 +119,23 @@ const AssistantMessage = observer(function AssistantMessage(props: { message: IA
return { allFields, viewDimensions, viewMeasures, filters };
}, [encodings]);

const multiViewInfo = useMemo(() => {
const viewsEncodings: Partial<Record<keyof DraggableFieldState, IViewField[]>> = {};
viewEncodingKeys(config.geoms[0]).forEach((k) => {
viewsEncodings[k] = encodings[k];
});

const { filters, views } = transformMultiDatasetFields({
filters: encodings.filters,
views: viewsEncodings,
});
return {
...emptyEncodings,
...views,
filters,
};
}, [encodings, config.geoms]);

const { viewData: data, loading: waiting } = useRenderer({
allFields,
viewDimensions,
Expand Down Expand Up @@ -149,7 +169,7 @@ const AssistantMessage = observer(function AssistantMessage(props: { message: IA
vizThemeConfig={vizThemeConfig}
name={name}
data={data}
draggableFieldState={encodings}
draggableFieldState={multiViewInfo}
visualConfig={config}
layout={{
...layout,
Expand Down
22 changes: 21 additions & 1 deletion packages/graphic-walker/src/renderer/pureRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { GWGlobalConfig } from '../vis/theme';
import { VizAppContext } from '../store/context';
import { useCurrentMediaTheme } from '../utils/media';
import LoadingLayer from '@/components/loadingLayer';
import { transformMultiDatasetFields } from '@/utils/route';
import { viewEncodingKeys } from '@/models/visSpec';
import { emptyEncodings } from '@/utils/save';

type IPureRendererProps = {
className?: string;
Expand Down Expand Up @@ -162,6 +165,23 @@ const PureRenderer = forwardRef<IReactVegaHandler, IPureRendererProps & (LocalPr
const darkMode = useCurrentMediaTheme(appearance ?? dark);
const [portal, setPortal] = useState<HTMLDivElement | null>(null);

const encoding = useMemo(() => {
const viewsEncodings: Partial<Record<keyof DraggableFieldState, IViewField[]>> = {};
viewEncodingKeys(visualConfig.geoms[0]).forEach((k) => {
viewsEncodings[k] = visualState[k];
});

const { filters, views } = transformMultiDatasetFields({
filters: visualState.filters,
views: viewsEncodings,
});
return {
...emptyEncodings,
...views,
filters,
};
}, [visualState, visualConfig.geoms]);

return (
<ShadowDom style={sizeMode === 'full' ? { width: '100%', height: '100%' } : undefined} className={className} uiTheme={uiTheme ?? colorConfig}>
<VizAppContext
Expand All @@ -183,7 +203,7 @@ const PureRenderer = forwardRef<IReactVegaHandler, IPureRendererProps & (LocalPr
name={name}
data={viewData}
ref={ref}
draggableFieldState={visualState}
draggableFieldState={encoding}
visualConfig={visualConfig}
layout={visualLayout}
locale={locale ?? 'en-US'}
Expand Down

0 comments on commit a459054

Please sign in to comment.