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

Revamp toolpad file system layout #1831

Merged
merged 43 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
aa90977
phase1
Janpot Mar 28, 2023
354389a
wip
Janpot Mar 29, 2023
f1908ae
Merge branch 'master' into pages-folder
Janpot Mar 30, 2023
d85c20f
dsfesf
Janpot Mar 30, 2023
cfee55f
Merge branch 'master' into pages-folder
Janpot Mar 30, 2023
9ef916b
daeer
Janpot Mar 30, 2023
c431484
fixes
Janpot Mar 30, 2023
8ae0b1f
accidentally
Janpot Mar 30, 2023
9267998
revert
Janpot Mar 30, 2023
4bfcba4
dear
Janpot Mar 30, 2023
e1493ba
update
Janpot Mar 30, 2023
11ec59c
Remove migration
Janpot Mar 30, 2023
3d09404
fsfew
Janpot Mar 30, 2023
3de236a
yaml patch
Janpot Mar 30, 2023
d846ec3
fwrgwrg
Janpot Mar 30, 2023
1c14f30
Fix custom components
Janpot Mar 30, 2023
3180745
codecomponents init
Janpot Mar 30, 2023
b0ff585
kdjeha
Janpot Mar 31, 2023
f9aa3bc
query params
Janpot Mar 31, 2023
3820d6e
Merge branch 'master' into pages-folder
Janpot Mar 31, 2023
fa55f3e
fix
Janpot Apr 1, 2023
09ef648
Merge branch 'master' into pages-folder
Janpot Apr 1, 2023
fe9f64e
Merge branch 'master' into pages-folder
Janpot Apr 3, 2023
c5d404e
rename page children to content
Janpot Apr 3, 2023
bb0f2e1
display
Janpot Apr 3, 2023
a923c1e
queries
Janpot Apr 4, 2023
e0834c7
daefef
Janpot Apr 4, 2023
9a28b20
naming conventions
Janpot Apr 4, 2023
6d67d2b
apiVersion
Janpot Apr 4, 2023
3e0ed59
some more descriptions
Janpot Apr 4, 2023
d925300
hopla
Janpot Apr 5, 2023
c813deb
Merge branch 'master' into pages-folder
Janpot Apr 5, 2023
bd29356
dae
Janpot Apr 5, 2023
c207aad
derwer
Janpot Apr 5, 2023
9e04e66
fix test
Janpot Apr 5, 2023
bd82662
dare
Janpot Apr 5, 2023
116cf21
output
Janpot Apr 5, 2023
1f0b519
add optional resource
Janpot Apr 5, 2023
ec068f7
fwesfwe
Janpot Apr 5, 2023
299ba2c
erwerw
Janpot Apr 5, 2023
b8d5705
dewrwe
Janpot Apr 5, 2023
5028c10
Merge branch 'master' into pages-folder
Janpot Apr 7, 2023
0a08415
Merge branch 'master' into pages-folder
Janpot Apr 12, 2023
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 @@ -16,7 +16,7 @@

The most powerful way of bringing data into Toolpad is through serverside JavaScript functions. The setup is as follows:

1. Start by changing `toolpad/queries.ts` and set its content to:
1. Start by changing `toolpad/resources/functions.ts` and set its content to:

```tsx
export async function example() {
Expand Down Expand Up @@ -48,7 +48,7 @@ The most powerful way of bringing data into Toolpad is through serverside JavaSc

<img src="/static/toolpad/docs/serverside-js/js-3.png?v=0" alt="Runs in Node.js" width="890px" />

You can import and use any Node.js module in `toolpad/queries.ts`. That means that you can access any API or database that distributes a client library as a Node.js module.
You can import and use any Node.js module in `toolpad/resources/functions.ts`. That means that you can access any API or database that distributes a client library as a Node.js module.

## Parameters

Expand Down
5 changes: 4 additions & 1 deletion packages/toolpad-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@
"superjson": "^1.12.2",
"ts-node": "^10.9.1",
"whatwg-url": "^12.0.1",
"yaml": "^2.2.1"
"yaml": "^2.2.1",
"yaml-diff-patch": "^2.0.0",
"zod": "^3.21.4",
"zod-validation-error": "^1.1.0"
},
"devDependencies": {
"@types/babel__code-frame": "^7.0.3",
Expand Down
39 changes: 29 additions & 10 deletions packages/toolpad-app/src/appDom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,14 @@ export function assertIsMutation<P>(node: AppDomNode): asserts node is MutationN
assertIsType<MutationNode>(node, 'mutation');
}

export function getRoot(dom: AppDom): AppDomNode {
return getNode(dom, dom.root);
}

export function getApp(dom: AppDom): AppNode {
const rootNode = getNode(dom, dom.root);
assertIsApp(rootNode);
return rootNode;
const app = getRoot(dom);
assertIsApp(app);
return app;
}

export type NodeChildren<N extends AppDomNode = any> = ChildNodesOf<N>;
Expand Down Expand Up @@ -500,20 +504,35 @@ export function createNode<T extends AppDomNodeType>(
});
}

export function createDom(): AppDom {
const rootId = createId();
export function createFragmentInternal<T extends AppDomNodeType>(
id: NodeId,
type: T,
init: AppDomNodeInitOfType<T> & { name: string },
): AppDom {
return {
nodes: {
[rootId]: createNodeInternal(rootId, 'app', {
name: 'Application',
attributes: {},
}),
[id]: createNodeInternal(id, type, init),
},
root: rootId,
root: id,
version: CURRENT_APPDOM_VERSION,
};
}

export function createFragment<T extends AppDomNodeType>(
type: T,
init: AppDomNodeInitOfType<T> & { name: string },
): AppDom {
const rootId = createId();
return createFragmentInternal(rootId, type, init);
}

export function createDom(): AppDom {
return createFragment('app', {
name: 'Application',
attributes: {},
});
}

/**
* Creates a new DOM node representing a React Element
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-app/src/appDom/migrations/v6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { mapValues } from '../../utils/collections';

export default {
up(dom: appDom.AppDom): appDom.AppDom {
invariant(dom.version === 5, 'Can only migrate dom of version 4');
invariant(dom.version === 5, 'Can only migrate dom of version 5');

const prefix = 'codeComponent.';
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/toolpad-app/src/server/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import applyTransform from '../toolpadDataSources/applyTransform';
import createRuntimeState from '../createRuntimeState';
import { saveLocalDom, loadLocalDom } from './localMode';

export async function saveDom(app: appDom.AppDom): Promise<void> {
await saveLocalDom(app);
export async function saveDom(app: appDom.AppDom): Promise<{ fingerprint: number }> {
return saveLocalDom(app);
}

export async function loadDom(): Promise<appDom.AppDom> {
Expand Down
Loading