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

188 auto-create, edit the dbt profile #194

Merged
merged 8 commits into from
Jul 14, 2023
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
1 change: 0 additions & 1 deletion src/components/Connections/Connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ export const Connections = () => {
anchorEl={anchorEl}
open={open}
handleClose={handleClose}
elementId={blockId}
handleEdit={handleEditConnection}
handleDeleteConnection={handleDeleteConnection}
handleResetConnection={handleResetConnection}
Expand Down
118 changes: 0 additions & 118 deletions src/components/DBT/DBTCreateProfile.tsx

This file was deleted.

75 changes: 67 additions & 8 deletions src/components/DBT/DBTSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSession } from 'next-auth/react';
import { useState, useContext, useEffect } from 'react';
import { GlobalContext } from '@/contexts/ContextProvider';
import { errorToast } from '@/components/ToastMessage/ToastHelper';
import { httpGet, httpPost } from '@/helpers/http';
import { httpGet, httpPost, httpPut } from '@/helpers/http';
import CustomDialog from '../Dialog/CustomDialog';
import Input from '../UI/Input/Input';

Expand All @@ -14,6 +14,15 @@ interface DBTSetupProps {
setExpandLogs: (...args: any) => any;
showDialog: boolean;
setShowDialog: (...args: any) => any;
gitrepoUrl: string;
schema: string;
mode: string;
}

interface DBTCreateWorkspaceParams {
gitrepoUrl: string;
gitrepoAccessToken: string;
schema: string;
}

export const DBTSetup = ({
Expand All @@ -22,10 +31,11 @@ export const DBTSetup = ({
setExpandLogs,
showDialog,
setShowDialog,
gitrepoUrl,
schema,
mode,
}: DBTSetupProps) => {
const { register, handleSubmit, reset } = useForm({
defaultValues: { gitrepoUrl: '', gitrepoAccessToken: '', schema: '' },
});
const { register, handleSubmit, reset } = useForm<DBTCreateWorkspaceParams>();
const { data: session }: any = useSession();
const [progressMessages, setProgressMessages] = useState<any[]>([]);
const [setupStatus, setSetupStatus] = useState('not-started');
Expand Down Expand Up @@ -82,24 +92,33 @@ export const DBTSetup = ({
setProgressMessages(progressMessages.concat(progressMsgs));
}, [setupStatus]);

const onSubmit = async (data: any) => {
setSetupStatus('started');
const onSubmit = async (data: DBTCreateWorkspaceParams) => {
handleClose();
setExpandLogs(true);

if (mode === 'create') {
setSetupStatus('started');
createWorkspace(data);
} else {
editWorkspace(data);
}
};

const createWorkspace = async (data: DBTCreateWorkspaceParams) => {
const payload = {
gitrepoUrl: data.gitrepoUrl,
dbtVersion: '1.4.5',
profile: {
name: 'dbt',
target: 'dev',
target_configs_schema: data.schema,
},
} as any;

if (data.gitrepoAccessToken) {
payload.gitrepoAccessToken = data.gitrepoAccessToken;
}

setExpandLogs(true);

try {
const message = await httpPost(session, 'dbt/workspace/', payload);
setTimeout(() => {
Expand All @@ -112,6 +131,44 @@ export const DBTSetup = ({
}
};

const editWorkspace = async (data: DBTCreateWorkspaceParams) => {
if (data.schema && data.schema !== schema) {
const updateSchemaPayload = {
target_configs_schema: data.schema,
};
try {
await httpPut(session, 'dbt/schema/', updateSchemaPayload);
} catch (err: any) {
console.error(err);
errorToast(err.message, [], toastContext);
setSetupStatus('failed');
return;
}
}
if (data.gitrepoUrl) {
if (data.gitrepoUrl === gitrepoUrl && !data.gitrepoAccessToken) {
return;
}
const updateGitPayload = {
gitrepoUrl: data.gitrepoUrl,
gitrepoAccessToken: data.gitrepoAccessToken,
};
setExpandLogs(true);
try {
const message = await httpPut(session, 'dbt/github/', updateGitPayload);
setTimeout(() => {
checkProgress(message.task_id);
}, 1000);
} catch (err: any) {
console.error(err);
errorToast(err.message, [], toastContext);
setSetupStatus('failed');
}
} else {
setSetupStatus('completed');
}
};

const handleClose = () => {
reset();
setShowDialog(false);
Expand All @@ -126,6 +183,7 @@ export const DBTSetup = ({
data-testid="github-url"
label="GitHub repo URL"
variant="outlined"
defaultValue={gitrepoUrl}
register={register}
name="gitrepoUrl"
required
Expand All @@ -149,6 +207,7 @@ export const DBTSetup = ({
data-testid="dbt-target-schema"
label="dbt target schema"
variant="outlined"
defaultValue={schema}
register={register}
name="schema"
required
Expand Down
1 change: 0 additions & 1 deletion src/components/DBT/DBTTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export const DBTTarget = ({
)}
</Button>
))}
<Image src={SyncIcon} className={styles.SyncIcon} alt="sync icon" />
<Select
value={selectedBlock}
onChange={(event) => {
Expand Down
64 changes: 0 additions & 64 deletions src/components/DBT/__tests__/DBTCreateProfile.test.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Flows/Flows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ export const Flows = ({
open={open}
handleEdit={handleEditConnection}
handleClose={handleClose}
elementId={deploymentId}
handleDeleteConnection={handleDeleteConnection}
/>
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
Expand Down
1 change: 0 additions & 1 deletion src/components/Sources/Sources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export const Sources = () => {
anchorEl={anchorEl}
open={open}
handleClose={handleClose}
elementId={sourceToBeDeleted}
handleEdit={handleEditSource}
handleDeleteConnection={handleDeleteSource}
/>
Expand Down
21 changes: 12 additions & 9 deletions src/components/UI/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import DeleteIcon from '@/assets/icons/delete.svg';
interface MenuProps {
anchorEl: null | HTMLElement;
open: boolean;
eleType: 'flow' | 'source' | 'connection';
eleType: 'flow' | 'source' | 'connection' | 'dbtworkspace';
handleClose: () => void;
handleEdit?: () => void;
elementId: string;
handleDeleteConnection: () => void;
handleResetConnection?: () => void;
}
Expand Down Expand Up @@ -49,13 +48,17 @@ export const ActionsMenu: React.FC<MenuProps> = ({
</ListItemIcon>
Edit
</MenuItem>
<Divider style={{ margin: 0 }} />
<MenuItem onClick={() => handleDeleteConnection()}>
<ListItemIcon style={{ minWidth: 28 }}>
<Image src={DeleteIcon} alt="delete icon" />
</ListItemIcon>
Delete
</MenuItem>
{eleType !== 'dbtworkspace' && (
<>
<Divider style={{ margin: 0 }} />
<MenuItem onClick={() => handleDeleteConnection()}>
<ListItemIcon style={{ minWidth: 28 }}>
<Image src={DeleteIcon} alt="delete icon" />
</ListItemIcon>
Delete
</MenuItem>
</>
)}
<Divider style={{ margin: 0 }} />
{eleType === 'connection' && handleResetConnection && (
<MenuItem onClick={() => handleResetConnection()}>
Expand Down
Loading