open sql link from markdown

This commit is contained in:
Jan Prochazka
2020-12-12 10:42:26 +01:00
parent ed98a9e2da
commit b1a2093e6b
3 changed files with 32 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import Markdown from 'markdown-to-jsx';
import styled from 'styled-components';
import OpenChartLink from './OpenChartLink';
import MarkdownLink from './MarkdownLink';
import OpenSqlLink from './OpenSqlLink';
const Wrapper = styled.div`
padding: 10px;
@@ -19,6 +20,9 @@ export default function MarkdownExtendedView({ children }) {
OpenChartLink: {
component: OpenChartLink,
},
OpenSqlLink: {
component: OpenSqlLink,
},
a: MarkdownLink,
},
}}

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { useCurrentDatabase, useSetOpenedTabs } from '../utility/globalState';
import { useCurrentDatabase } from '../utility/globalState';
import axios from '../utility/axios';
import useTheme from '../theme/useTheme';
import { StyledThemedLink } from '../widgets/FormStyledButton';
@@ -20,6 +20,7 @@ export default function OpenChartLink({ file, children }) {
props: {
conid: currentDb && currentDb.connection && currentDb.connection._id,
database: currentDb && currentDb.name,
savedFile: file,
},
},
resp.data

View File

@@ -0,0 +1,26 @@
import React from 'react';
import axios from '../utility/axios';
import useTheme from '../theme/useTheme';
import { StyledThemedLink } from '../widgets/FormStyledButton';
import useNewQuery from '../query/useNewQuery';
export default function OpenSqlLink({ file, children }) {
const newQuery = useNewQuery();
const theme = useTheme();
const handleClick = async () => {
const resp = await axios.post('files/load', { folder: 'sql', file, format: 'text' });
newQuery({
title: file,
initialData: resp.data,
// @ts-ignore
savedFile: file,
});
};
return (
<StyledThemedLink theme={theme} onClick={handleClick}>
{children}
</StyledThemedLink>
);
}