Fix: Use domain name as key for editing and deleting
Publish Docker image / build-and-push (push) Successful in 1m34s
Publish Docker image / build-and-push (push) Successful in 1m34s
This commit is contained in:
+18
-17
@@ -12,7 +12,7 @@ function App() {
|
|||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
const [success, setSuccess] = useState('')
|
const [success, setSuccess] = useState('')
|
||||||
const [searchTerm, setSearchTerm] = useState('')
|
const [searchTerm, setSearchTerm] = useState('')
|
||||||
const [editingIndex, setEditingIndex] = useState(null)
|
const [editingDomain, setEditingDomain] = useState(null)
|
||||||
const [editingValue, setEditingValue] = useState('')
|
const [editingValue, setEditingValue] = useState('')
|
||||||
const [bulkFrom, setBulkFrom] = useState('SharkFIN')
|
const [bulkFrom, setBulkFrom] = useState('SharkFIN')
|
||||||
const [bulkTo, setBulkTo] = useState('SharkAM')
|
const [bulkTo, setBulkTo] = useState('SharkAM')
|
||||||
@@ -41,24 +41,25 @@ function App() {
|
|||||||
setNewDomain({ domain: '', type: 'SharkFIN' })
|
setNewDomain({ domain: '', type: 'SharkFIN' })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleEdit = (index) => {
|
const handleEdit = (domain) => {
|
||||||
setEditingIndex(index)
|
setEditingDomain(domain.domain)
|
||||||
setEditingValue(domains[index].type)
|
setEditingValue(domain.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSaveEdit = (index) => {
|
const handleSaveEdit = (domainName) => {
|
||||||
const updatedDomains = [...domains]
|
const updatedDomains = domains.map(d =>
|
||||||
updatedDomains[index].type = editingValue
|
d.domain === domainName ? { ...d, type: editingValue } : d
|
||||||
|
)
|
||||||
setDomains(updatedDomains)
|
setDomains(updatedDomains)
|
||||||
setEditingIndex(null)
|
setEditingDomain(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCancelEdit = () => {
|
const handleCancelEdit = () => {
|
||||||
setEditingIndex(null)
|
setEditingDomain(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDeleteDomain = (index) => {
|
const handleDeleteDomain = (domainNameToDelete) => {
|
||||||
setDomains(domains.filter((_, i) => i !== index))
|
setDomains(domains.filter(d => d.domain !== domainNameToDelete))
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSaveChanges = async () => {
|
const handleSaveChanges = async () => {
|
||||||
@@ -194,11 +195,11 @@ function App() {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{filteredDomains.map((d, index) => (
|
{filteredDomains.map((d, index) => (
|
||||||
<tr key={index}>
|
<tr key={d.domain}>
|
||||||
<td>{index + 1}</td>
|
<td>{index + 1}</td>
|
||||||
<td>{d.domain}</td>
|
<td>{d.domain}</td>
|
||||||
<td>
|
<td>
|
||||||
{editingIndex === index ? (
|
{editingDomain === d.domain ? (
|
||||||
<Form.Control
|
<Form.Control
|
||||||
type="text"
|
type="text"
|
||||||
value={editingValue}
|
value={editingValue}
|
||||||
@@ -210,9 +211,9 @@ function App() {
|
|||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-center">
|
<td className="text-center">
|
||||||
{editingIndex === index ? (
|
{editingDomain === d.domain ? (
|
||||||
<>
|
<>
|
||||||
<Button variant="success" size="sm" className="me-2" onClick={() => handleSaveEdit(index)}>
|
<Button variant="success" size="sm" className="me-2" onClick={() => handleSaveEdit(d.domain)}>
|
||||||
Сохранить
|
Сохранить
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="secondary" size="sm" onClick={handleCancelEdit}>
|
<Button variant="secondary" size="sm" onClick={handleCancelEdit}>
|
||||||
@@ -221,10 +222,10 @@ function App() {
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Button variant="info" size="sm" className="me-2" onClick={() => handleEdit(index)}>
|
<Button variant="info" size="sm" className="me-2" onClick={() => handleEdit(d)}>
|
||||||
Изменить
|
Изменить
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="danger" size="sm" onClick={() => handleDeleteDomain(index)}>
|
<Button variant="danger" size="sm" onClick={() => handleDeleteDomain(d.domain)}>
|
||||||
Удалить
|
Удалить
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user