Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove editor segment from route #800

Merged
merged 7 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function CreateCodeComponentDialog({
const appNode = appDom.getApp(dom);
domApi.addNode(newNode, appNode, 'codeComponents');
onClose();
navigate(`/app/${appId}/editor/codeComponents/${newNode.id}`);
navigate(`/app/${appId}/codeComponents/${newNode.id}`);
}}
>
<DialogTitle>Create a new MUI Toolpad Code Component</DialogTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function CreateConnectionDialog({
const appNode = appDom.getApp(dom);
domApi.addNode(newNode, appNode, 'connections');
onClose();
navigate(`/app/${appId}/editor/connections/${newNode.id}`);
navigate(`/app/${appId}/connections/${newNode.id}`);
}}
>
<DialogTitle>Create a new MUI Toolpad Connection</DialogTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function CreatePageDialog({ appId, onClose, ...props }: CreatePag
domApi.addNode(newNode, appNode, 'pages');

onClose();
navigate(`/app/${appId}/editor/pages/${newNode.id}`);
navigate(`/app/${appId}/pages/${newNode.id}`);
}}
>
<DialogTitle>Create a new MUI Toolpad Page</DialogTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ function getActiveNodeId(location: Location): NodeId | null {
const match =
matchRoutes(
[
{ path: `/app/:appId/editor/pages/:activeNodeId` },
{ path: `/app/:appId/editor/apis/:activeNodeId` },
{ path: `/app/:appId/editor/codeComponents/:activeNodeId` },
{ path: `/app/:appId/editor/connections/:activeNodeId` },
{ path: `/app/:appId/pages/:activeNodeId` },
{ path: `/app/:appId/apis/:activeNodeId` },
{ path: `/app/:appId/codeComponents/:activeNodeId` },
{ path: `/app/:appId/connections/:activeNodeId` },
],
location,
) || [];
Expand All @@ -84,11 +84,11 @@ function getActiveNodeId(location: Location): NodeId | null {
function getLinkToNodeEditor(appId: string, node: appDom.AppDomNode): string | undefined {
switch (node.type) {
case 'page':
return `/app/${appId}/editor/pages/${node.id}`;
return `/app/${appId}/pages/${node.id}`;
case 'connection':
return `/app/${appId}/editor/connections/${node.id}`;
return `/app/${appId}/connections/${node.id}`;
case 'codeComponent':
return `/app/${appId}/editor/codeComponents/${node.id}`;
return `/app/${appId}/codeComponents/${node.id}`;
default:
return undefined;
}
Expand Down Expand Up @@ -137,20 +137,20 @@ export default function HierarchyExplorer({ appId, className }: HierarchyExplore
// TODO: sort out in-page selection
const page = appDom.getPageAncestor(dom, node);
if (page) {
navigate(`/app/${appId}/editor/pages/${page.id}`);
navigate(`/app/${appId}/pages/${page.id}`);
}
}

if (appDom.isPage(node)) {
navigate(`/app/${appId}/editor/pages/${node.id}`);
navigate(`/app/${appId}/pages/${node.id}`);
}

if (appDom.isCodeComponent(node)) {
navigate(`/app/${appId}/editor/codeComponents/${node.id}`);
navigate(`/app/${appId}/codeComponents/${node.id}`);
}

if (appDom.isConnection(node)) {
navigate(`/app/${appId}/editor/connections/${node.id}`);
navigate(`/app/${appId}/connections/${node.id}`);
}
};

Expand Down Expand Up @@ -201,7 +201,7 @@ export default function HierarchyExplorer({ appId, className }: HierarchyExplore
if (firstSiblingOfType) {
redirectAfterDelete = getLinkToNodeEditor(appId, firstSiblingOfType);
} else {
redirectAfterDelete = `/app/${appId}/editor`;
redirectAfterDelete = `/app/${appId}`;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/toolpad-app/src/toolpad/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function CreateAppDialog({ onClose, ...props }: CreateAppDialogProps) {

const createAppMutation = client.useMutation('createApp', {
onSuccess: (app) => {
window.location.href = `/_toolpad/app/${app.id}/editor`;
window.location.href = `/_toolpad/app/${app.id}`;
},
});

Expand Down Expand Up @@ -302,7 +302,7 @@ function AppCard({ app, activeDeployment, onDelete }: AppCardProps) {
/>
</CardContent>
<CardActions>
<Button component="a" href={app ? `/_toolpad/app/${app.id}/editor` : ''} disabled={!app}>
<Button component="a" href={app ? `/_toolpad/app/${app.id}` : ''} disabled={!app}>
Edit
</Button>
{openButton}
Expand Down
10 changes: 8 additions & 2 deletions packages/toolpad-app/src/toolpad/Toolpad.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import { BrowserRouter, Routes, Route, Navigate, useParams } from 'react-router-dom';
import { Box, CircularProgress, NoSsr, styled } from '@mui/material';
import { ErrorBoundary } from 'react-error-boundary';
import Release from './Release';
Expand Down Expand Up @@ -35,13 +35,19 @@ function FullPageError({ error }: FullPageErrorProps) {
);
}

function LegacyEditorUrlRedirect() {
const { '*': editorRoute } = useParams();
return <Navigate to={`../${editorRoute}`} />;
}

function AppWorkspace() {
return (
<Routes>
<Route>
<Route path="editor/*" element={<AppEditor />} />
<Route path="editor/*" element={<LegacyEditorUrlRedirect />} />
<Route path="releases" element={<Releases />} />
<Route path="releases/:version" element={<Release />} />
<Route path="*" element={<AppEditor />} />
</Route>
</Routes>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-app/src/toolpad/ToolpadAppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ToolpadAppShell({ appId, ...props }: ToolpadAppShellProp
<ToolpadShell
navigation={
<React.Fragment>
<Button component={Link} to={`/app/${appId}/editor`} color="inherit">
<Button component={Link} to={`/app/${appId}`} color="inherit">
Editor
</Button>
<Button component={Link} to={`/app/${appId}/releases`} color="inherit">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ async function handler(
await api.setConnectionParams(appId, connectionId, client.credentials);
}
return res.redirect(
`/_toolpad/app/${encodeURIComponent(appId)}/editor/connections/${encodeURIComponent(
`/_toolpad/app/${encodeURIComponent(appId)}/connections/${encodeURIComponent(
connectionId,
)}`,
);
Expand Down
2 changes: 1 addition & 1 deletion test/e2e-smoke/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('basic app creation flow', async ({ page }) => {

await page.click('[role="dialog"] button:has-text("create")');

await page.waitForNavigation({ url: /\/_toolpad\/app\/[^/]+\/editor\/pages\/[^/]+/ });
await page.waitForNavigation({ url: /\/_toolpad\/app\/[^/]+\/pages\/[^/]+/ });

// TODO: basic editor tests

Expand Down