From 53cfc1eb33f7de9ce91eb2080e313484bad89daa Mon Sep 17 00:00:00 2001 From: lgalis Date: Thu, 23 May 2024 17:28:00 -0400 Subject: [PATCH] [AAP-22997] Update credential filter (#2290) --- .../components/PageFormCredentialsSelect.tsx | 9 +++++++-- .../hooks/useSelectCredentials.tsx | 20 ++++++++++++++----- .../RulebookActivationForm.cy.tsx | 15 ++++++++++++++ .../RulebookActivationForm.tsx | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/frontend/eda/access/credentials/components/PageFormCredentialsSelect.tsx b/frontend/eda/access/credentials/components/PageFormCredentialsSelect.tsx index 094187261e..7f9296b703 100644 --- a/frontend/eda/access/credentials/components/PageFormCredentialsSelect.tsx +++ b/frontend/eda/access/credentials/components/PageFormCredentialsSelect.tsx @@ -7,9 +7,14 @@ import { useSelectCredentials } from '../hooks/useSelectCredentials'; export function PageFormCredentialSelect< TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath = FieldPath, ->(props: { name: TFieldName; labelHelp: string; isRequired?: boolean; credentialKind?: string }) { +>(props: { + name: TFieldName; + labelHelp: string; + isRequired?: boolean; + credentialKinds?: string[]; +}) { const { t } = useTranslation(); - const selectCredential = useSelectCredentials(props.credentialKind); + const selectCredential = useSelectCredentials(props.credentialKinds); return ( diff --git a/frontend/eda/access/credentials/hooks/useSelectCredentials.tsx b/frontend/eda/access/credentials/hooks/useSelectCredentials.tsx index 770914af20..289db78bf1 100644 --- a/frontend/eda/access/credentials/hooks/useSelectCredentials.tsx +++ b/frontend/eda/access/credentials/hooks/useSelectCredentials.tsx @@ -7,7 +7,7 @@ import { EdaCredential } from '../../../interfaces/EdaCredential'; import { useEdaView } from '../../../common/useEventDrivenView'; import { MultiSelectDialog, usePageDialog } from '../../../../../framework'; -export function useSelectCredentials(credentialKind?: string, title?: string) { +export function useSelectCredentials(credentialKinds?: string[], title?: string) { const [_, setDialog] = usePageDialog(); const { t } = useTranslation(); const openSelectCredentials = useCallback( @@ -16,11 +16,11 @@ export function useSelectCredentials(credentialKind?: string, title?: string) { ); }, - [credentialKind, setDialog, t, title] + [credentialKinds, setDialog, t, title] ); return openSelectCredentials; } @@ -29,13 +29,23 @@ function SelectEdaCredentials(props: { title: string; onSelect: (credentials: EdaCredential[]) => void; defaultEdaCredential?: EdaCredential; - credentialKind?: string; + credentialKinds?: string[]; }) { const toolbarFilters = useCredentialFilters(); const tableColumns = useCredentialColumns(); const view = useEdaView({ - url: edaAPI`/eda-credentials/?credential_type__kind=vault&credential_type__kind=cloud&page_size=300`, + url: edaAPI`/eda-credentials/`, toolbarFilters, + viewPerPage: 300, + ...(props.credentialKinds && + props.credentialKinds?.length > 0 && { + queryParams: { + credential_type__kind__in: + props.credentialKinds.length === 1 + ? props.credentialKinds[0] + : props.credentialKinds.join(','), + }, + }), tableColumns: tableColumns, disableQueryString: true, }); diff --git a/frontend/eda/rulebook-activations/RulebookActivationForm.cy.tsx b/frontend/eda/rulebook-activations/RulebookActivationForm.cy.tsx index 4ab1bcb658..ef7227cb31 100644 --- a/frontend/eda/rulebook-activations/RulebookActivationForm.cy.tsx +++ b/frontend/eda/rulebook-activations/RulebookActivationForm.cy.tsx @@ -85,4 +85,19 @@ describe('Create rulebook activation ', () => { }); }); }); + + it('Should use kind_in filter for credentials', () => { + cy.mount(); + cy.get('[data-cy="name"]').type('Test'); + cy.selectDropdownOptionByResourceName('decision-environment-id', 'EDA Decision Environment 3'); + cy.selectDropdownOptionByResourceName('project-id', 'Project 4'); + cy.selectDropdownOptionByResourceName('rulebook', 'hello_echo.yml'); + cy.get('[data-cy="organization_id"]').click(); + cy.get('#organization-2 > .pf-v5-c-menu__item-main > .pf-v5-c-menu__item-text').click(); + cy.get('.pf-v5-c-input-group > .pf-v5-c-button').click(); + + cy.intercept('GET', edaAPI`/eda-credentials/`, (req) => { + expect(req.url).to.contain('credential_type__kind__in=vault%2Ccloud'); + }); + }); }); diff --git a/frontend/eda/rulebook-activations/RulebookActivationForm.tsx b/frontend/eda/rulebook-activations/RulebookActivationForm.tsx index f252aaf9c3..67695fc297 100644 --- a/frontend/eda/rulebook-activations/RulebookActivationForm.tsx +++ b/frontend/eda/rulebook-activations/RulebookActivationForm.tsx @@ -233,7 +233,7 @@ export function RulebookActivationInputs() { /> name="credential_refs" - credentialKind={'vault, cloud'} + credentialKinds={['vault,cloud']} labelHelp={t(`Select the credentials for this rulebook activation.`)} />