-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(asset): add variable query #71
Conversation
|
||
export type Props = QueryEditorProps<AssetDataSource, AssetQuery> | ||
|
||
export class AssetQueryEditorCommon { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of a strange implementation here. you are basically having a common class that you use in 2 places. You are also creating references to your methods from the datasource and components . I think a better solution here is to create a custom react hook and pass the methods in the components here needed.
|
||
readonly loadMinionIdOptions = (ids: SystemMetadata[] | void): Array<SelectableValue<string>> => { | ||
if (!ids) { | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are missing the endline ;
|
||
const onWorkspaceChange = (item?: SelectableValue<string>): void => { | ||
if (item?.value && item.value !== query.workspace) { | ||
// if workspace changed, reset Systems and Assets fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just remove all comments from this component
import { AssetQuery } from "../types"; | ||
import { FloatingError, parseErrorMessage } from "../../../core/errors"; | ||
|
||
export function AssetVariableQueryEditor(props: Props) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a description/summary to your component instead. Something like :
This component is going to be used to render Assets as part of Grafana Variables.
The following components will query for assets based by workspace and system
const render = setupRenderer(AssetVariableQueryEditor, FakeAssetDataSource); | ||
const workspacesLoaded = () => waitForElementToBeRemoved(screen.getByTestId('Spinner')); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra empty line
expect(screen.getByText('1')).toBeInTheDocument(); | ||
|
||
// User selects different workspace | ||
await select(screen.getAllByRole('combobox')[0], 'Default workspace', { container: document.body }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can test what happens when the call to the backend fails.
We should get a floating error right ?
conditions.push(`workspace = "${workspace}"`); | ||
} | ||
const assetFilter = conditions.join(' and '); | ||
const assetsResponse: AssetModel[] = await this.queryAssets(assetFilter, 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this we need to specify in the HLD and discuss with Josh. Should we query for 1000 assets here ? We also don't have projection here so it will eat up a lot of unnecessary resources both on client and on the backend
@@ -98,6 +99,22 @@ export class AssetDataSource extends DataSourceBase<AssetMetadataQuery> { | |||
} | |||
} | |||
|
|||
async metricFindQuery({ minionIds, workspace }: AssetQuery): Promise<MetricFindValue[]> { | |||
const conditions = []; | |||
if (minionIds?.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we'd probably want to implement a query builder using the builder pattern to reduce complexity
@TigranVardanyan I think here we'd need to get @joshuaprewitt feedback here to make sure that we are not building something that will eventually be rewritten to due missing/wrong requirements. Please add a more detailed explanation and provide some screenshots to highlight how this code change will affect the product in the PR description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting on feedback above to be addressed
@TigranVardanyan Putting this PR on hold until we have the new solution with the advanced query builder. I already have a draft PR for that |
This PR isn't needed anymore @TigranVardanyan please abandon it |
not actual |
Pull Request
π€¨ Rationale
Added variable query to Asset datasource
π©βπ» Implementation
π§ͺ Testing
β Checklist