-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hma][UI] Refactor Banks Page (#1652)
- Loading branch information
1 parent
ca987f8
commit 403308b
Showing
8 changed files
with
288 additions
and
201 deletions.
There are no files selected for viewing
89 changes: 0 additions & 89 deletions
89
hasher-matcher-actioner/src/OpenMediaMatch/templates/components/add_to_bank_form.html.j2
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
hasher-matcher-actioner/src/OpenMediaMatch/templates/components/banks/actions_bar.html.j2
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,6 @@ | ||
<div class="mt-4 mb-4"> | ||
{% include "components/banks/match_form.html.j2" %} | ||
<div class="d-flex mt-5 mb-4 justify-content-end"> | ||
{% include 'components/banks/create_new_bank.html.j2' %} | ||
</div> | ||
</div> |
37 changes: 37 additions & 0 deletions
37
...r-matcher-actioner/src/OpenMediaMatch/templates/components/banks/add_to_bank_form.html.j2
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,37 @@ | ||
{# Copyright (c) Meta Platforms, Inc. and affiliates. #} | ||
<button type="button" class="btn btn-light" data-bs-toggle="modal" data-bs-target="#{{bank_title}}">Add content</button> | ||
<!-- Modal --> | ||
<div class="modal fade" id="{{bank_title}}" tabindex="-1"> | ||
<div class="modal-dialog modal-dialog-centered modal-xl" style="width: 60%; max-width: none;"> | ||
<div class="modal-content modal-xl" style="padding: 20px"> | ||
<form id="add_content_to_bank_{{ bank_title }}"> | ||
<div class="modal-header"> | ||
<h1 class="modal-title fs-5">Add Content: {{ bank_title }}</h1> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="row" style="width: 80%"> | ||
<input class="form-control" type="file" name="file" required style="margin-bottom: 20px"> | ||
<select class="form-select" name="content_type" required> | ||
<option selected disabled value="">Select content type</option> | ||
{% for c in content %} | ||
{% if c['enabled'] %} | ||
<option value="{{c['name']}}">{{c['name'].capitalize()}}</option> | ||
{% endif %} | ||
{% endfor %} | ||
</select> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="submit" class="btn btn-success">Add</button> | ||
</div> | ||
</form> | ||
<div id="hash_result_{{ bank_title }}"> | ||
<!-- Added to by javascript --> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script> | ||
</script> |
121 changes: 121 additions & 0 deletions
121
hasher-matcher-actioner/src/OpenMediaMatch/templates/components/banks/banks_grid.html.j2
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,121 @@ | ||
{# Copyright (c) Meta Platforms, Inc. and affiliates. #} | ||
<h1>Banks</h1> | ||
<p class="text-secondary">Banks are like folders. You can do the following on this page:</p> | ||
<ul class="text-secondary"> | ||
<li>Create new banks</li> | ||
<li>Add content: Add content to each bank</li> | ||
<li>Search by content: Find banks that contain a certain piece of content</li> | ||
</ul> | ||
{% include 'components/banks/actions_bar.html.j2' %} | ||
|
||
<div class="row row-cols-1 row-cols-md-4 g-4"> | ||
<table class="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Bank Name</th> | ||
<th scope="col">Matching Enabled Ratio</th> | ||
<th scope="col">Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for bank in bankList %} | ||
<tr id="bank_item_{{bank['name']}}"> | ||
<th scope="row" style="background-color: transparent;">{{ loop.index }}</th> | ||
<td style="background-color: transparent;">{{ bank['name'] }}</td> | ||
<td style="background-color: transparent;">{{ bank['matching_enabled_ratio'] }}</td> | ||
<td style="background-color: transparent;"> | ||
{% with bank_title=bank['name'] %} | ||
{% include 'components/banks/add_to_bank_form.html.j2' %} | ||
{% endwith %} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
|
||
</table> | ||
</div> | ||
<script> | ||
const banksData = [ | ||
{% for bank in bankList %} | ||
{ | ||
name: "{{ bank.name|e }}" | ||
}{% if not loop.last %},{% endif %} | ||
{% endfor %} | ||
]; | ||
banksData.forEach(function(bank) { | ||
const bankTitle=bank.name; | ||
const addContentModal = document.getElementById(bankTitle); | ||
const addContentToBankForm = document.getElementById("add_content_to_bank_" + bankTitle); | ||
const formContent = addContentToBankForm.innerHTML; | ||
addContentToBankForm.addEventListener("submit", (event) => { | ||
event.preventDefault(); | ||
const formData = new FormData(event.target); | ||
formData.append(event.target.content_type.value, event.target.file.files[0]); | ||
formData.delete("file"); | ||
fetch(`/c/bank/${bankTitle}/content`, { | ||
method: 'POST', | ||
body: formData | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
// Handle the response from the server here | ||
renderAddBankResult(data); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
}) | ||
// reset modal innerHTML | ||
addContentModal.addEventListener('hidden.bs.modal', function () { | ||
addContentToBankForm.innerHTML = formContent; | ||
}); | ||
const renderAddBankResult = (result) => { | ||
// Render hashes table | ||
const hashTable = HashTable(result); | ||
// render on HTML | ||
addContentToBankForm.innerHTML = hashTable; | ||
} | ||
const HashTable = (result) => { | ||
return ` | ||
<div class="modal-header"> | ||
<h3 class="text-success">Success!</h3> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<h4>Added Hashes:</h4> | ||
<p>Content ID: ${result.id}</p> | ||
<h4>Hash Values:</h4> | ||
<table class="table table-hover" => | ||
<thead> | ||
<tr> | ||
<th>Key</th> | ||
<th>Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
${Object.entries(result.signals).map(([key, value]) => ` | ||
<tr> | ||
<td>${key}</td> | ||
<td style="overflow: scroll; max-width: 200px; white-space: no-wrap;">${value}</td> | ||
</tr> | ||
`).join('')} | ||
</tbody> | ||
</table> | ||
</div> | ||
`; | ||
} | ||
}); | ||
</script> |
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.