Skip to content

Commit

Permalink
[AAP-22997] Update credential filter (#2290)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalis authored May 23, 2024
1 parent f0f38da commit 53cfc1e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import { useSelectCredentials } from '../hooks/useSelectCredentials';
export function PageFormCredentialSelect<
TFieldValues extends FieldValues = FieldValues,
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>(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 (
<PageFormMultiInput<EdaCredential>
Expand Down
20 changes: 15 additions & 5 deletions frontend/eda/access/credentials/hooks/useSelectCredentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -16,11 +16,11 @@ export function useSelectCredentials(credentialKind?: string, title?: string) {
<SelectEdaCredentials
title={t(title ? title : 'Select credential')}
onSelect={onSelect}
credentialKind={credentialKind}
credentialKinds={credentialKinds}
/>
);
},
[credentialKind, setDialog, t, title]
[credentialKinds, setDialog, t, title]
);
return openSelectCredentials;
}
Expand All @@ -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<EdaCredential>({
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,
});
Expand Down
15 changes: 15 additions & 0 deletions frontend/eda/rulebook-activations/RulebookActivationForm.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,19 @@ describe('Create rulebook activation ', () => {
});
});
});

it('Should use kind_in filter for credentials', () => {
cy.mount(<CreateRulebookActivation />);
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');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export function RulebookActivationInputs() {
/>
<PageFormCredentialSelect<{ credential_refs: string; id: string; credentialKind: string }>
name="credential_refs"
credentialKind={'vault, cloud'}
credentialKinds={['vault,cloud']}
labelHelp={t(`Select the credentials for this rulebook activation.`)}
/>
<PageFormSelect<IEdaRulebookActivationInputs>
Expand Down

0 comments on commit 53cfc1e

Please sign in to comment.