Skip to content

Commit

Permalink
Merge pull request #21 from Multiwoven/feat/beautify-sql
Browse files Browse the repository at this point in the history
feat: beautify sql queries
  • Loading branch information
sumitd94 authored Apr 9, 2024
2 parents f21bf67 + b9009d6 commit a9de2a4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 11 deletions.
89 changes: 87 additions & 2 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"react-icons": "^4.12.0",
"react-router-dom": "^6.21.1",
"rollup": "^4.9.1",
"sql-formatter": "^15.3.0",
"styled-components": "^6.1.1",
"yup": "^1.3.3"
},
Expand Down
6 changes: 3 additions & 3 deletions ui/src/views/Activate/Syncs/EditSync/EditSync.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ContentContainer from '@/components/ContentContainer';
import { Box } from '@chakra-ui/react';
import { SYNCS_LIST_QUERY_KEY } from '@/views/Activate/Syncs/constants';
import { useNavigate, useParams } from 'react-router-dom';
import { useQuery, useQueryClient } from '@tanstack/react-query';
Expand Down Expand Up @@ -179,7 +179,7 @@ const EditSync = (): JSX.Element | null => {

return (
<form onSubmit={formik.handleSubmit} style={{ backgroundColor: 'gray.200' }}>
<ContentContainer>
<Box width='100%' pt='20px'>
{isLoading || isConnectorInfoLoading || !syncData ? <Loader /> : null}
{syncData && destinationFetchResponse?.data ? (
<React.Fragment>
Expand Down Expand Up @@ -228,7 +228,7 @@ const EditSync = (): JSX.Element | null => {
isContinueCtaRequired
isBackRequired
/>
</ContentContainer>
</Box>
</form>
);
};
Expand Down
4 changes: 2 additions & 2 deletions ui/src/views/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const Dashboard = (): JSX.Element | null => {
setReportTime(timePeriod);
};

const syncRunTriggeredData = report?.data.sync_run_triggered;
const syncRunRowsData = report?.data.total_sync_run_rows;
const syncRunTriggeredData = report?.data?.sync_run_triggered;
const syncRunRowsData = report?.data?.total_sync_run_rows;

if (isLoading) {
return <Loader />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ContentContainer from '@/components/ContentContainer';
import SourceFormFooter from '@/views/Connectors/Sources/SourcesForm/SourceFormFooter';
import { CustomToastStatus } from '@/components/Toast/index';
import useCustomToast from '@/hooks/useCustomToast';
import { format } from 'sql-formatter';

const DefineSQL = ({
hasPrefilledValues = false,
Expand All @@ -30,10 +31,10 @@ const DefineSQL = ({
const [loading, setLoading] = useState(false);
const [moveForward, canMoveForward] = useState(false);
const [runQuery, canRunQuery] = useState(prefillValues ? true : false);
const [userQuery, setUserQuery] = useState(prefillValues?.query || '');

let connector_id: string = '';
let connector_icon: JSX.Element = <></>;
let user_query: string = '';

if (!hasPrefilledValues) {
const extracted = extractData(state.forms);
Expand All @@ -45,7 +46,6 @@ const DefineSQL = ({

connector_id = prefillValues.connector_id.toString();
connector_icon = prefillValues.connector_icon;
user_query = prefillValues.query;
}

const showToast = useCustomToast();
Expand Down Expand Up @@ -167,6 +167,7 @@ const DefineSQL = ({
fontSize='12px'
height='32px'
paddingX={3}
onClick={() => setUserQuery(format(userQuery))}
>
<Image src={StarsImage} w={6} mr={2} /> Beautify
</Button>
Expand All @@ -179,12 +180,13 @@ const DefineSQL = ({
language='mysql'
defaultLanguage='mysql'
defaultValue='Enter your query...'
value={user_query}
value={userQuery}
saveViewState={true}
onMount={handleEditorDidMount}
onChange={() => {
onChange={(query) => {
canMoveForward(false);
canRunQuery(true);
setUserQuery(query as string);
}}
theme='light'
options={{
Expand Down

0 comments on commit a9de2a4

Please sign in to comment.