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
Visual Experiments - Add EditDOMMutations modal #1394
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f0fc050
Add EditDOMMutations modal
bttf 96d26e8
Use edit link; Add bypass
bttf 493400c
Refine
bttf 55e4125
Merge branch 'main' into adnan/delete-visual-change-modal
bttf fca7e02
Try this
bttf c23f91b
Merge branch 'main' into adnan/delete-visual-change-modal
bttf e918e68
Merge branch 'adnan/delete-visual-change-modal' of https://github.com…
bttf File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
packages/front-end/components/Experiment/EditDOMMutationsModal.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,130 @@ | ||
import { VisualChange } from "back-end/types/visual-changeset"; | ||
import { FC, useCallback, useState } from "react"; | ||
import Code from "@/components/SyntaxHighlighting/Code"; | ||
import Modal from "../Modal"; | ||
|
||
const EditDOMMutatonsModal: FC<{ | ||
visualChange: VisualChange; | ||
close: () => void; | ||
onSave: (newVisualChange: VisualChange) => void; | ||
}> = ({ close, visualChange, onSave }) => { | ||
const [newVisualChange, setNewVisualChange] = useState<VisualChange>( | ||
visualChange | ||
); | ||
|
||
const deleteCustomJS = useCallback(() => { | ||
setNewVisualChange({ | ||
...newVisualChange, | ||
js: "", | ||
}); | ||
}, [newVisualChange, setNewVisualChange]); | ||
|
||
const deleteGlobalCSS = useCallback(() => { | ||
setNewVisualChange({ | ||
...newVisualChange, | ||
css: "", | ||
}); | ||
}, [newVisualChange, setNewVisualChange]); | ||
|
||
const deleteDOMMutation = useCallback( | ||
(index: number) => { | ||
setNewVisualChange({ | ||
...newVisualChange, | ||
domMutations: newVisualChange.domMutations.filter( | ||
(_m, i) => i !== index | ||
), | ||
}); | ||
}, | ||
[newVisualChange, setNewVisualChange] | ||
); | ||
|
||
const onSubmit = () => { | ||
onSave(newVisualChange); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
open | ||
close={close} | ||
size="lg" | ||
header="Remove Visual Changes" | ||
submit={onSubmit} | ||
cta="Save" | ||
> | ||
<div> | ||
<div className="mb-4"> | ||
<h4> | ||
Global CSS | ||
{newVisualChange.css ? ( | ||
<small className="ml-2"> | ||
<a href="#" className="text-danger" onClick={deleteGlobalCSS}> | ||
delete | ||
bttf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</a> | ||
</small> | ||
) : null} | ||
</h4> | ||
{newVisualChange.css ? ( | ||
<Code | ||
language="css" | ||
code={newVisualChange.css} | ||
className="disabled" | ||
/> | ||
) : ( | ||
<div className="text-muted font-italic">(None)</div> | ||
)} | ||
</div> | ||
|
||
<div className="mb-4"> | ||
<h4> | ||
Custom JS | ||
{newVisualChange.js ? ( | ||
<small className="ml-2"> | ||
<a href="#" className="text-danger" onClick={deleteCustomJS}> | ||
delete | ||
</a> | ||
</small> | ||
) : null} | ||
</h4> | ||
{newVisualChange.js ? ( | ||
<Code | ||
language="javascript" | ||
code={newVisualChange.js ?? ""} | ||
className="disabled" | ||
/> | ||
) : ( | ||
<div className="text-muted font-italic">(None)</div> | ||
)} | ||
</div> | ||
|
||
<div className="mb-4"> | ||
<h4>DOM Mutations</h4> | ||
|
||
{newVisualChange.domMutations.length ? ( | ||
newVisualChange.domMutations.map((m, i) => ( | ||
<div key={i} className="d-flex flex-column align-items-end"> | ||
<a | ||
className="text-danger" | ||
href="#" | ||
onClick={() => deleteDOMMutation(i)} | ||
style={{ marginBottom: "-.5rem", fontSize: "0.75rem" }} | ||
> | ||
delete | ||
</a> | ||
<Code | ||
language="json" | ||
code={JSON.stringify(m)} | ||
className="disabled" | ||
containerClassName="w-100" | ||
/> | ||
</div> | ||
)) | ||
) : ( | ||
<div className="text-muted font-italic">(None)</div> | ||
)} | ||
</div> | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default EditDOMMutatonsModal; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: useCallback for these seems unnecessary, as it's a very inexpensive operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. It comes from a force of habit. I don't equate
useCallback
as a thing to use when something is expensive but rather when 'we don't need to redefine this function per render'