Skip to content

Commit

Permalink
Merge branch 'master' into fix/block-empty-dir-inplace-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
moesterheld authored Nov 14, 2024
2 parents 1875488 + b88223a commit 0610681
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 18 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/issue-20899.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "fixed"
message = "Fix handling of path prefix in `useSendTelemetry`."

issues = ["20899"]
pulls = ["20909"]
4 changes: 4 additions & 0 deletions changelog/unreleased/pr-20910.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type = "fixed"
message = "Fixing replay search routes when path prefix is present."

pulls = ["20910"]
6 changes: 3 additions & 3 deletions graylog2-web-interface/docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1892,9 +1892,9 @@ http-parser-js@>=0.5.1:
integrity sha512-vDlkRPDJn93swjcjqMSaGSPABbIarsr1TLAui/gLDXzV5VsJNdXNzMYDyNBLQkjWQCJ1uizu8T2oDMhmGt0PRA==

http-proxy-middleware@^2.0.3:
version "2.0.6"
resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.6.tgz#e1a4dd6979572c7ab5a4e4b55095d1f32a74963f"
integrity sha512-ya/UeJ6HVBYxrgYotAZo1KvPWlgB48kUJLDePFeneHsVujFaW5WNj2NgWCAE//B1Dl02BIfYlpNgBy8Kf8Rjmw==
version "2.0.7"
resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.7.tgz#915f236d92ae98ef48278a95dedf17e991936ec6"
integrity sha512-fgVY8AV7qU7z/MmXJ/rxwbrtQH4jBQ9m7kp3llF0liB7glmFeVZFBepQb32T3y8n8k2+AEYuMPCpinYW+/CuRA==
dependencies:
"@types/http-proxy" "^1.17.8"
http-proxy "^1.18.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"eslint-plugin-jest-dom": "5.4.0",
"eslint-plugin-jest-formatting": "3.1.0",
"eslint-plugin-jsx-a11y": "6.10.2",
"eslint-plugin-react": "7.37.1",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-testing-library": "6.3.4"
"eslint-plugin-testing-library": "6.4.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import * as React from 'react';
import { renderHook } from 'wrappedTestingLibrary/hooks';

import TelemetryContext from 'logic/telemetry/TelemetryContext';

import useSendTelemetry from './useSendTelemetry';

jest.mock('util/AppConfig');

const contextValue = {
sendTelemetry: jest.fn(),
};
const DummyTelemetryContext = ({ children = undefined }: React.PropsWithChildren<{}>) => (
<TelemetryContext.Provider value={contextValue}>{children}</TelemetryContext.Provider>
);

describe('useSendTelemetry', () => {
const setLocation = (pathname: string) => Object.defineProperty(window, 'location', {
value: {
pathname,
},
writable: true,
});

const oldLocation = window.location;

afterEach(() => {
window.location = oldLocation;
});

it('should return `sendTelemetry` that retrieves current route', () => {
setLocation('/welcome');
const { result } = renderHook(() => useSendTelemetry(), { wrapper: DummyTelemetryContext });

const sendTelemetry = result.current;

expect(sendTelemetry).toBeDefined();

sendTelemetry('$pageview', { app_section: 'welcome section' });

expect(contextValue.sendTelemetry).toHaveBeenCalledWith('$pageview', { app_path_pattern: undefined, app_section: 'welcome section' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ import type { DataRouterContextObject } from 'react-router/dist/lib/context';

import type { TelemetryEventType, TelemetryEvent } from 'logic/telemetry/TelemetryContext';
import TelemetryContext from 'logic/telemetry/TelemetryContext';
import { currentPathnameWithoutPrefix } from 'util/URLUtils';
import { currentPathname, stripPrefixFromPathname } from 'util/URLUtils';
import { singleton } from 'logic/singleton';

const retrieveCurrentRoute = (dataRouterContext: DataRouterContextObject) => {
if (!dataRouterContext?.router?.routes) {
return undefined;
}

const { router: { routes } } = dataRouterContext;
const pathname = currentPathnameWithoutPrefix();
const pathname = currentPathname();
const matches = matchRoutes(routes, pathname);

return matches.at(-1).route.path;
return stripPrefixFromPathname(matches?.at(-1)?.route.path);
};

const useSendTelemetry = () => {
Expand All @@ -49,4 +50,4 @@ const useSendTelemetry = () => {
}, [dataRouterContext, sendTelemetry]);
};

export default useSendTelemetry;
export default singleton('core.useSendTelemetry', () => useSendTelemetry);
9 changes: 9 additions & 0 deletions graylog2-web-interface/src/util/URLUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,14 @@ describe('qualifyUrl', () => {

expect(currentPathnameWithoutPrefix()).toBe(pathname);
});

it('returns current path when prefix is defined and ends with `/`', () => {
const pathname = '/welcome';
setLocation(`/foo${pathname}`);

mockPathPrefix('/foo/');

expect(currentPathnameWithoutPrefix()).toBe(pathname);
});
});
});
21 changes: 18 additions & 3 deletions graylog2-web-interface/src/util/URLUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const URLUtils = {
try {
// eslint-disable-next-line
new URL(str);
} catch (e) {
} catch (ignored) {
isValid = false;
}

Expand All @@ -113,12 +113,25 @@ const URLUtils = {
getPathnameWithoutId(pathname: string) {
return pathname.replace(/\/[0-9a-fA-F]{24}/, '').slice(1);
},
currentPathname() {
return window.location.pathname;
},
currentPathnameWithoutPrefix() {
const pathPrefix = AppConfig.gl2AppPathPrefix();
return URLUtils.stripPrefixFromPathname(URLUtils.currentPathname());
},
stripPrefixFromPathname(path: string) {
if (!path) {
return path;
}

const rawPathPrefix = AppConfig.gl2AppPathPrefix();
const pathPrefix = rawPathPrefix?.length > 1 && rawPathPrefix.endsWith('/')
? rawPathPrefix.slice(0, -1)
: rawPathPrefix;

const pathPrefixLength = (!pathPrefix || pathPrefix === '' || pathPrefix === '/') ? 0 : pathPrefix.length;

return window.location.pathname.slice(pathPrefixLength);
return path.slice(pathPrefixLength);
},
};

Expand All @@ -134,5 +147,7 @@ export const {
concatURLPath,
isValidURL,
hasAcceptedProtocol,
currentPathname,
currentPathnameWithoutPrefix,
stripPrefixFromPathname,
} = URLUtils;
4 changes: 2 additions & 2 deletions graylog2-web-interface/src/views/bindings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ const exports: PluginExports = {
{ path: Routes.unqualified.stream_search(':streamId'), component: StreamSearchPage, parentComponent: App },
{ path: extendedSearchPath, component: NewSearchPage, parentComponent: App },
{ path: showViewsPath, component: ShowViewPage, parentComponent: App },
{ path: Routes.ALERTS.replay_search(':alertId'), component: EventReplaySearchPage, parentComponent: App },
{ path: Routes.ALERTS.DEFINITIONS.replay_search(':definitionId'), component: EventDefinitionReplaySearchPage, parentComponent: App },
{ path: Routes.unqualified.ALERTS.replay_search(':alertId'), component: EventReplaySearchPage, parentComponent: App },
{ path: Routes.unqualified.ALERTS.DEFINITIONS.replay_search(':definitionId'), component: EventDefinitionReplaySearchPage, parentComponent: App },
],
enterpriseWidgets: [
{
Expand Down
6 changes: 2 additions & 4 deletions graylog2-web-interface/webpack/vendor-module-ids.json
Original file line number Diff line number Diff line change
Expand Up @@ -3848,7 +3848,6 @@
3049,
3052,
3067,
3072,
3086,
3090,
3093,
Expand Down Expand Up @@ -3880,7 +3879,6 @@
3366,
3377,
3386,
3404,
3413,
3465,
3475,
Expand All @@ -3892,7 +3890,6 @@
3557,
3607,
3625,
3641,
3651,
3652,
3678,
Expand Down Expand Up @@ -4383,7 +4380,6 @@
9290,
9294,
9295,
9317,
9354,
9359,
9361,
Expand Down Expand Up @@ -4428,10 +4424,12 @@
9827,
9847,
9861,
9864,
9874,
9886,
9894,
9915,
9921,
9961,
9962,
9963,
Expand Down

0 comments on commit 0610681

Please sign in to comment.