Skip to content

Commit

Permalink
fix: ADDON-64637 add input value to query for menu navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsvetkov-splunk committed Sep 11, 2023
1 parent 664fb7c commit 3ca0c43
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions ui/src/main/webapp/components/MenuInput.jsx
Expand Up @@ -49,8 +49,8 @@ function MenuInput({ handleRequestOpen }) {
};

const handleChangeCustomMenu = (val) => {
const { service } = val;
handleRequestOpen(service);
const { service, input } = val;
handleRequestOpen({ serviceName: service, input });
};

const getMenuItems = (serviceItems, groupName) =>
Expand All @@ -70,7 +70,7 @@ function MenuInput({ handleRequestOpen }) {
<Menu.Item
key={service.name}
onClick={() => {
handleRequestOpen(service.name, groupName);
handleRequestOpen({ serviceName: service.name, groupName });
setIsSubMenu(false);
}}
>
Expand Down Expand Up @@ -171,7 +171,7 @@ function MenuInput({ handleRequestOpen }) {
appearance="primary"
id="addInputBtn"
onClick={() => {
handleRequestOpen(services[0].name);
handleRequestOpen({ serviceName: services[0].name });
}}
/>
);
Expand Down
15 changes: 9 additions & 6 deletions ui/src/main/webapp/components/MenuInput.test.jsx
Expand Up @@ -61,7 +61,7 @@ describe('single service', () => {

await userEvent.click(createButton);

expect(mockHandleRequestOpen).toHaveBeenCalledWith('test-service-name');
expect(mockHandleRequestOpen).toHaveBeenCalledWith({ serviceName: 'test-service-name' });
});
});

Expand Down Expand Up @@ -105,7 +105,10 @@ describe('multiple services', () => {
const { mockHandleRequestOpen } = setup({ services: getTwoServices() });
await userEvent.click(getCreateDropdown());
await userEvent.click(screen.getByText('test-service-title2'));
expect(mockHandleRequestOpen).toHaveBeenCalledWith('test-service-name2', 'main_panel');
expect(mockHandleRequestOpen).toHaveBeenCalledWith({
groupName: 'main_panel',
serviceName: 'test-service-name2',
});
});

describe('groups', () => {
Expand Down Expand Up @@ -190,10 +193,10 @@ describe('multiple services', () => {
await userEvent.click(screen.getByText('test-group-title1'));
await userEvent.click(screen.getByText('test-subservice1-title1'));

expect(mockHandleRequestOpen).toHaveBeenCalledWith(
'test-subservice1-name1',
'test-group-name1'
);
expect(mockHandleRequestOpen).toHaveBeenCalledWith({
groupName: 'test-group-name1',
serviceName: 'test-subservice1-name1',
});
});
});

Expand Down
7 changes: 6 additions & 1 deletion ui/src/main/webapp/pages/Input/InputPage.jsx
Expand Up @@ -100,7 +100,7 @@ function InputPage() {
};

// handle modal/page open request on create/add entity button
const handleRequestOpen = (serviceName, groupName) => {
const handleRequestOpen = ({ serviceName, groupName, input }) => {
const service = services.find((x) => x.name === serviceName);
const serviceTitle = service.title;
const isInputPageStyle = service.style === STYLE_PAGE;
Expand All @@ -118,6 +118,11 @@ function InputPage() {
// set query and push to navigate
query.set('service', serviceName);
query.set('action', MODE_CREATE);
if (input) {
query.set('input', input);
} else {
query.delete('input');
}
navigate({ search: query.toString() });
}
};
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/webapp/pages/Input/InputPage.test.jsx
Expand Up @@ -40,6 +40,6 @@ it('should redirect user on menu click', async () => {

// check that InputPage redirects to correct URL according to callback
expect(mockNavigateFn).toHaveBeenCalledWith({
search: `service=${service}&action=${action}`,
search: `service=${service}&action=${action}&input=${input}`,
});
});

0 comments on commit 3ca0c43

Please sign in to comment.