-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Form to add a system via yaml (#1062)
* Add new system page * Refactor YamlForm so it can be reused * Fixup some types in existing system slice * Add SystemYamlForm * Add cypress test for system * Update changelog * Fix empty state and remove ellipsis for now * Remove tests on more actions button * Move changelog items to Unreleased
- Loading branch information
1 parent
29a9803
commit f31e96a
Showing
17 changed files
with
415 additions
and
143 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
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
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
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,31 @@ | ||
{ | ||
"fides_key": "demo_analytics_system", | ||
"organization_fides_key": "default_organization", | ||
"tags": null, | ||
"name": "Demo Analytics System", | ||
"description": "A system used for analyzing customer behaviour.", | ||
"registry_id": null, | ||
"meta": null, | ||
"fidesctl_meta": null, | ||
"system_type": "Service", | ||
"data_responsibility_title": "Controller", | ||
"privacy_declarations": [ | ||
{ | ||
"name": "Analyze customer behaviour for improvements.", | ||
"data_categories": ["user.contact", "user.device.cookie_id"], | ||
"data_use": "improve.system", | ||
"data_qualifier": "aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified", | ||
"data_subjects": ["customer"], | ||
"dataset_references": ["demo_users_dataset"] | ||
} | ||
], | ||
"system_dependencies": null, | ||
"joint_controller": null, | ||
"third_country_transfers": ["USA", "CAN"], | ||
"administrating_department": "Engineering", | ||
"data_protection_impact_assessment": { | ||
"is_required": true, | ||
"progress": "Complete", | ||
"link": "https://example.org/analytics_system_data_protection_impact_assessment" | ||
} | ||
} |
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,101 @@ | ||
import { Box, Button, Text } from "@fidesui/react"; | ||
import { Form, Formik, FormikHelpers } from "formik"; | ||
import yaml from "js-yaml"; | ||
|
||
import { CustomTextArea } from "~/features/common/form/inputs"; | ||
import { getErrorMessage, isYamlException } from "~/features/common/helpers"; | ||
import { RTKResult } from "~/features/common/types"; | ||
|
||
const initialValues = { yaml: "" }; | ||
type FormValues = typeof initialValues; | ||
|
||
interface Props<T> { | ||
description: string; | ||
submitButtonText: string; | ||
onCreate: (yaml: unknown) => RTKResult<T>; | ||
onSuccess: (data: T) => void; | ||
} | ||
|
||
const YamlForm = <T extends unknown>({ | ||
description, | ||
submitButtonText, | ||
onCreate, | ||
onSuccess, | ||
}: Props<T>) => { | ||
const handleCreate = async ( | ||
newValues: FormValues, | ||
formikHelpers: FormikHelpers<FormValues> | ||
) => { | ||
const { setErrors } = formikHelpers; | ||
const parsedYaml = yaml.load(newValues.yaml, { json: true }); | ||
const result = await onCreate(parsedYaml); | ||
|
||
if ("error" in result) { | ||
const errorMessage = getErrorMessage(result.error); | ||
setErrors({ yaml: errorMessage }); | ||
} else if ("data" in result) { | ||
onSuccess(result.data); | ||
} | ||
}; | ||
|
||
const validate = (newValues: FormValues) => { | ||
try { | ||
const parsedYaml = yaml.load(newValues.yaml, { json: true }); | ||
if (!parsedYaml) { | ||
return { yaml: "Could not parse the supplied YAML" }; | ||
} | ||
} catch (error) { | ||
if (isYamlException(error)) { | ||
return { | ||
yaml: `Could not parse the supplied YAML: \n\n${error.message}`, | ||
}; | ||
} | ||
return { yaml: "Could not parse the supplied YAML" }; | ||
} | ||
return {}; | ||
}; | ||
|
||
return ( | ||
<Formik | ||
initialValues={initialValues} | ||
validate={validate} | ||
onSubmit={handleCreate} | ||
validateOnChange={false} | ||
validateOnBlur={false} | ||
> | ||
{({ isSubmitting }) => ( | ||
<Form> | ||
<Text size="sm" color="gray.700" mb={4}> | ||
{description} | ||
</Text> | ||
{/* note: the error is more helpful in a monospace font, so apply Menlo to the whole Box */} | ||
<Box mb={4} whiteSpace="pre-line" fontFamily="Menlo"> | ||
<CustomTextArea | ||
name="yaml" | ||
textAreaProps={{ | ||
fontWeight: 400, | ||
lineHeight: "150%", | ||
color: "gray.800", | ||
fontSize: "13px", | ||
height: "50vh", | ||
width: "100%", | ||
mb: "2", | ||
}} | ||
/> | ||
</Box> | ||
<Button | ||
size="sm" | ||
colorScheme="primary" | ||
type="submit" | ||
disabled={isSubmitting} | ||
data-testid="submit-yaml-btn" | ||
> | ||
{submitButtonText} | ||
</Button> | ||
</Form> | ||
)} | ||
</Formik> | ||
); | ||
}; | ||
|
||
export default YamlForm; |
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import { RTKErrorResult } from "~/types/errors"; | ||
|
||
export interface TreeNode { | ||
label: string; | ||
value: string; | ||
children: TreeNode[]; | ||
} | ||
|
||
export type RTKResult<T> = Promise< | ||
| { | ||
data: T; | ||
} | ||
| { error: RTKErrorResult["error"] } | ||
>; |
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
Oops, something went wrong.