-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract UI helper components from DbtCloudTransformationsCard.tsx
I put a little effort into keeping all of the API interactions within the top-level component, and a linting rule required me to split out individual stylesheets for each helper component (plus one non-module scss file for shared card styles that individual scss modules can `@forward`)
- Loading branch information
1 parent
bfb5dc7
commit 9634479
Showing
13 changed files
with
317 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...es/connections/ConnectionTransformationPage/DbtCloudTransformationsCard/DbtCloudCard.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@use "scss/colors"; | ||
@use "scss/variables"; | ||
|
||
.cardTitle { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
.cardBodyContainer { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
padding: variables.$spacing-xl; | ||
background-color: colors.$grey-50; | ||
} | ||
|
||
.contextExplanation { | ||
color: colors.$grey-300; | ||
width: 100%; | ||
|
||
& a { | ||
color: colors.$grey-300; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ionTransformationPage/DbtCloudTransformationsCard/DbtCloudTransformationsCard.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@forward "./DbtCloudCard.scss"; |
5 changes: 5 additions & 0 deletions
5
...nections/ConnectionTransformationPage/DbtCloudTransformationsCard/DbtJobsForm.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@forward "./DbtCloudCard.scss"; | ||
|
||
.jobListForm { | ||
width: 100%; | ||
} |
91 changes: 91 additions & 0 deletions
91
...ages/connections/ConnectionTransformationPage/DbtCloudTransformationsCard/DbtJobsForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { faPlus } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { Form, Formik, FieldArray, FormikHelpers } from "formik"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import { FormChangeTracker } from "components/common/FormChangeTracker"; | ||
import { Button } from "components/ui/Button"; | ||
import { Card } from "components/ui/Card"; | ||
import { DropdownMenu } from "components/ui/DropdownMenu"; | ||
|
||
import { DbtCloudJobInfo } from "packages/cloud/lib/domain/dbtCloud"; | ||
import { DbtCloudJob, isSameJob } from "packages/cloud/services/dbtCloud"; | ||
|
||
import styles from "./DbtJobsForm.module.scss"; | ||
import { JobsList } from "./JobsList"; | ||
|
||
interface DbtJobListValues { | ||
jobs: DbtCloudJob[]; | ||
} | ||
|
||
interface DbtJobsFormProps { | ||
saveJobs: (jobs: DbtCloudJob[]) => Promise<unknown>; | ||
isSaving: boolean; | ||
dbtCloudJobs: DbtCloudJob[]; | ||
availableDbtCloudJobs: DbtCloudJobInfo[]; | ||
} | ||
|
||
export const DbtJobsForm: React.FC<DbtJobsFormProps> = ({ | ||
saveJobs, | ||
isSaving, | ||
dbtCloudJobs, | ||
availableDbtCloudJobs, | ||
}) => { | ||
const onSubmit = (values: DbtJobListValues, { resetForm }: FormikHelpers<DbtJobListValues>) => { | ||
saveJobs(values.jobs).then(() => resetForm({ values })); | ||
}; | ||
|
||
// because we don't store names for saved jobs, just the account and job IDs needed for | ||
// webhook operation, we have to find the display names for saved jobs by comparing IDs | ||
// with the list of available jobs as provided by dbt Cloud. | ||
const jobs = dbtCloudJobs.map((savedJob) => { | ||
const { jobName } = availableDbtCloudJobs.find((remoteJob) => isSameJob(remoteJob, savedJob)) || {}; | ||
const { accountId, jobId } = savedJob; | ||
|
||
return { accountId, jobId, jobName }; | ||
}); | ||
|
||
return ( | ||
<Formik | ||
onSubmit={onSubmit} | ||
initialValues={{ jobs }} | ||
render={({ values, dirty }) => { | ||
return ( | ||
<Form className={styles.jobListForm}> | ||
<FormChangeTracker changed={dirty} /> | ||
<FieldArray | ||
name="jobs" | ||
render={({ remove, push }) => { | ||
return ( | ||
<Card | ||
title={ | ||
<span className={styles.cardTitle}> | ||
<FormattedMessage id="connection.dbtCloudJobs.cardTitle" /> | ||
<DropdownMenu | ||
options={availableDbtCloudJobs | ||
.filter((remoteJob) => !values.jobs.some((savedJob) => isSameJob(remoteJob, savedJob))) | ||
.map((job) => ({ displayName: job.jobName, value: job }))} | ||
onChange={(selection) => { | ||
push(selection.value); | ||
}} | ||
> | ||
{() => ( | ||
<Button variant="secondary" icon={<FontAwesomeIcon icon={faPlus} />}> | ||
<FormattedMessage id="connection.dbtCloudJobs.addJob" /> | ||
</Button> | ||
)} | ||
</DropdownMenu> | ||
</span> | ||
} | ||
> | ||
<JobsList jobs={values.jobs} remove={remove} dirty={dirty} isLoading={isSaving} /> | ||
</Card> | ||
); | ||
}} | ||
/> | ||
</Form> | ||
); | ||
}} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.