villebro commented on a change in pull request #17903:
URL: https://github.com/apache/superset/pull/17903#discussion_r785415772
##########
File path:
superset-frontend/plugins/plugin-chart-handlebars/src/plugin/controls/handlebarTemplate.tsx
##########
@@ -0,0 +1,60 @@
+import {
+ ControlConfig,
+ ControlSetItem,
+ CustomControlConfig,
+ sharedControls,
+} from '@superset-ui/chart-controls';
+import { t, validateNonEmpty } from '@superset-ui/core';
+import React from 'react';
+import { CodeEditor } from '../../components/CodeEditor/CodeEditor';
+import { ControlHeader } from '../../components/ControlHeader/controlHeader';
+
+interface HandlebarsCustomControlProps {
+ value: string;
+}
+
+const HandlebarsTemplateControl = (
+ props: CustomControlConfig<HandlebarsCustomControlProps>,
+) => {
+ const val = String(
+ props?.value ? props?.value : props?.default ? props?.default : '',
+ );
+
+ const updateConfig = (source: string) => {
+ props.onChange(source);
+ };
+ return (
+ <div>
+ <ControlHeader>{props.label}</ControlHeader>
+ <CodeEditor
+ theme="dark"
+ value={val}
+ onChange={source => {
+ updateConfig(source || '');
+ }}
+ />
+ </div>
+ );
+};
+const handlebarsTemplateControlConfig: ControlConfig<any> = {
+ ...sharedControls.entity,
+ type: HandlebarsTemplateControl,
+ label: t('Handlebars Template'),
+ description: t('A handlebars template that is applied to the data'),
+ default: `<ul class="data_list">
+ {{#each data}}
+ <li>{{this}}</li>
+ {{/each}}
+ </ul>`,
+ isInt: false,
+
+ validators: [validateNonEmpty],
+ mapStateToProps: ({ controls }) => ({
+ value: controls?.handlebars_template?.value,
+ }),
+};
+
+export const HandlebarsTemplateControlSetItem: ControlSetItem = {
Review comment:
Yes; since they instantiate the `ControlSetItem` type, I consider naming
them like regular JS variables (camelCase) more appropriate than `PascalCase`.
So I would recommend changing the case on all of these, as it's the common
convention throughout the other control definitions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]