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

Preview query button #647

Merged
merged 5 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -321,7 +321,7 @@ function QueryNodeEditorDialog<Q, P>({
<DialogTitle>Edit Query ({node.id})</DialogTitle>
{dataSourceId && dataSource ? (
<DialogContent>
<Stack spacing={1} py={1} gap={2}>
<Stack spacing={2} py={1}>
<Stack direction="row" gap={2}>
<NodeNameEditor node={node} />
<ConnectionSelect
Expand Down Expand Up @@ -404,16 +404,16 @@ function QueryNodeEditorDialog<Q, P>({
</Grid>
<Divider />
<Toolbar disableGutters>
preview
<LoadingButton
sx={{ ml: 2 }}
size="medium"
disabled={previewParams === paramsObject && previewQuery === input}
loading={isPreviewLoading}
loadingPosition="start"
variant="contained"
onClick={handleUpdatePreview}
startIcon={<PlayArrowIcon />}
>
Run
Preview
</LoadingButton>
</Toolbar>
{queryPreview.error ? <ErrorAlert error={queryPreview.error} /> : null}
Expand All @@ -422,7 +422,7 @@ function QueryNodeEditorDialog<Q, P>({
</DialogContent>
) : (
<DialogContent>
<Alert severity="error">DataSource &quot;{dataSourceId}&quot; not found</Alert>
<Alert severity="error">DaPtaSource &quot;{dataSourceId}&quot; not found</Alert>
</DialogContent>
)}
<DialogActions>
Expand Down
12 changes: 9 additions & 3 deletions packages/toolpad-app/src/components/JsonView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { SxProps, styled } from '@mui/material';
import { ObjectInspector, ObjectInspectorProps, ObjectValue, ObjectLabel } from 'react-inspector';

const nodeRenderer: ObjectInspectorProps['nodeRenderer'] = ({
Expand All @@ -14,21 +15,26 @@ const nodeRenderer: ObjectInspectorProps['nodeRenderer'] = ({
);
};

const JsonViewRoot = styled('div')({
whiteSpace: 'nowrap',
});

export interface JsonViewProps {
src: unknown;
sx?: SxProps;
}

export default function JsonView({ src }: JsonViewProps) {
export default function JsonView({ src, sx }: JsonViewProps) {
// TODO: elaborate on this to show a nice default, but avoid expanding massive amount of objects
const expandPaths = Array.isArray(src) ? ['$', '$.0', '$.1', '$.2', '$.3', '$.4'] : undefined;
return (
<div style={{ whiteSpace: 'nowrap' }}>
<JsonViewRoot sx={sx}>
<ObjectInspector
nodeRenderer={nodeRenderer}
expandLevel={1}
expandPaths={expandPaths}
data={src}
/>
</div>
</JsonViewRoot>
);
}