Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/path-to-regexp-1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanahuckova authored Sep 26, 2024
2 parents 98533d7 + f34daa9 commit 08855ec
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
2 changes: 2 additions & 0 deletions pkg/github/client/errorsourcehandling.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var (
downstreamErrors = []string{
"Could not resolve to",
"Your token has not been granted the required scopes to execute this query",
"Resource protected by organization SAML enforcement. You must grant your Personal Access token access to this organization.",
"API rate limit exceeded",
}
)

Expand Down
14 changes: 13 additions & 1 deletion pkg/github/client/errorsourcehandling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ func TestAddErrorSourceToError(t *testing.T) {
name: "context canceled error",
err: context.Canceled,
resp: nil,
expected: errorsource.DownstreamError( context.Canceled, false),
expected: errorsource.DownstreamError(context.Canceled, false),
},
{
name: "saml error message",
err: errors.New("Resource protected by organization SAML enforcement. You must grant your Personal Access token access to this organization."),
resp: nil,
expected: errorsource.DownstreamError(errors.New("Resource protected by organization SAML enforcement. You must grant your Personal Access token access to this organization."), false),
},
{
name: "limit exceeded error message",
err: errors.New("API rate limit exceeded for ID 1"),
resp: nil,
expected: errorsource.DownstreamError(errors.New("API rate limit exceeded for ID 1"), false),
},
}

Expand Down
44 changes: 35 additions & 9 deletions src/views/QueryEditorPackages.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';

import { Input, Select, InlineField } from '@grafana/ui';
import { SelectableValue } from '@grafana/data';
Expand All @@ -10,14 +10,7 @@ interface Props extends PackagesOptions {
onChange: (value: PackagesOptions) => void;
}

export const DefaultPackageType = PackageType.NPM;

const packageTypeOptions: Array<SelectableValue<string>> = Object.keys(PackageType).map((v) => {
return {
label: v.replace('/_/gi', ' '),
value: v,
};
});
export const DefaultPackageType = PackageType.DOCKER;

const QueryEditorPackages = (props: Props) => {
const [names, setNames] = useState<string>(props.names || '');
Expand All @@ -32,6 +25,39 @@ const QueryEditorPackages = (props: Props) => {
}
}, [props]);

const packageTypeOptions = useMemo(() => {
// @TODO: These package types are not supported through GraphQL endpoint that we are using in our queries.
// We should remove them from the list of options, but for now we will just ignore them
// and not show them in the dropdown, if they have not been selected before.
// Not sure if they ever been supported.
const notSupportedTroughGraphQL: string[] = [PackageType.NPM, PackageType.RUBYGEMS, PackageType.NUGET];
const packageTypeOptions: SelectableValue[] = Object.values(PackageType)
.filter((packageType) => {
// Filter out package types that are not supported through GraphQL
return !notSupportedTroughGraphQL.includes(packageType);
})
.map((v) => {
return {
label: v.replace('/_/gi', ' '),
value: v,
};
});

// If user has selected a package type that is not in the list of options, add it to the list
if (props.packageType) {
const selectedPackageType = packageTypeOptions.find((opt: SelectableValue) => opt.value === props.packageType);
if (!selectedPackageType) {
packageTypeOptions.push({
label: props.packageType.replace('/_/gi', ' '),
value: props.packageType,
});
}
}
return packageTypeOptions;
// We want to run this only once when component is mounted and not every time packageType is changed
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<>
<InlineField labelWidth={LeftColumnWidth * 2} label="Package type">
Expand Down

0 comments on commit 08855ec

Please sign in to comment.