Skip to content

Commit

Permalink
feat: add a method to get templates for the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Loori-R committed Jul 19, 2023
1 parent 5b1234e commit 82cd75e
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/components/monaco-query-field/MonacoQueryField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,26 @@ const MonacoQueryField = (props: Props) => {
Promise.resolve(historyRef.current.map((h) => h.query.expr).filter((expr) => expr !== undefined));

const getAllMetricNames = () => {
const { metrics, metricsMetadata, withTemplates } = lpRef.current;
const templates = withTemplates.map(t => ({ name: t.label, help: t.value, type: "WITH template" }))
const { metrics, metricsMetadata } = lpRef.current;
const result = metrics.map((m) => {
const metaItem = metricsMetadata?.[m];
return {
name: m,
help: metaItem?.help ?? '',
type: metaItem?.type ?? '',
};
}).concat(templates);
});

return Promise.resolve(result);
};

const getAllWithTemplates = () => {
const { withTemplates } = lpRef.current;
const result = withTemplates.map(t => ({
name: t.label,
help: t.comment || "",
value: t.value
}))

return Promise.resolve(result);
};
Expand All @@ -176,7 +186,14 @@ const MonacoQueryField = (props: Props) => {

const getLabelValues = (labelName: string) => lpRef.current.getLabelValues(labelName);

const dataProvider = { getSeries, getHistory, getAllMetricNames, getAllLabelNames, getLabelValues };
const dataProvider = {
getSeries,
getHistory,
getAllMetricNames,
getAllWithTemplates,
getAllLabelNames,
getLabelValues
};
const completionProvider = getCompletionProvider(monaco, dataProvider);

// completion-providers in monaco are not registered directly to editor-instances,
Expand Down

0 comments on commit 82cd75e

Please sign in to comment.