@grafana/plugin-ui 0.10.8 → 0.10.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +20 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/components/SQLEditor/components/SQLEditor.js +7 -5
- package/dist/esm/components/SQLEditor/components/SQLEditor.js.map +1 -1
- package/dist/esm/components/SQLEditor/hooks/useLatestCallback.js +16 -0
- package/dist/esm/components/SQLEditor/hooks/useLatestCallback.js.map +1 -0
- package/dist/esm/components/VisualQueryBuilder/components/QueryBuilderHints.js +3 -4
- package/dist/esm/components/VisualQueryBuilder/components/QueryBuilderHints.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -2880,6 +2880,18 @@ const standardSQLLanguageDefinition = {
|
|
|
2880
2880
|
completionProvider: getStandardSQLCompletionProvider
|
|
2881
2881
|
};
|
|
2882
2882
|
|
|
2883
|
+
function useLatestCallback(callback) {
|
|
2884
|
+
const ref = React.useRef(callback);
|
|
2885
|
+
React.useEffect(() => {
|
|
2886
|
+
ref.current = callback;
|
|
2887
|
+
});
|
|
2888
|
+
const hasCallback = Boolean(callback);
|
|
2889
|
+
return React.useMemo(
|
|
2890
|
+
() => hasCallback ? (...args) => ref.current(...args) : undefined,
|
|
2891
|
+
[hasCallback]
|
|
2892
|
+
);
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2883
2895
|
const STANDARD_SQL_LANGUAGE = "sql";
|
|
2884
2896
|
const LANGUAGES_CACHE = /* @__PURE__ */ new Map();
|
|
2885
2897
|
const INSTANCE_CACHE = /* @__PURE__ */ new Map();
|
|
@@ -2894,6 +2906,7 @@ const SQLEditor = ({
|
|
|
2894
2906
|
}) => {
|
|
2895
2907
|
const monacoRef = React.useRef(null);
|
|
2896
2908
|
const langUid = React.useRef();
|
|
2909
|
+
const stableOnChange = useLatestCallback(onChange);
|
|
2897
2910
|
const id = React.useMemo(() => {
|
|
2898
2911
|
const uid = uuid.v4();
|
|
2899
2912
|
const id2 = `${language.id}-${uid}`;
|
|
@@ -2914,7 +2927,7 @@ const SQLEditor = ({
|
|
|
2914
2927
|
}
|
|
2915
2928
|
}, []);
|
|
2916
2929
|
const onSqlBlur = (text) => {
|
|
2917
|
-
|
|
2930
|
+
stableOnChange && stableOnChange(text, false);
|
|
2918
2931
|
onBlur && onBlur(text);
|
|
2919
2932
|
};
|
|
2920
2933
|
return /* @__PURE__ */ React__namespace.default.createElement("div", { style: { width } }, /* @__PURE__ */ React__namespace.default.createElement(
|
|
@@ -2931,14 +2944,14 @@ const SQLEditor = ({
|
|
|
2931
2944
|
monacoRef.current = editor;
|
|
2932
2945
|
editor.onDidChangeModelContent((e) => {
|
|
2933
2946
|
const text = editor.getValue();
|
|
2934
|
-
if (
|
|
2935
|
-
|
|
2947
|
+
if (stableOnChange) {
|
|
2948
|
+
stableOnChange(text, false);
|
|
2936
2949
|
}
|
|
2937
2950
|
});
|
|
2938
2951
|
editor.addCommand(m.KeyMod.CtrlCmd | m.KeyCode.Enter, () => {
|
|
2939
2952
|
const text = editor.getValue();
|
|
2940
|
-
if (
|
|
2941
|
-
|
|
2953
|
+
if (stableOnChange) {
|
|
2954
|
+
stableOnChange(text, true);
|
|
2942
2955
|
}
|
|
2943
2956
|
});
|
|
2944
2957
|
editor.onKeyUp((e) => {
|
|
@@ -9595,16 +9608,15 @@ const QueryBuilderHints = ({
|
|
|
9595
9608
|
buildDataQueryFromQueryString,
|
|
9596
9609
|
buildQueryStringFromDataQuery
|
|
9597
9610
|
}) => {
|
|
9598
|
-
const [hints, setHints] = React.useState([]);
|
|
9599
9611
|
const styles = ui.useStyles2(getStyles$2);
|
|
9600
|
-
React.
|
|
9612
|
+
const hints = React.useMemo(() => {
|
|
9601
9613
|
var _a;
|
|
9602
9614
|
const dataQuery = buildDataQueryFromQueryString(queryModeller.renderQuery(visualQuery));
|
|
9603
9615
|
const hints2 = (_a = datasource.getQueryHints) == null ? undefined : _a.call(datasource, dataQuery, (data == null ? undefined : data.series) || []).filter((hint) => {
|
|
9604
9616
|
var _a2;
|
|
9605
9617
|
return (_a2 = hint.fix) == null ? undefined : _a2.action;
|
|
9606
9618
|
});
|
|
9607
|
-
|
|
9619
|
+
return hints2 != null ? hints2 : [];
|
|
9608
9620
|
}, [datasource, visualQuery, data, queryModeller, buildDataQueryFromQueryString]);
|
|
9609
9621
|
return /* @__PURE__ */ React__namespace.default.createElement(React__namespace.default.Fragment, null, hints.length > 0 && /* @__PURE__ */ React__namespace.default.createElement("div", { className: styles.container }, hints.map((hint) => {
|
|
9610
9622
|
var _a, _b, _c, _d;
|