mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
fix: can't match project when last visit page is dashboard (#7762)
* fix: can't match project when last visit page is dashboard * fix: typo
This commit is contained in:
parent
1cf0901895
commit
ec48392081
@ -1,4 +1,4 @@
|
|||||||
import { matchPath } from 'react-router-dom';
|
import { matchPath, type PathMatch } from 'react-router-dom';
|
||||||
|
|
||||||
import { database } from '../common/database';
|
import { database } from '../common/database';
|
||||||
import * as models from '../models';
|
import * as models from '../models';
|
||||||
@ -11,6 +11,27 @@ export const enum AsyncTask {
|
|||||||
MigrateProjects,
|
MigrateProjects,
|
||||||
SyncProjects,
|
SyncProjects,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getMatchParams = (location: string) => {
|
||||||
|
const workspaceMatch = matchPath(
|
||||||
|
{
|
||||||
|
path: '/organization/:organizationId/project/:projectId/workspace/:workspaceId',
|
||||||
|
end: false,
|
||||||
|
},
|
||||||
|
location
|
||||||
|
);
|
||||||
|
|
||||||
|
const projectMatch = matchPath(
|
||||||
|
{
|
||||||
|
path: '/organization/:organizationId/project/:projectId',
|
||||||
|
end: false,
|
||||||
|
},
|
||||||
|
location
|
||||||
|
);
|
||||||
|
|
||||||
|
return (workspaceMatch || projectMatch) as PathMatch<'organizationId' | 'projectId' | 'workspaceId'> | null;
|
||||||
|
};
|
||||||
|
|
||||||
export const getInitialRouteForOrganization = async ({
|
export const getInitialRouteForOrganization = async ({
|
||||||
organizationId,
|
organizationId,
|
||||||
navigateToWorkspace = false,
|
navigateToWorkspace = false,
|
||||||
@ -21,13 +42,8 @@ export const getInitialRouteForOrganization = async ({
|
|||||||
);
|
);
|
||||||
// Check if the last visited project exists and redirect to it
|
// Check if the last visited project exists and redirect to it
|
||||||
if (prevOrganizationLocation) {
|
if (prevOrganizationLocation) {
|
||||||
const match = matchPath(
|
|
||||||
{
|
const match = getMatchParams(prevOrganizationLocation);
|
||||||
path: '/organization/:organizationId/project/:projectId/workspace/:workspaceId',
|
|
||||||
end: false,
|
|
||||||
},
|
|
||||||
prevOrganizationLocation
|
|
||||||
);
|
|
||||||
|
|
||||||
if (match && match.params.organizationId && match.params.projectId) {
|
if (match && match.params.organizationId && match.params.projectId) {
|
||||||
const existingProject = await models.project.getById(match.params.projectId);
|
const existingProject = await models.project.getById(match.params.projectId);
|
||||||
|
Loading…
Reference in New Issue
Block a user