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

Allow binding query parameters to environment variables #2777

Merged
merged 38 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c9f813e
fix by second way
Oct 10, 2023
8841905
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 11, 2023
ceb878e
fix type error
Oct 11, 2023
8b342ef
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 12, 2023
c197c24
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 16, 2023
60ea47a
revert
Oct 16, 2023
df2428a
Merge branch '2616_add_node_env_second_way' of https://github.com/Jer…
Oct 16, 2023
c2b15d3
fix
Oct 16, 2023
6658227
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 17, 2023
4605334
fix
Oct 17, 2023
13d00d2
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 17, 2023
e3d0861
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 18, 2023
4f691d5
fix
Oct 18, 2023
ebc73a4
fix
Oct 18, 2023
ac8ff11
Merge branch '2616_add_node_env_second_way' of https://github.com/Jer…
Oct 18, 2023
98e548b
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 18, 2023
8e97f54
fix
Oct 20, 2023
553fbcd
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 20, 2023
81c5f75
fix
Oct 24, 2023
a5116b9
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 24, 2023
3fb2462
fix
Oct 24, 2023
c5467fe
Merge branch '2616_add_node_env_second_way' of https://github.com/Jer…
Oct 24, 2023
13f428f
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 24, 2023
3a81d5d
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 26, 2023
e116cf5
fix
Oct 26, 2023
b0f1ccc
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 30, 2023
7e237f7
display undefined if the variable included variable env
Oct 30, 2023
ca938a5
Merge branch '2616_add_node_env_second_way' of https://github.com/Jer…
Oct 30, 2023
79070a4
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Oct 31, 2023
c2d5bbf
optimized my code
Oct 31, 2023
e18045d
Merge branch '2616_add_node_env_second_way' of https://github.com/Jer…
Oct 31, 2023
2540902
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Nov 2, 2023
b924cdb
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Nov 4, 2023
568303e
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Nov 6, 2023
9c91fb3
fix
Nov 6, 2023
bd4eb99
Merge branch '2616_add_node_env_second_way' of https://github.com/Jer…
Nov 6, 2023
e8a7988
Merge branch 'master' into 2616_add_node_env_second_way
JerryWu1234 Nov 7, 2023
1517841
fix
Nov 7, 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
15 changes: 9 additions & 6 deletions packages/toolpad-app/src/toolpadDataSources/rest/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '@mui/material';
import { Controller, useForm } from 'react-hook-form';
import { TabContext, TabList } from '@mui/lab';
import { useBrowserJsRuntime } from '@mui/toolpad-core/jsBrowserRuntime';
import { useServerJsRuntime } from '@mui/toolpad-core/jsServerRuntime';
import { Panel, PanelGroup, PanelResizeHandle } from '../../components/resizablePanels';
import { ClientDataSource, ConnectionEditorProps, QueryEditorProps } from '../../types';
Expand Down Expand Up @@ -266,7 +265,10 @@ function QueryEditor({
},
{ retry: false },
);
const envVarNames = React.useMemo(() => introspection?.data?.envVarNames || [], [introspection]);

const envObj = React.useMemo(() => introspection?.data?.envVarNames, [introspection]);

const envVarNames = React.useMemo(() => Object.keys(envObj || {}) || [], [envObj]);

const handleParamsChange = React.useCallback(
(newParams: [string, BindableAttrValue<string>][]) => {
Expand Down Expand Up @@ -335,11 +337,10 @@ function QueryEditor({

const paramsEntries = input.params || EMPTY_PARAMS;

const jsBrowserRuntime = useBrowserJsRuntime();
const jsServerRuntime = useServerJsRuntime();
const jsServerRuntime = useServerJsRuntime(envObj);

const paramsEditorLiveValue = useEvaluateLiveBindingEntries({
jsRuntime: jsBrowserRuntime,
jsRuntime: jsServerRuntime,
input: paramsEntries,
globalScope,
});
Expand Down Expand Up @@ -463,6 +464,7 @@ function QueryEditor({
globalScopeMeta={QUERY_SCOPE_META}
liveValue={liveSearchParams}
jsRuntime={jsServerRuntime}
envVarNames={envVarNames}
/>
</TabPanel>
<TabPanel disableGutters value="body">
Expand Down Expand Up @@ -530,7 +532,8 @@ function QueryEditor({
globalScope={globalScope}
globalScopeMeta={globalScopeMeta}
liveValue={paramsEditorLiveValue}
jsRuntime={jsBrowserRuntime}
jsRuntime={jsServerRuntime}
envVarNames={envVarNames}
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
/>
</Box>
</Panel>
Expand Down
4 changes: 1 addition & 3 deletions packages/toolpad-app/src/toolpadDataSources/rest/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ export default function createDatasource(
switch (query.kind) {
case 'introspection': {
const env = await loadEnvFile(project);
const envVarNames = Object.keys(env);

return { envVarNames };
return { envVarNames: env };
}
case 'debugExec':
return execBase(project, connection, query.query, query.params);
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-app/src/toolpadDataSources/rest/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ export interface FetchResult extends ExecFetchResult<any> {
}

export type IntrospectionResult = {
envVarNames: string[];
envVarNames: Record<string, string | undefined>;
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
};
5 changes: 2 additions & 3 deletions packages/toolpad-core/src/jsServerRuntime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ export function createServerJsRuntime(env?: Record<string, string | undefined>):
};
}

export function useServerJsRuntime(): JsRuntime {
export function useServerJsRuntime(processEnv: Record<string, string | undefined> = {}): JsRuntime {
return React.useMemo(() => {
// process.env is not available in the browser
const processEnv = {};
return createServerJsRuntime(processEnv);
}, []);
}, [processEnv]);
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading