Skip to content

Commit

Permalink
code review fix(2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmadom committed Nov 13, 2023
1 parent 8739afd commit acf4873
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/ui/components/Widgets/Chart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const Chart = (props: ChartNoWidgetProps) => {
ignoreUsedParams,
onInnerParamsChanged,
disableChartLoader,
actionParamsEnabled,
} = props;

const innerParamsRef = React.useRef<DataProps['params'] | null>(null);
Expand Down Expand Up @@ -170,7 +171,7 @@ export const Chart = (props: ChartNoWidgetProps) => {
ignoreUsedParams,
clearedOuterParams,
onInnerParamsChanged,
enableActionParams: false,
enableActionParams: actionParamsEnabled,
});

/**
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/Widgets/Chart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type ChartKitBaseWrapperProps = ChartsProps & {
skipReload?: boolean;

renderPluginLoader?: () => React.ReactNode;
actionParamsEnabled?: boolean;
};

export type ChartWidgetProviderPropsWithRefProps = Omit<
Expand Down
1 change: 1 addition & 0 deletions src/ui/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export const URL_OPTIONS = {
EMBEDDED: '_embedded',
NO_CONTROLS: '_no_controls',
LANGUAGE: '_lang',
ACTION_PARAMS_ENABLED: '_ap_enabled',
};

export const DLS_SUBJECT = {
Expand Down
18 changes: 3 additions & 15 deletions src/ui/libs/DatalensChartkit/ChartKit/helpers/apply-hc-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type {Highcharts} from '@gravity-ui/chartkit/highcharts';
import {pickActionParamsFromParams} from '@gravity-ui/dashkit';
import {wrap} from 'highcharts';
import get from 'lodash/get';
import has from 'lodash/has';
import merge from 'lodash/merge';
import set from 'lodash/set';
import {GraphWidgetEventScope, URL_ACTION_PARAMS_PREFIX} from 'shared';

import type {GraphWidgetEventScope} from '../../../../../shared';
import type {GraphWidget} from '../../types';
import type {ChartKitAdapterProps} from '../types';

Expand All @@ -30,19 +31,6 @@ export const fixPieTotals = (args: {data: GraphWidget}) => {
});
};

function getActionParams(params: Record<string, string | string[]> = {}) {
const actionParams: Record<string, string | string[]> = {};
Object.entries(params).forEach(([key, value]) => {
if (key.startsWith(URL_ACTION_PARAMS_PREFIX)) {
actionParams[key.slice(URL_ACTION_PARAMS_PREFIX.length)] = Array.isArray(value)
? value
: [value];
}
});

return actionParams;
}

export const applySetActionParamsEvents = (args: {
action: ShapedAction;
data: GraphWidget;
Expand Down Expand Up @@ -72,7 +60,7 @@ export const applySetActionParamsEvents = (args: {
set(data, pathToScatterMarkerStates, {});
}

const actionParams = getActionParams(get(data, 'unresolvedParams', {}));
const actionParams = pickActionParamsFromParams(get(data, 'unresolvedParams', {}));

wrap(
get(data, pathToChartEvents),
Expand Down
3 changes: 2 additions & 1 deletion src/ui/units/preview/components/Preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const Preview: React.FC<PreviewProps> = (props) => {
isEmbedded,
} = props;

const {noControls} = Utils.getOptionsFromSearch(search);
const {noControls, actionParamsEnabled} = Utils.getOptionsFromSearch(search);

const possibleEntryId = React.useMemo(() => extractEntryId(idOrSource), [idOrSource]);

Expand Down Expand Up @@ -197,6 +197,7 @@ const Preview: React.FC<PreviewProps> = (props) => {
onChartLoad={onChartLoad}
onChartRender={onChartRender}
noControls={noControls}
actionParamsEnabled={actionParamsEnabled}
forwardedRef={chartKitRef as unknown as React.RefObject<ChartKitType>}
splitTooltip={hasSplitTooltip}
menuType="preview"
Expand Down
1 change: 1 addition & 0 deletions src/ui/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export default class Utils {
noControls:
searchParams.get(URL_OPTIONS.NO_CONTROLS) === '1' ||
searchParams.get(URL_OPTIONS.NO_CONTROLS) === 'true', // deprecated
actionParamsEnabled: searchParams.get(URL_OPTIONS.ACTION_PARAMS_ENABLED) === '1',
};
}

Expand Down

0 comments on commit acf4873

Please sign in to comment.