Skip to content

Commit

Permalink
Remove dom duplication (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Aug 19, 2022
1 parent 4aa32bf commit d7bd51e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 29 deletions.
27 changes: 0 additions & 27 deletions packages/toolpad-app/src/appDom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,30 +872,3 @@ export function fromLegacyQueryNode(node: QueryNode<any>): QueryNode<any> {

return node;
}

/**
* Poor man's duplicate function
* In anticipation of https://github.com/mui/mui-toolpad/pull/658
*/
export function duplicate(dom: AppDom): AppDom {
const newIndices = new Map(Object.keys(dom.nodes).map((id) => [id, cuid()]));
return {
root: newIndices.get(dom.root) as NodeId,
nodes: Object.fromEntries(
Object.entries(dom.nodes).map(([oldId, node]) => {
const newId = newIndices.get(oldId) as NodeId;
const newNode = {
...node,
parentId: node.parentId ? (newIndices.get(node.parentId) as NodeId) : null,
id: newId,
} as AppDomNode;
if (isQuery(newNode) && newNode.attributes.connectionId.value) {
newNode.attributes.connectionId.value = ref(
newIndices.get(deref(newNode.attributes.connectionId.value)) as NodeId,
);
}
return [newId, newNode];
}),
),
};
}
1 change: 1 addition & 0 deletions packages/toolpad-app/src/components/JsonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const JsonViewRoot = styled('div')(({ theme }) => ({
position: 'relative',
display: 'flex',
minHeight: 0,
minWidth: 0,

[`&.${classes.disabled}`]: {
opacity: 0.5,
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-app/src/server/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export async function createApp(name: string, opts: CreateAppOptions = {}): Prom
data: { name },
});

const dom = opts.dom ? appDom.duplicate(opts.dom) : createDefaultDom();
const dom = opts.dom || createDefaultDom();

await saveDom(app.id, dom);

Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-app/src/toolpad/AppEditor/PagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function AppMenu() {
maxWidth="sm"
>
<DialogTitle id={dialogTitleId}>Application DOM</DialogTitle>
<DialogContent sx={{ position: 'relative', display: 'flex' }}>
<DialogContent sx={{ position: 'relative', display: 'flex', alignItems: 'stretch' }}>
<JsonView sx={{ flex: 1 }} copyToClipboard src={dom} expandPaths={[]} expandLevel={5} />
</DialogContent>
<DialogActions>
Expand Down

0 comments on commit d7bd51e

Please sign in to comment.