MCPcopy Create free account
hub / github.com/microsoft/data-formulator / handleRefreshVariant

Function handleRefreshVariant

src/views/EncodingShelfCard.tsx:996–1067  ·  view source on GitHub ↗
(variant: ChartStyleVariant)

Source from the content-addressed store, hash-verified

994 * Triggered automatically by clicking a stale chip.
995 */
996 const handleRefreshVariant = async (variant: ChartStyleVariant) => {
997 if (refreshingVariantId) return;
998 if (!activeModel) {
999 dispatch(dfActions.addMessages({
1000 timestamp: Date.now(),
1001 component: 'chart restyle',
1002 type: 'error',
1003 value: 'No model is configured. Please select a model before refreshing.',
1004 }));
1005 return;
1006 }
1007 // Refresh always starts from the current default spec (NOT the stale
1008 // variant's spec) so we don't compound staleness. We re-run the
1009 // variant's original prompt against the freshly-assembled spec, with
1010 // the previous variant spec as a STYLE REFERENCE so visual choices
1011 // carry forward.
1012 const prepared = buildSpecForRestyle(chart, currentTable, conceptShelfItems);
1013 if (!prepared) {
1014 dispatch(dfActions.addMessages({
1015 timestamp: Date.now(),
1016 component: 'chart restyle',
1017 type: 'error',
1018 value: 'Cannot refresh — chart is not currently renderable.',
1019 }));
1020 return;
1021 }
1022 const { dataSample } = buildDataContext(currentTable, prepared.embeddedData);
1023
1024 setRefreshingVariantId(variant.id);
1025 // Surface the standard "chart agent working" signal in the canvas
1026 // (LinearProgress overlay) while the refresh request is in flight.
1027 dispatch(dfActions.changeChartRunningStatus({ chartId, status: true }));
1028 try {
1029 const result = await callRestyleAgent({
1030 instruction: variant.prompt,
1031 vlSpec: prepared.spec,
1032 chartType: chart.chartType,
1033 dataSample,
1034 model: activeModel,
1035 styleReferenceSpec: variant.vlSpec,
1036 });
1037 if (result.kind === 'out_of_scope') {
1038 dispatch(dfActions.addMessages({
1039 timestamp: Date.now(),
1040 component: 'chart restyle',
1041 type: 'info',
1042 value: result.rationale
1043 ? `Style agent: "${result.rationale}"`
1044 : 'Could not refresh this variant against the current encoding.',
1045 }));
1046 return;
1047 }
1048 dispatch(dfActions.updateStyleVariant({
1049 chartId,
1050 variantId: variant.id,
1051 vlSpec: result.vlSpec,
1052 rationale: result.rationale,
1053 encodingFingerprint: computeEncodingFingerprint(chart),

Callers 1

EncodingShelfCardFunction · 0.85

Calls 4

buildSpecForRestyleFunction · 0.90
buildDataContextFunction · 0.90
callRestyleAgentFunction · 0.90

Tested by

no test coverage detected