Skip to content

Commit

Permalink
MR Permissions - Group and Project dropdown issues (#3219)
Browse files Browse the repository at this point in the history
* saving work

* working fix

* addressed all comments except entry duplicates

* Updated the Tooltip

* fixed test to match new behaviour

* format

* comments

* comment2
  • Loading branch information
YuliaKrimerman committed Sep 20, 2024
1 parent 83730aa commit 83472f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ describe('MR Permissions', () => {

usersTab.findAddGroupButton().click();

groupTable.findNameSelect().fill('new-example-mr-group');
cy.findByText('Create "new-example-mr-group"').click();
// Type the group name into the input
groupTable.findNameSelect().type('new-example-mr-group');

// Wait for the dropdown to appear and select the option
cy.contains('new-example-mr-group', { timeout: 10000 }).should('be.visible').click();

groupTable.findSaveNewButton().click();

cy.wait('@addGroup').then((interception) => {
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/components/TypeaheadSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export interface TypeaheadSelectProps extends Omit<SelectProps, 'toggle' | 'onSe

const defaultNoOptionsFoundMessage = (filter: string) => `No results found for "${filter}"`;
const defaultCreateOptionMessage = (newValue: string) => `Create "${newValue}"`;

const defaultFilterFunction = (filterValue: string, options: TypeaheadSelectOption[]) =>
options.filter((o) => String(o.content).toLowerCase().includes(filterValue.toLowerCase()));

Expand Down Expand Up @@ -212,12 +211,10 @@ const TypeaheadSelect: React.FunctionComponent<TypeaheadSelectProps> = ({
const onInputClick = () => {
if (!isOpen) {
openMenu();
setTimeout(() => {
textInputRef.current?.focus();
}, 100);
} else if (isFiltering) {
closeMenu();
}
setTimeout(() => {
textInputRef.current?.focus();
}, 100);
};

const selectOption = (
Expand Down Expand Up @@ -401,6 +398,7 @@ const TypeaheadSelect: React.FunctionComponent<TypeaheadSelectProps> = ({
onSelect={handleSelect}
onOpenChange={(open) => !open && closeMenu()}
toggle={toggle}
shouldFocusFirstItemOnOpen={false}
ref={innerRef}
{...props}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ const RoleBindingPermissionsNameInput: React.FC<RoleBindingPermissionsNameInputP
const displayName = isProjectSubject ? namespaceToProjectDisplayName(option, projects) : option;
return { value: displayName, content: displayName };
});

if (value && !typeAhead.includes(value)) {
// If we've selected an option that doesn't exist via isCreatable, include it in the options so it remains selected
if (value && !selectOptions.some((option) => option.value === value)) {
selectOptions.push({ value, content: value });
}

return (
<TypeaheadSelect
selectOptions={selectOptions}
Expand All @@ -68,6 +67,7 @@ const RoleBindingPermissionsNameInput: React.FC<RoleBindingPermissionsNameInputP
}
}}
placeholder={placeholderText}
createOptionMessage={(newValue) => `Select "${newValue}"`}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ const RoleBindingPermissionsTableRow: React.FC<RoleBindingPermissionsTableRowPro
<Tooltip
content={
<div>
This group is created by default. You can add users to this group via the API.
This group is created by default. You can add users to this group in OpenShift
user management, or ask the cluster admin to do so.
</div>
}
>
Expand Down

0 comments on commit 83472f4

Please sign in to comment.