From 2634f6ca89294698d7f7f1ca068f979ce2bab05a Mon Sep 17 00:00:00 2001 From: MartinBelton-gov <111495215+MartinBelton-gov@users.noreply.github.com> Date: Thu, 11 Jan 2024 13:26:55 +0000 Subject: [PATCH] Enabled Costs to be retrieved by just subscription and or resource (#11) * Used queryText to get information by resource id * Added onBlur Handler * Added New Line --- dfe-azurecostbackend-datasource/package.json | 2 +- .../pkg/plugin/datasource.go | 23 ++++-- .../pkg/plugin/datasource_test.go | 10 +-- .../src/components/ConfigEditor.js | 40 +++++++++-- .../src/components/ConfigEditor.js.map | 2 +- .../src/components/ConfigEditor.tsx | 71 +++++++++++++++---- .../src/components/QueryEditor.js | 8 ++- .../src/components/QueryEditor.js.map | 2 +- .../src/components/QueryEditor.tsx | 13 ++-- 9 files changed, 130 insertions(+), 41 deletions(-) diff --git a/dfe-azurecostbackend-datasource/package.json b/dfe-azurecostbackend-datasource/package.json index d895cff..71619c2 100644 --- a/dfe-azurecostbackend-datasource/package.json +++ b/dfe-azurecostbackend-datasource/package.json @@ -1,7 +1,7 @@ { "id": "1", "name": "azurecost-backend", - "version": "1.0.2", + "version": "1.0.3", "description": "Azure cost backend", "scripts": { "build": "webpack -c ./.config/webpack/webpack.config.ts --env production", diff --git a/dfe-azurecostbackend-datasource/pkg/plugin/datasource.go b/dfe-azurecostbackend-datasource/pkg/plugin/datasource.go index f5026ae..83e4dbc 100644 --- a/dfe-azurecostbackend-datasource/pkg/plugin/datasource.go +++ b/dfe-azurecostbackend-datasource/pkg/plugin/datasource.go @@ -193,7 +193,10 @@ func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataReques return response, nil } -type queryModel struct{} +type queryModel struct { + QueryText string `json:"queryText"` + Constant float64 `json:"constant"` +} func (d *Datasource) query(_ context.Context, pCtx backend.PluginContext, query backend.DataQuery) backend.DataResponse { var response backend.DataResponse @@ -214,6 +217,7 @@ func (d *Datasource) query(_ context.Context, pCtx backend.PluginContext, query //MAB Added log.Print("Starting Datasource") log.Println("URL:", d.config.AzureCostSubscriptionUrl) + log.Println("ResourceId:", qm.QueryText) // Call the fetchToken function token, err := fetchToken(d.config) @@ -228,12 +232,12 @@ func (d *Datasource) query(_ context.Context, pCtx backend.PluginContext, query start, end := getCurrentYearDates() timeRange := query.TimeRange - if !timeRange.From.IsZero() && !timeRange.To.IsZero(){ + if !timeRange.From.IsZero() && !timeRange.To.IsZero() { start = timeRange.From.Format("2006-01-02") - end = timeRange.To.Format("2006-01-02") + end = timeRange.To.Format("2006-01-02") } - costs, err := getCosts(token, d.config, start, end) + costs, err := getCosts(token, d.config, start, end, qm.QueryText) if err != nil { log.Println("Error getting costs:", err) return response @@ -373,9 +377,15 @@ func parseAccessToken(body []byte) (string, error) { } // Fetch Costs -func getCosts(token string, config Config, start string, end string) (CostResponse, error) { +func getCosts(token string, config Config, start string, end string, resourceid string) (CostResponse, error) { url := config.SubscriptionID + "/providers/Microsoft.CostManagement/query?api-version=2023-03-01" + if len(resourceid) > 2 { + url = config.SubscriptionID + "/resourceGroups/" + resourceid + "/providers/Microsoft.CostManagement/query?api-version=2023-03-01" + } + + log.Println("CostUrl:", url) + bodyParameters := map[string]interface{}{ "type": "Usage", "timeframe": "Custom", @@ -495,5 +505,4 @@ func getCurrentYearDates() (string, string) { thirtyFirstOfDecemberFormatted := thirtyFirstOfDecember.Format("2006-01-02") return firstOfJanuaryFormatted, thirtyFirstOfDecemberFormatted -} - +} \ No newline at end of file diff --git a/dfe-azurecostbackend-datasource/pkg/plugin/datasource_test.go b/dfe-azurecostbackend-datasource/pkg/plugin/datasource_test.go index 9a27b15..3f0f3bd 100644 --- a/dfe-azurecostbackend-datasource/pkg/plugin/datasource_test.go +++ b/dfe-azurecostbackend-datasource/pkg/plugin/datasource_test.go @@ -4,6 +4,7 @@ import ( "context" "net/http" "net/http/httptest" + "strconv" "testing" "time" "encoding/json" @@ -145,7 +146,7 @@ func TestGetCosts(t *testing.T) { token := "your-mock-token" config.TokenURL = server.URL start, end := getCurrentYearDates() - costs, err := getCosts(token, config, start, end) + costs, err := getCosts(token, config, start, end, "resourceid") if err != nil { t.Errorf("Expected no error, got %v", err) } @@ -204,8 +205,8 @@ func TestGetCurrentYearDates(t *testing.T) { firstOfJanuary, thirtyFirstOfDecember := getCurrentYearDates() // Expected results for the mock date - expectedFirstOfJanuary := "2023-01-01" - expectedThirtyFirstOfDecember := "2023-12-31" + expectedFirstOfJanuary := strconv.Itoa(time.Now().Year()) + "-01-01" + expectedThirtyFirstOfDecember := strconv.Itoa(time.Now().Year()) + "-12-31" // Check if the actual results match the expected results if firstOfJanuary != expectedFirstOfJanuary { @@ -215,5 +216,4 @@ func TestGetCurrentYearDates(t *testing.T) { if thirtyFirstOfDecember != expectedThirtyFirstOfDecember { t.Errorf("Thirty-First of December: expected %s, got %s", expectedThirtyFirstOfDecember, thirtyFirstOfDecember) } -} - +} \ No newline at end of file diff --git a/dfe-azurecostbackend-datasource/src/components/ConfigEditor.js b/dfe-azurecostbackend-datasource/src/components/ConfigEditor.js index 3330d2c..aef4b2f 100644 --- a/dfe-azurecostbackend-datasource/src/components/ConfigEditor.js +++ b/dfe-azurecostbackend-datasource/src/components/ConfigEditor.js @@ -7,6 +7,14 @@ export function ConfigEditor(props) { Password: event.target.value, } })); }; + const onPasswordBlur = (event) => { + updatePassword(event.target.value); + }; + const updatePassword = (newPassword) => { + onOptionsChange(Object.assign(Object.assign({}, options), { secureJsonData: { + Password: newPassword, + } })); + }; const onResetPasswordKey = () => { onOptionsChange(Object.assign(Object.assign({}, options), { secureJsonFields: Object.assign(Object.assign({}, options.secureJsonFields), { Password: false }), secureJsonData: Object.assign(Object.assign({}, options.secureJsonData), { Password: '' }) })); }; @@ -15,6 +23,14 @@ export function ConfigEditor(props) { ClientID: event.target.value, } })); }; + const onClientIDKeyBlur = (event) => { + updateonClientIDKey(event.target.value); + }; + const updateonClientIDKey = (itemupdate) => { + onOptionsChange(Object.assign(Object.assign({}, options), { secureJsonData: { + ClientID: itemupdate, + } })); + }; const onResetClientIDKey = () => { onOptionsChange(Object.assign(Object.assign({}, options), { secureJsonFields: Object.assign(Object.assign({}, options.secureJsonFields), { ClientID: false }), secureJsonData: Object.assign(Object.assign({}, options.secureJsonData), { ClientID: '' }) })); }; @@ -23,6 +39,14 @@ export function ConfigEditor(props) { TenantID: event.target.value, } })); }; + const onTenantIDKeyBlur = (event) => { + updateonTenantIDKey(event.target.value); + }; + const updateonTenantIDKey = (itemupdate) => { + onOptionsChange(Object.assign(Object.assign({}, options), { secureJsonData: { + TenantID: itemupdate, + } })); + }; const onResetTenantIDKey = () => { onOptionsChange(Object.assign(Object.assign({}, options), { secureJsonFields: Object.assign(Object.assign({}, options.secureJsonFields), { TenantID: false }), secureJsonData: Object.assign(Object.assign({}, options.secureJsonData), { TenantID: '' }) })); }; @@ -31,6 +55,14 @@ export function ConfigEditor(props) { SubscriptionID: event.target.value, } })); }; + const onSubscriptionIDKeyBlur = (event) => { + updateonSubscriptionIDKey(event.target.value); + }; + const updateonSubscriptionIDKey = (itemupdate) => { + onOptionsChange(Object.assign(Object.assign({}, options), { secureJsonData: { + SubscriptionID: itemupdate, + } })); + }; const onResetSubscriptionIDKey = () => { onOptionsChange(Object.assign(Object.assign({}, options), { secureJsonFields: Object.assign(Object.assign({}, options.secureJsonFields), { SubscriptionID: false }), secureJsonData: Object.assign(Object.assign({}, options.secureJsonData), { SubscriptionID: '' }) })); }; @@ -47,13 +79,13 @@ export function ConfigEditor(props) { const secureJsonData = (options.secureJsonData || {}); return (React.createElement("div", { className: "gf-form-group" }, React.createElement(InlineField, { label: "Password / Client Secret", labelWidth: 27 }, - React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.Password), value: secureJsonData.Password || '', placeholder: "secure Password / Client Secret (backend only)", width: 100, onReset: onResetPasswordKey, onChange: onPasswordKeyChange })), + React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.Password), value: secureJsonData.Password || '', placeholder: "secure Password / Client Secret (backend only)", width: 100, onReset: onResetPasswordKey, onChange: onPasswordKeyChange, onBlur: onPasswordBlur })), React.createElement(InlineField, { label: "ClientID", labelWidth: 12 }, - React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.ClientID), value: secureJsonData.ClientID || '', placeholder: "secure Client ID (backend only)", width: 100, onReset: onResetClientIDKey, onChange: onClientIDKeyChange })), + React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.ClientID), value: secureJsonData.ClientID || '', placeholder: "secure Client ID (backend only)", width: 100, onReset: onResetClientIDKey, onChange: onClientIDKeyChange, onBlur: onClientIDKeyBlur })), React.createElement(InlineField, { label: "TenantID", labelWidth: 12 }, - React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.TenantID), value: secureJsonData.TenantID || '', placeholder: "secure Tenant ID (backend only)", width: 60, onReset: onResetTenantIDKey, onChange: onTenantIDKeyChange })), + React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.TenantID), value: secureJsonData.TenantID || '', placeholder: "secure Tenant ID (backend only)", width: 60, onReset: onResetTenantIDKey, onChange: onTenantIDKeyChange, onBlur: onTenantIDKeyBlur })), React.createElement(InlineField, { label: "SubscriptionID", labelWidth: 17 }, - React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.SubscriptionID), value: secureJsonData.SubscriptionID || '', placeholder: "secure Subscription ID (backend only)", width: 100, onReset: onResetSubscriptionIDKey, onChange: onSubscriptionIDKeyChange })), + React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.SubscriptionID), value: secureJsonData.SubscriptionID || '', placeholder: "secure Subscription ID (backend only)", width: 100, onReset: onResetSubscriptionIDKey, onChange: onSubscriptionIDKeyChange, onBlur: onSubscriptionIDKeyBlur })), React.createElement(InlineField, { label: "Region", labelWidth: 12 }, React.createElement(SecretInput, { isConfigured: (secureJsonFields && secureJsonFields.Region), value: secureJsonData.Region || '', placeholder: "secure Region (backend only)", width: 100, onReset: onResetRegionKey, onChange: onRegionKeyChange })))); } diff --git a/dfe-azurecostbackend-datasource/src/components/ConfigEditor.js.map b/dfe-azurecostbackend-datasource/src/components/ConfigEditor.js.map index 8221a95..d0db35f 100644 --- a/dfe-azurecostbackend-datasource/src/components/ConfigEditor.js.map +++ b/dfe-azurecostbackend-datasource/src/components/ConfigEditor.js.map @@ -1 +1 @@ -{"version":3,"file":"ConfigEditor.js","sourceRoot":"","sources":["ConfigEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAMvD,MAAM,UAAU,YAAY,CAAC,KAAY;IACvC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAE3C,MAAM,mBAAmB,GAAG,CAAC,KAAoC,EAAE,EAAE;QACnE,eAAe,iCACV,OAAO,KACV,cAAc,EAAE;gBACd,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK;aAC7B,IACD,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,kBAAkB,GAAG,GAAG,EAAE;QAC9B,eAAe,iCACV,OAAO,KACV,gBAAgB,kCACX,OAAO,CAAC,gBAAgB,KAC3B,QAAQ,EAAE,KAAK,KAEjB,cAAc,kCACT,OAAO,CAAC,cAAc,KACzB,QAAQ,EAAE,EAAE,OAEd,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,mBAAmB,GAAG,CAAC,KAAoC,EAAE,EAAE;QACnE,eAAe,iCACV,OAAO,KACV,cAAc,EAAE;gBACd,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK;aAC7B,IACD,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,kBAAkB,GAAG,GAAG,EAAE;QAC9B,eAAe,iCACV,OAAO,KACV,gBAAgB,kCACX,OAAO,CAAC,gBAAgB,KAC3B,QAAQ,EAAE,KAAK,KAEjB,cAAc,kCACT,OAAO,CAAC,cAAc,KACzB,QAAQ,EAAE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,EAAE,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,QAAQ,CAAY,EACxE,KAAK,EAAE,cAAc,CAAC,QAAQ,IAAI,EAAE,EACpC,WAAW,EAAC,iCAAiC,EAC7C,KAAK,EAAE,EAAE,EACT,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,EAAE,iBAAiB,GACzB,CACU;QACd,oBAAC,WAAW,IAAC,KAAK,EAAC,gBAAgB,EAAC,UAAU,EAAE,EAAE;YAChD,oBAAC,WAAW,IACV,YAAY,EAAE,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,cAAc,CAAY,EAC9E,KAAK,EAAE,cAAc,CAAC,cAAc,IAAI,EAAE,EAC1C,WAAW,EAAC,uCAAuC,EACnD,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,wBAAwB,EACjC,QAAQ,EAAE,yBAAyB,EACnC,MAAM,EAAE,uBAAuB,GAC/B,CACU;QACd,oBAAC,WAAW,IAAC,KAAK,EAAC,QAAQ,EAAC,UAAU,EAAE,EAAE;YACxC,oBAAC,WAAW,IACV,YAAY,EAAE,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,CAAY,EACtE,KAAK,EAAE,cAAc,CAAC,MAAM,IAAI,EAAE,EAClC,WAAW,EAAC,8BAA8B,EAC1C,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,iBAAiB,GAC3B,CACU,CACV,CACP,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/dfe-azurecostbackend-datasource/src/components/ConfigEditor.tsx b/dfe-azurecostbackend-datasource/src/components/ConfigEditor.tsx index 2225b73..c5ba498 100644 --- a/dfe-azurecostbackend-datasource/src/components/ConfigEditor.tsx +++ b/dfe-azurecostbackend-datasource/src/components/ConfigEditor.tsx @@ -9,17 +9,27 @@ export function ConfigEditor(props: Props) { const { onOptionsChange, options } = props; const onPasswordKeyChange = (event: React.KeyboardEvent) => { - if (event.key === 'Enter' || event.type === 'blur') { - // Save the value on Enter key press onOptionsChange({ ...options, secureJsonData: { Password: (event.target as HTMLInputElement).value, }, }); - } }; + const onPasswordBlur = (event: React.FocusEvent) => { + updatePassword(event.target.value); + }; + + const updatePassword = (newPassword: string) => { + onOptionsChange({ + ...options, + secureJsonData: { + Password: newPassword, + }, + }); + }; + const onResetPasswordKey = () => { onOptionsChange({ ...options, @@ -35,15 +45,25 @@ export function ConfigEditor(props: Props) { }; const onClientIDKeyChange = (event: React.KeyboardEvent) => { - if (event.key === 'Enter' || event.type === 'blur') { - // Save the value on Enter key press onOptionsChange({ ...options, secureJsonData: { ClientID: (event.target as HTMLInputElement).value, }, }); - } + }; + + const onClientIDKeyBlur = (event: React.FocusEvent) => { + updateonClientIDKey(event.target.value); + }; + + const updateonClientIDKey = (itemupdate: string) => { + onOptionsChange({ + ...options, + secureJsonData: { + ClientID: itemupdate, + }, + }); }; const onResetClientIDKey = () => { @@ -61,15 +81,25 @@ export function ConfigEditor(props: Props) { }; const onTenantIDKeyChange = (event: React.KeyboardEvent) => { - if (event.key === 'Enter' || event.type === 'blur') { - // Save the value on Enter key press onOptionsChange({ ...options, secureJsonData: { TenantID: (event.target as HTMLInputElement).value, }, }); - } + }; + + const onTenantIDKeyBlur = (event: React.FocusEvent) => { + updateonTenantIDKey(event.target.value); + }; + + const updateonTenantIDKey = (itemupdate: string) => { + onOptionsChange({ + ...options, + secureJsonData: { + TenantID: itemupdate, + }, + }); }; const onResetTenantIDKey = () => { @@ -87,15 +117,25 @@ export function ConfigEditor(props: Props) { }; const onSubscriptionIDKeyChange = (event: React.KeyboardEvent) => { - if (event.key === 'Enter' || event.type === 'blur') { - // Save the value on Enter key press onOptionsChange({ ...options, secureJsonData: { SubscriptionID: (event.target as HTMLInputElement).value, }, }); - } + }; + + const onSubscriptionIDKeyBlur = (event: React.FocusEvent) => { + updateonSubscriptionIDKey(event.target.value); + }; + + const updateonSubscriptionIDKey = (itemupdate: string) => { + onOptionsChange({ + ...options, + secureJsonData: { + SubscriptionID: itemupdate, + }, + }); }; const onResetSubscriptionIDKey = () => { @@ -113,15 +153,12 @@ export function ConfigEditor(props: Props) { }; const onRegionKeyChange = (event: React.KeyboardEvent) => { - if (event.key === 'Enter' || event.type === 'blur') { - // Save the value on Enter key press onOptionsChange({ ...options, secureJsonData: { Region: (event.target as HTMLInputElement).value, }, }); - } }; const onResetRegionKey = () => { @@ -153,6 +190,7 @@ export function ConfigEditor(props: Props) { width={100} onReset={onResetPasswordKey} onChange={onPasswordKeyChange} + onBlur={onPasswordBlur} /> @@ -163,6 +201,7 @@ export function ConfigEditor(props: Props) { width={100} onReset={onResetClientIDKey} onChange={onClientIDKeyChange} + onBlur={onClientIDKeyBlur} /> @@ -173,6 +212,7 @@ export function ConfigEditor(props: Props) { width={60} onReset={onResetTenantIDKey} onChange={onTenantIDKeyChange} + onBlur={onTenantIDKeyBlur} /> @@ -183,6 +223,7 @@ export function ConfigEditor(props: Props) { width={100} onReset={onResetSubscriptionIDKey} onChange={onSubscriptionIDKeyChange} + onBlur={onSubscriptionIDKeyBlur} /> diff --git a/dfe-azurecostbackend-datasource/src/components/QueryEditor.js b/dfe-azurecostbackend-datasource/src/components/QueryEditor.js index fa3de7a..f3b833f 100644 --- a/dfe-azurecostbackend-datasource/src/components/QueryEditor.js +++ b/dfe-azurecostbackend-datasource/src/components/QueryEditor.js @@ -3,6 +3,8 @@ import { InlineField, Input } from '@grafana/ui'; export function QueryEditor({ query, onChange, onRunQuery }) { const onQueryTextChange = (event) => { onChange(Object.assign(Object.assign({}, query), { queryText: event.target.value })); + // executes the query + onRunQuery(); }; const onConstantChange = (event) => { onChange(Object.assign(Object.assign({}, query), { constant: parseFloat(event.target.value) })); @@ -11,9 +13,9 @@ export function QueryEditor({ query, onChange, onRunQuery }) { }; const { queryText, constant } = query; return (React.createElement("div", { className: "gf-form" }, - React.createElement(InlineField, { label: "Constant" }, - React.createElement(Input, { onChange: onConstantChange, value: constant, width: 8, type: "number", step: "0.1" })), - React.createElement(InlineField, { label: "Query Text", labelWidth: 16, tooltip: "Not used yet" }, + false && (React.createElement(InlineField, { label: "Constant" }, + React.createElement(Input, { onChange: onConstantChange, value: constant, width: 8, type: "number", step: "0.1" }))), + React.createElement(InlineField, { label: "Azure Reource Id", labelWidth: 26, tooltip: "Reource Id" }, React.createElement(Input, { onChange: onQueryTextChange, value: queryText || '' })))); } //# sourceMappingURL=QueryEditor.js.map diff --git a/dfe-azurecostbackend-datasource/src/components/QueryEditor.js.map b/dfe-azurecostbackend-datasource/src/components/QueryEditor.js.map index adab40f..f353eb5 100644 --- a/dfe-azurecostbackend-datasource/src/components/QueryEditor.js.map +++ b/dfe-azurecostbackend-datasource/src/components/QueryEditor.js.map @@ -1 +1 @@ -{"version":3,"file":"QueryEditor.js","sourceRoot":"","sources":["QueryEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAOjD,MAAM,UAAU,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAS;IAChE,MAAM,iBAAiB,GAAG,CAAC,KAAoC,EAAE,EAAE;QACjE,QAAQ,iCAAM,KAAK,KAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAG,CAAC;IACxD,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,CAAC,KAAoC,EAAE,EAAE;QAChE,QAAQ,iCAAM,KAAK,KAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAG,CAAC;QACjE,qBAAqB;QACrB,UAAU,EAAE,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAEtC,OAAO,CACL,6BAAK,SAAS,EAAC,SAAS;QACtB,oBAAC,WAAW,IAAC,KAAK,EAAC,UAAU;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AAE,gBAAgB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,KAAK,GAAG,CAC7E,CACf;QAED,oBAAC,WAAW,IAAC,KAAK,EAAC,kBAAkB,EAAC,UAAU,EAAE,EAAE,EAAE,OAAO,EAAC,YAAY;YACxE,oBAAC,KAAK,IAAC,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAI,CAClD,CACV,CACP,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/dfe-azurecostbackend-datasource/src/components/QueryEditor.tsx b/dfe-azurecostbackend-datasource/src/components/QueryEditor.tsx index 0348c27..90307bb 100644 --- a/dfe-azurecostbackend-datasource/src/components/QueryEditor.tsx +++ b/dfe-azurecostbackend-datasource/src/components/QueryEditor.tsx @@ -9,6 +9,8 @@ type Props = QueryEditorProps; export function QueryEditor({ query, onChange, onRunQuery }: Props) { const onQueryTextChange = (event: ChangeEvent) => { onChange({ ...query, queryText: event.target.value }); + // executes the query + onRunQuery(); }; const onConstantChange = (event: ChangeEvent) => { @@ -21,10 +23,13 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) { return (
- - - - + {false && ( + + + + )} + +