Skip to content

Commit

Permalink
Fix base path support
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Oct 28, 2022
1 parent e192495 commit ce620aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ jest.mock('../../../../common/lib/kibana', () => ({
]),
activeSpaceId: 'space1',
}),
useKibana: () => ({
services: {
http: {
basePath: {
get: () => '/basePath',
},
},
},
}),
}));

describe('rule_event_log_list_cell_renderer', () => {
Expand Down Expand Up @@ -126,7 +135,7 @@ describe('rule_event_log_list_cell_renderer', () => {
);
// @ts-ignore data-href is not a native EuiLink prop
expect(wrapper2.find(EuiLink).props()['data-href']).toEqual(
'/s/space2/app/management/insightsAndAlerting/triggersActions/rule/1'
'/basePath/s/space2/app/management/insightsAndAlerting/triggersActions/rule/1'
);

window.location = savedLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { RuleAlertingOutcome } from '@kbn/alerting-plugin/common';
import { useHistory } from 'react-router-dom';
import { routeToRuleDetails } from '../../../constants';
import { formatRuleAlertCount } from '../../../../common/lib/format_rule_alert_count';
import { useSpacesData } from '../../../../common/lib/kibana';
import { useKibana, useSpacesData } from '../../../../common/lib/kibana';
import { RuleEventLogListStatus } from './rule_event_log_list_status';
import { RuleDurationFormat } from '../../rules_list/components/rule_duration_format';
import {
Expand All @@ -37,6 +37,7 @@ interface RuleEventLogListCellRendererProps {
export const RuleEventLogListCellRenderer = (props: RuleEventLogListCellRendererProps) => {
const { columnId, value, version, dateFormat = DEFAULT_DATE_FORMAT, ruleId, spaceIds } = props;
const spacesData = useSpacesData();
const { http } = useKibana().services;

const history = useHistory();

Expand All @@ -55,10 +56,14 @@ export const RuleEventLogListCellRenderer = (props: RuleEventLogListCellRenderer
const ruleRoute = routeToRuleDetails.replace(':ruleId', ruleId);
if (ruleOnDifferentSpace) {
const [linkedSpaceId] = spaceIds ?? [];
const basePath = http.basePath.get();
const spacePath = linkedSpaceId !== 'default' ? `/s/${linkedSpaceId}` : '';
const historyPathname = history.location.pathname;
const newPathname = `${spacePath}${window.location.pathname
.replace(/^\/s\/([^/])+/, '')
const newPathname = `${basePath.replace(
`/s/${activeSpace!.id}`,
''
)}${spacePath}${window.location.pathname
.replace(basePath, '')
.replace(historyPathname, ruleRoute)}`;
return newPathname;
}
Expand Down

0 comments on commit ce620aa

Please sign in to comment.