Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.
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
91 changes: 62 additions & 29 deletions client/src/common/SqlEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ import 'ace-builds/src-noconflict/theme-sqlserver';
const noop = () => {};

export interface Props {
autoHeight: boolean;
onChange?: (value: string) => void;
readOnly: boolean;
value: string;
onSelectionChange: (value: string) => void;
}

function SqlEditor({ onChange, readOnly, value, onSelectionChange }: Props) {
function SqlEditor({
autoHeight,
onChange,
readOnly,
value,
onSelectionChange,
}: Props) {
const { config } = useAppContext();
const [dimensions, setDimensions] = useState({ width: -1, height: -1 });
const [editor, setEditor] = useState<any>(null);
Expand Down Expand Up @@ -57,46 +64,72 @@ function SqlEditor({ onChange, readOnly, value, onSelectionChange }: Props) {
tabSize: 2,
};

if (autoHeight) {
return (
<Measure
bounds
onResize={(contentRect: any) => setDimensions(contentRect.bounds)}
>
{({ measureRef }) => (
<div ref={measureRef} className="h-100 w-100">
<AceEditor
editorProps={{ $blockScrolling: Infinity }}
focus={!readOnly}
height={height + 'px'}
fontSize={14}
highlightActiveLine={false}
mode="sql"
name="query-ace-editor"
onChange={onChange || noop}
onLoad={(editor) => setEditor(editor)}
onSelectionChange={handleSelection}
readOnly={readOnly}
setOptions={setOptions}
showGutter={true}
showPrintMargin={false}
theme="sqlserver"
value={value}
width={width + 'px'}
/>
</div>
)}
</Measure>
);
}

return (
<Measure
bounds
onResize={(contentRect: any) => setDimensions(contentRect.bounds)}
>
{({ measureRef }) => (
<div ref={measureRef} className="h-100 w-100">
<AceEditor
editorProps={{ $blockScrolling: Infinity }}
focus={!readOnly}
height={height + 'px'}
fontSize={14}
highlightActiveLine={false}
mode="sql"
name="query-ace-editor"
onChange={onChange || noop}
onLoad={(editor) => setEditor(editor)}
onSelectionChange={handleSelection}
readOnly={readOnly}
setOptions={setOptions}
showGutter={true}
showPrintMargin={false}
theme="sqlserver"
value={value}
width={width + 'px'}
/>
</div>
)}
</Measure>
<AceEditor
editorProps={{ $blockScrolling: Infinity }}
focus={!readOnly}
fontSize={14}
highlightActiveLine={false}
mode="sql"
name="query-ace-editor"
onChange={onChange || noop}
onLoad={(editor) => setEditor(editor)}
onSelectionChange={handleSelection}
readOnly={readOnly}
setOptions={setOptions}
showGutter={true}
showPrintMargin={false}
theme="sqlserver"
value={value}
maxLines={12}
width={'100%'}
/>
);
}

SqlEditor.propTypes = {
autoHeight: PropTypes.bool,
onChange: PropTypes.func,
onSelectionChange: PropTypes.func,
readOnly: PropTypes.bool,
value: PropTypes.string,
};

SqlEditor.defaultProps = {
autoHeight: true,
onSelectionChange: () => {},
readOnly: false,
value: '',
Expand Down
10 changes: 5 additions & 5 deletions client/src/common/SqlpadTauChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ function SqlpadTauChart({
let chart: any;

if (!isRunning && !queryError && chartConfiguration && columns && rows) {
const queryResult = {
const dataRows = getObjectRows(columns, rows);
const chartConfig = getTauChartConfig(
chartConfiguration,
columns,
rows: getObjectRows(columns, rows),
};
const chartConfig = getTauChartConfig(chartConfiguration, queryResult);
dataRows
);
if (chartConfig) {
chart = new Chart(chartConfig);
chart.renderTo('#chart');
Expand Down Expand Up @@ -86,7 +87,6 @@ SqlpadTauChart.propTypes = {
isRunning: PropTypes.bool,
chartConfiguration: PropTypes.object,
queryError: PropTypes.string,
queryResult: PropTypes.object,
};

export default SqlpadTauChart;
19 changes: 8 additions & 11 deletions client/src/common/getTauChartConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import quickFilter from 'taucharts/dist/plugins/quick-filter';
import tooltip from 'taucharts/dist/plugins/tooltip';
import tcTrendline from 'taucharts/dist/plugins/trendline';
import baseUrl from '../utilities/baseUrl';
import { StatementColumn } from '../types';

/**
* Caution this uses any type for a few things
Expand All @@ -25,11 +26,6 @@ interface Field {
inputType: string;
}

interface Column {
name: string;
datatype: string;
}

interface ChartConfiguration {
chartType: string;
fields: StringMap;
Expand Down Expand Up @@ -62,13 +58,14 @@ const getUnmetFields = (chartType: string, selectedFieldMap: StringMap) => {

export default function getTauChartConfig(
chartConfiguration: ChartConfiguration,
queryResult: any
columns: StatementColumn[] = [],
rows: any[] = []
) {
if (!chartConfiguration) {
return null;
}
const columns = queryResult ? queryResult.columns : [];
let dataRows = queryResult ? queryResult.rows : [];

let dataRows = rows || [];
const chartType = chartConfiguration.chartType;
const selectedFields = chartConfiguration.fields;

Expand Down Expand Up @@ -109,7 +106,7 @@ export default function getTauChartConfig(
// loop through data rows and convert types as needed
dataRows = dataRows.map((row: DataRow) => {
const newRow: DataRow = {};
columns.forEach((col: Column) => {
columns.forEach((col: StatementColumn) => {
const { datatype, name } = col;
if (datatype === 'date' || datatype === 'datetime') {
newRow[name] = new Date(row[name]);
Expand All @@ -131,7 +128,7 @@ export default function getTauChartConfig(
forceDimensionFields.forEach((fieldDefinition) => {
const columnName = selectedFields[fieldDefinition.fieldId];
const column = columns.find(
(column: Column) => column.name === columnName
(column: StatementColumn) => column.name === columnName
);
const colDatatype = column ? column.datatype : null;
if (columnName && colDatatype === 'number' && newRow[columnName]) {
Expand All @@ -154,7 +151,7 @@ export default function getTauChartConfig(

if (fieldDefinition && fieldDefinition.inputType !== 'field-dropdown') {
fieldsMap[fieldColName] = columnName;
} else if (columns.find((c: Column) => c.name === columnName)) {
} else if (columns.find((c: StatementColumn) => c.name === columnName)) {
fieldsMap[fieldColName] = columnName;
}
return fieldsMap;
Expand Down
12 changes: 8 additions & 4 deletions client/src/queryEditor/QueryEditorChartToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import React from 'react';
import IconButton from '../common/IconButton';
import { exportPng } from '../common/tauChartRef';
import {
useLastStatementId,
useSessionQueryId,
useSessionQueryName,
useSessionQueryResult,
useStatementStatus,
} from '../stores/editor-store';
import { api } from '../utilities/api';

function QueryEditorChartToolbar({ children }: any) {
const queryId = useSessionQueryId() || 'new';
const queryName = useSessionQueryName() || 'New query';
const queryResult = useSessionQueryResult();

const downloadEnabled =
queryResult && queryResult.rows && queryResult.rows.length;
const statementId = useLastStatementId();
const status = useStatementStatus(statementId);
const { data } = api.useStatementResults(statementId, status);

const downloadEnabled = data && data.length;

return (
<div
Expand Down
28 changes: 0 additions & 28 deletions client/src/queryHistory/QueryHistoryResultHeader.module.css

This file was deleted.

48 changes: 0 additions & 48 deletions client/src/queryHistory/QueryHistoryResultHeader.tsx

This file was deleted.

1 change: 0 additions & 1 deletion client/src/stores/editor-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ export const loadQuery = async (queryId: string) => {
selectedStatementId: '',
isRunning: false,
queryError: undefined,
queryResult: undefined,
unsavedChanges: false,
});

Expand Down
6 changes: 0 additions & 6 deletions client/src/stores/editor-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export interface EditorSession {
selectedText: string;
selectedStatementId: string;
queryError?: any;
queryResult?: any;
runQueryStartTime?: any;
showValidation: boolean;
unsavedChanges: boolean;
Expand Down Expand Up @@ -86,7 +85,6 @@ export const INITIAL_SESSION: EditorSession = {
canWrite: true,
canDelete: true,
queryError: undefined,
queryResult: undefined,
runQueryStartTime: undefined,
selectedText: '',
selectedStatementId: '',
Expand Down Expand Up @@ -214,10 +212,6 @@ export function useSessionChartFields() {
return useEditorStore((s) => s.getFocusedSession().chartFields);
}

export function useSessionQueryResult() {
return useEditorStore((s) => s.getFocusedSession().queryResult);
}

export function useSessionQueryError() {
return useEditorStore((s) => {
const { queryError, selectedStatementId } = s.getFocusedSession();
Expand Down
1 change: 1 addition & 0 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ proxy['^/.*/api/app'] = PROXY_URL;

// https://vitejs.dev/config/
export default defineConfig({
base: '/sqlpad/',
plugins: [reactRefresh()],
server: {
proxy,
Expand Down