Skip to content

Commit

Permalink
fix: vertical view for secrets and filter credentials by label (#3392)
Browse files Browse the repository at this point in the history
Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com>
(cherry picked from commit 0a0f08a)
  • Loading branch information
Marvin9 authored and github-actions[bot] committed Jan 30, 2025
1 parent bfd3b74 commit d5a833d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 22 additions & 1 deletion internal/api/list_credentials_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"connectrpc.com/connect"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"sigs.k8s.io/controller-runtime/pkg/client"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
Expand All @@ -32,12 +34,31 @@ func (s *server) ListCredentials(
return nil, err
}

credsLabelSelector := labels.NewSelector()

credsLabelSelectorRequirement, err := labels.NewRequirement(
kargoapi.CredentialTypeLabelKey,
selection.In,
[]string{
kargoapi.CredentialTypeLabelValueGit,
kargoapi.CredentialTypeLabelValueHelm,
kargoapi.CredentialTypeLabelValueImage,
})

if err != nil {
return nil, err
}

Check warning on line 50 in internal/api/list_credentials_v1alpha1.go

View check run for this annotation

Codecov / codecov/patch

internal/api/list_credentials_v1alpha1.go#L37-L50

Added lines #L37 - L50 were not covered by tests

credsLabelSelector = credsLabelSelector.Add(*credsLabelSelectorRequirement)

Check warning on line 53 in internal/api/list_credentials_v1alpha1.go

View check run for this annotation

Codecov / codecov/patch

internal/api/list_credentials_v1alpha1.go#L52-L53

Added lines #L52 - L53 were not covered by tests
var secretsList corev1.SecretList
if err := s.client.List(
ctx,
&secretsList,
client.InNamespace(req.Msg.GetProject()),
client.HasLabels{kargoapi.CredentialTypeLabelKey},
&client.ListOptions{
LabelSelector: credsLabelSelector,
},

Check warning on line 61 in internal/api/list_credentials_v1alpha1.go

View check run for this annotation

Codecov / codecov/patch

internal/api/list_credentials_v1alpha1.go#L59-L61

Added lines #L59 - L61 were not covered by tests
); err != nil {
return nil, fmt.Errorf("list secrets: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions ui/src/features/project/credentials/credentials-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const CredentialsList = () => {

return (
<div className='p-4'>
<Flex gap={16}>
<Flex gap={16} vertical>
<Card
title={
<Flex align='center'>
Expand All @@ -73,14 +73,14 @@ export const CredentialsList = () => {
</Button>
</Flex>
}
className='w-1/2'
>
<Table
scroll={{ x: 'max-content' }}
key={specificCredentials.length}
dataSource={specificCredentials}
rowKey={(record: Secret) => record?.metadata?.name || ''}
loading={listCredentialsQuery.isLoading}
pagination={{ defaultPageSize: 5 }}
columns={[
{
title: 'Name',
Expand Down Expand Up @@ -208,7 +208,6 @@ export const CredentialsList = () => {
</Button>
</Flex>
}
className='w-1/2'
>
<Table
scroll={{ x: 'max-content' }}
Expand Down

0 comments on commit d5a833d

Please sign in to comment.