Skip to content

Commit

Permalink
Add preview to schema sources (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Scullin authored Sep 22, 2023
1 parent 908e56c commit b6f8f14
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/extension/notebook/renderer/schema_entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,23 @@ const SchemaRendererWrapper = ({
}
};

const onPreviewClick = (explore: Explore) => {
const type = 'malloy.runQuery';
const args = [
`query: ${explore.name}->{ project: *; limit: 20 }`,
`preview ${explore.name}`,
'html',
];
postMessage?.({type, args});
};

return (
<SchemaRenderer
explores={explores}
queries={queries}
onFieldClick={onFieldClick}
onQueryClick={onQueryClick}
onPreviewClick={onPreviewClick}
/>
);
};
26 changes: 25 additions & 1 deletion src/extension/webviews/components/SchemaRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface SchemaRendererProps {
defaultShow?: boolean;
onFieldClick?: (field: Field) => void;
onQueryClick?: (query: NamedQuery | QueryField) => void;
onPreviewClick?: (explore: Explore) => void;
}

/**
Expand Down Expand Up @@ -206,6 +207,7 @@ export const SchemaRenderer: React.FC<SchemaRendererProps> = ({
defaultShow = false,
onFieldClick,
onQueryClick,
onPreviewClick,
}) => {
if (!explores || !explores.length) {
return <b>No Schema Information</b>;
Expand Down Expand Up @@ -235,12 +237,23 @@ export const SchemaRenderer: React.FC<SchemaRendererProps> = ({
[setHidden]
);

const onClick = (event: React.MouseEvent) => {
onPreviewClick?.(explore);
event.stopPropagation();
event.preventDefault();
};

return (
<li className={`schema ${hidden}`} title={buildTitle(explore, path)}>
<div onClick={toggleHidden}>
<span>{hidden ? '▶' : '▼'}</span>{' '}
{getIconElement(`struct_${subtype}`, false)}{' '}
<b className="explore_name">{getExploreName(explore, path)}</b>
<b className="explore_name">{getExploreName(explore, path)}</b>{' '}
{onPreviewClick && !explore.hasParentExplore() && (
<span className="preview" onClick={onClick}>
Preview
</span>
)}
</div>
<ul>
{queries.length ? (
Expand Down Expand Up @@ -430,4 +443,15 @@ const SchemaTree = styled.div`
vertical-align: middle;
display: inline-block;
}
.preview {
color: var(--vscode-editorCodeLens-foreground);
font-size: 0.8em;
padding-left: 5px;
cursor: pointer;
&:hover {
color: var(--vscode-editorLink-activeForeground);
}
}
`;

0 comments on commit b6f8f14

Please sign in to comment.