Skip to content

Commit

Permalink
Merge pull request #37 from ozkeisar/bugfix-36
Browse files Browse the repository at this point in the history
fix issue 36
  • Loading branch information
ozkeisar authored Mar 4, 2025
2 parents ff5bb36 + d33f942 commit c1ef21c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Route, RouteResponse } from '../../../../types';
import { useGeneralStore } from '../../../state';
import { ResponseDetails } from './responseDetails';
import {
buildRouteUrl,
emitSocketEvent,
getRouteBGColor,
openInNewTab,
Expand Down Expand Up @@ -44,7 +45,12 @@ export function RouteDetails() {
const { deleteRoute } = useRouteActions();
const { deleteResponse } = useResponseActions();

const linkUrl = `${host}:${server?.settings.port}${parent?.path}${route?.routePath}`;
const linkUrl = buildRouteUrl(
host,
server?.settings.port,
parent?.path,
route?.routePath,
);

const handleSetActive = (routeId: string, responseId: string) => {
const localParent = cloneDeep(parent);
Expand Down
28 changes: 16 additions & 12 deletions src/renderer/components/dialogs/routeDialog/routeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,22 @@ export function RouteDialog({ onClose, open, data, parent, server }: Props) {
onClose();
};

const alreadyExistError = isRouteExist({
id: data?.id || '',
routePath,
method,
paramKey,
paramType,
paramValue,
description,
responsesHash:{},
activeResponseId:'',
withParams
}, parent) &&
const alreadyExistError =
isRouteExist(
{
id: data?.id || '',
routePath,
method,
paramKey,
paramType,
paramValue,
description,
responsesHash: {},
activeResponseId: '',
withParams,
},
parent,
) &&
!(data?.method === method && data.routePath === routePath && !!data.id);

return (
Expand Down
20 changes: 7 additions & 13 deletions src/renderer/components/logRow/restLogRow/restLogRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import {
formatDate,
getKeyValuePairReq,
getRequestRoute,
removeLastPartOfUri,
removeQueryParams,
reportButtonClick,
reportElementClick,
} from '../../../utils';
Expand Down Expand Up @@ -149,10 +149,7 @@ export function RestLogRow({
() =>
matchedParents?.reduce(
(acc, parent) => {
const requestRoute = removeQueryParams(requestUrl).replace(
parent.path,
'',
);
const requestRoute = getRequestRoute(requestUrl, parent.path);

if (acc.matchedRoute) {
return acc;
Expand Down Expand Up @@ -215,10 +212,8 @@ export function RestLogRow({
});

const _matchedParent = sortedMatchedParent[0];
const requestRoute = removeQueryParams(requestUrl).replace(
_matchedParent.path,
'',
);
const requestRoute = getRequestRoute(requestUrl, _matchedParent.path);

const _matchedRoute = Object.values(_matchedParent.routesHash || {}).find(
(routeItem) => {
return (
Expand Down Expand Up @@ -274,17 +269,16 @@ export function RestLogRow({

const _matchedParent = sortedMatchedParent[0];

const routePath = getRequestRoute(requestUrl, _matchedParent.path);

onAddRouteClick({
serverName: server?.name,
matchedParent: _matchedParent,
data: {
paramKey: key,
paramType: _type,
paramValue: value,
routePath: removeQueryParams(requestUrl).replace(
_matchedParent.path,
'',
),
routePath,
method: requestMethod,
activeResponseIndex: 0,
responses: [],
Expand Down
23 changes: 16 additions & 7 deletions src/renderer/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ export const JSONStringifyExtra = (obj: any) =>
});

export const openInNewTab = (url: string) => {
const newWindow = window.open(
url,
'_blank',
'noopener,noreferrer',
);
const newWindow = window.open(url, '_blank', 'noopener,noreferrer');
if (newWindow) newWindow.opener = null;
};

Expand Down Expand Up @@ -113,6 +109,21 @@ export const removeQueryParams = (uri: string) => {
return uri;
};

export const getRequestRoute = (uri: string, parentPath: string) => {
const routePath = removeQueryParams(uri).replace(parentPath, '');

return routePath.startsWith('/') ? routePath : `/${routePath}`;
};

export const buildRouteUrl = (
host: string | null,
port: number | undefined,
parentPath: string | undefined,
routePath: string | undefined,
) => {
return `${host}:${port}${parentPath === '/' ? '' : parentPath}${routePath}`;
};

type params = { [key: string]: any };
export const getKeyValuePairReq = (
body: params,
Expand Down Expand Up @@ -177,8 +188,6 @@ export const checkIsAllRoutesExists = (
);
};



export function combineNestedObjects(data: any) {
if (Array.isArray(data) && data.length > 0) {
// Handle array of objects
Expand Down

0 comments on commit c1ef21c

Please sign in to comment.