Skip to content

Commit

Permalink
Merge pull request #1297 from DalgoT4D/update-github-pat
Browse files Browse the repository at this point in the history
show stars if git PAT exists
  • Loading branch information
Ishankoradia authored Nov 11, 2024
2 parents c0ee3e4 + cd68fea commit c066969
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/components/DBT/DBTSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface DBTSetupProps {
showDialog: boolean;
setShowDialog: (...args: any) => any;
gitrepoUrl: string;
gitrepoAccessToken: string;
schema: string;
mode: string;
setWorkspace: (...args: any) => any;
Expand All @@ -34,6 +35,7 @@ export const DBTSetup = ({
showDialog,
setShowDialog,
gitrepoUrl,
gitrepoAccessToken,
schema,
mode,
setWorkspace,
Expand All @@ -43,6 +45,7 @@ export const DBTSetup = ({
handleSubmit,
reset,
formState: { errors },
setValue,
} = useForm<DBTCreateWorkspaceParams>();
const { data: session }: any = useSession();
const [progressMessages, setProgressMessages] = useState<any[]>([]);
Expand Down Expand Up @@ -74,6 +77,12 @@ export const DBTSetup = ({
}
};

useEffect(() => {
setValue('gitrepoUrl', gitrepoUrl);
setValue('gitrepoAccessToken', gitrepoAccessToken);
setValue('schema', schema);
}, [gitrepoUrl, gitrepoAccessToken, schema]);

useEffect(() => {
setLogs(
progressMessages.map((msg) => `${msg.stepnum ? msg.stepnum + '. ' : ''}${msg.message}`)
Expand Down Expand Up @@ -156,20 +165,45 @@ export const DBTSetup = ({
}
}
if (data.gitrepoUrl) {
if (data.gitrepoUrl === gitrepoUrl && !data.gitrepoAccessToken) {
let changes = data.gitrepoUrl !== gitrepoUrl;
if (data.gitrepoAccessToken && !gitrepoAccessToken) {
// added an access token
changes = true;
}
if (gitrepoAccessToken && !data.gitrepoAccessToken) {
// removed an access token
changes = true;
}
if (
gitrepoAccessToken &&
data.gitrepoAccessToken &&
!data.gitrepoAccessToken.match(/^\*+$/)
) {
// changed an access token
changes = true;
}
if (!changes) {
return;
}
const updateGitPayload = {
gitrepoUrl: data.gitrepoUrl,
gitrepoAccessToken: data.gitrepoAccessToken,
gitrepoAccessToken: data.gitrepoAccessToken.match(/^\*+$/) ? null : data.gitrepoAccessToken,
};
setExpandLogs(true);
try {
const message = await httpPut(session, 'dbt/github/', updateGitPayload);
setWorkspace({
gitrepo_url: data.gitrepoUrl,
gitrepo_access_token: data.gitrepoAccessToken ? '*********' : null,
default_schema: data.schema,
});
if (data.gitrepoAccessToken) {
gitrepoAccessToken = '*********';
} else {
gitrepoAccessToken = '';
}
gitrepoUrl = data.gitrepoUrl;
schema = data.schema;
await delay(1000);

checkProgress(message.task_id, 'clone-github-repo');
Expand Down Expand Up @@ -197,7 +231,6 @@ export const DBTSetup = ({
data-testid="github-url"
label="GitHub repo URL"
variant="outlined"
defaultValue={gitrepoUrl}
register={register}
name="gitrepoUrl"
required
Expand Down Expand Up @@ -225,7 +258,6 @@ export const DBTSetup = ({
data-testid="dbt-target-schema"
label="dbt target schema"
variant="outlined"
defaultValue={schema}
register={register}
name="schema"
required
Expand Down
3 changes: 3 additions & 0 deletions src/components/DBT/DBTTransformType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type DBTSetupStage = 'create-workspace' | 'complete' | '';
const DBTTransformType = ({ transformType }: { transformType: TransformType }) => {
const [workspace, setWorkspace] = useState({
status: '',
gitrepo_access_token: '',
gitrepo_url: '',
default_schema: '',
});
Expand Down Expand Up @@ -384,6 +385,7 @@ const DBTTransformType = ({ transformType }: { transformType: TransformType }) =
showDialog={showConnectRepoDialog}
setShowDialog={setShowConnectRepoDialog}
gitrepoUrl=""
gitrepoAccessToken=""
schema=""
mode="create"
setWorkspace={setWorkspace}
Expand All @@ -398,6 +400,7 @@ const DBTTransformType = ({ transformType }: { transformType: TransformType }) =
showDialog={showConnectRepoDialog}
setShowDialog={setShowConnectRepoDialog}
gitrepoUrl={workspace?.gitrepo_url}
gitrepoAccessToken={workspace?.gitrepo_access_token}
schema={workspace?.default_schema}
mode="edit"
setWorkspace={setWorkspace}
Expand Down

0 comments on commit c066969

Please sign in to comment.