-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add button to prompt for arbitrary urls for batch tagging
- Loading branch information
1 parent
efd6e0a
commit 25012b5
Showing
3 changed files
with
115 additions
and
2 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
69 changes: 69 additions & 0 deletions
69
public/components/BatchTagControls/BatchTagArbitraryUrls.js
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,69 @@ | ||
import React, {useState} from "react"; | ||
|
||
export const BatchTagArbitraryUrls = ({addPathsToSelection}) => { | ||
|
||
const [isModalDisplayed, setIsModalDisplayed] = useState(false); | ||
|
||
const [input, setInput] = useState("") // string | ||
const [treated, setTreated] = useState(); // string[] | ||
|
||
const close = () => { | ||
setInput(""); | ||
setTreated(null); | ||
setIsModalDisplayed(false); | ||
} | ||
const treat = () => setTreated([...new Set( | ||
input.split("\n").map(url => { | ||
if(url.startsWith("http")){ | ||
return url.trim().split("/").slice(3).join("/"); | ||
} | ||
return url.trim(); // already just the path | ||
}) | ||
)]); | ||
|
||
const complete = () => { | ||
addPathsToSelection(treated); | ||
close(); | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
{isModalDisplayed && ( | ||
<div className="batch-tag__arbitrary_modal_background"> | ||
<div className="batch-tag__arbitrary_modal_content"> | ||
<div><strong>{treated | ||
? "Please check the paths extracted from the web URLs you entered" | ||
: "Enter web URLs (one per line)" | ||
}</strong></div> | ||
<textarea | ||
className="batch-tag__arbitrary_modal_input" | ||
rows={15} | ||
value={treated ? treated.join("\n") : input} | ||
onChange={({target}) => setInput(target.value)} | ||
disabled={!!treated} | ||
/> | ||
<div className="batch-tag__arbitrary_modal_button_bar"> | ||
<button className="batch-tag__arbitrary_button" onClick={close}>Cancel</button> | ||
{treated ? ( | ||
<div> | ||
<button className="batch-tag__arbitrary_button--red" onClick={() => setTreated(null)}> | ||
Back | ||
</button> | ||
{" "} | ||
<button className="batch-tag__arbitrary_button--green" disabled={!input} onClick={complete}> | ||
Add {treated.length} unique rows | ||
</button> | ||
</div> | ||
) : ( | ||
<button className="batch-tag__arbitrary_button--green" disabled={!input} onClick={treat}> | ||
Next | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
<button className="batch-tag__arbitrary_button" onClick={() => setIsModalDisplayed(true)}>Add arbitrary URLs</button> | ||
</React.Fragment> | ||
); | ||
} |
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