...
This commit is contained in:
@@ -45,7 +45,7 @@ const SipParams = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
//url params comes here name and id
|
||||
const profileParam = useParams();
|
||||
const [editingRow, setEditingRow] = useState(null);
|
||||
const [editingRow, setEditingRow] = useState<string | null>(null);
|
||||
//grid data comes here
|
||||
const [rowData, setRowData] = useState<any>([]);
|
||||
//skeleton loading state for reRendering Form
|
||||
@@ -74,6 +74,9 @@ const SipParams = () => {
|
||||
//create and update data from store here
|
||||
const [state, setState] = useState<any>(initialState);
|
||||
|
||||
const getRowKey = (row: Pick<InputItem, "ParamType" | "parameter">) =>
|
||||
JSON.stringify([row.ParamType, row.parameter]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
//grid Cols
|
||||
const columns = [
|
||||
@@ -425,6 +428,7 @@ const SipParams = () => {
|
||||
|
||||
//Delete params from grid
|
||||
function DeleteRow(params: any) {
|
||||
const rowKey = getRowKey(params.data);
|
||||
return (
|
||||
<>
|
||||
<FiEdit
|
||||
@@ -432,9 +436,9 @@ const SipParams = () => {
|
||||
className="mx-2 edit-icon"
|
||||
// Only call handleEditRow if the row is not currently being edited
|
||||
onClick={() => {
|
||||
if (editingRow !== params.data.parameter) {
|
||||
if (editingRow !== rowKey) {
|
||||
handleEditRow(params.data);
|
||||
setEditingRow(params.data.parameter);
|
||||
setEditingRow(rowKey);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
@@ -442,17 +446,23 @@ const SipParams = () => {
|
||||
style={{ paddingLeft: "8px" }}
|
||||
className="delete-icon"
|
||||
onClick={() => {
|
||||
const rowIndexInOriginalData = rowData.findIndex(
|
||||
(row: any) => row.parameter === params.data.parameter
|
||||
setRowData((currentRows: InputItem[]) =>
|
||||
currentRows.filter((row) => getRowKey(row) !== rowKey)
|
||||
);
|
||||
if (rowIndexInOriginalData !== -1) {
|
||||
const updatedRowData = [...rowData];
|
||||
updatedRowData.splice(rowIndexInOriginalData, 1);
|
||||
setRowData(updatedRowData);
|
||||
// Check if the row being deleted is the one being edited, and reset the editing state
|
||||
if (editingRow === rowIndexInOriginalData) {
|
||||
setEditingRow(null);
|
||||
}
|
||||
setSelected((currentRows: InputItem[]) =>
|
||||
currentRows.filter((row) => getRowKey(row) !== rowKey)
|
||||
);
|
||||
setState((currentState: any) => {
|
||||
const updatedType = { ...currentState[params.data.ParamType] };
|
||||
delete updatedType[params.data.parameter];
|
||||
return { ...currentState, [params.data.ParamType]: updatedType };
|
||||
});
|
||||
if (editingRow === rowKey) {
|
||||
setEditingRow(null);
|
||||
setMode(false);
|
||||
setSelectedParamType(null);
|
||||
setSelectedParam([]);
|
||||
setRenderedFormControls([]);
|
||||
}
|
||||
}}
|
||||
size={28}
|
||||
@@ -570,6 +580,7 @@ const SipParams = () => {
|
||||
|
||||
if (mode) {
|
||||
setMode(false);
|
||||
setEditingRow(null);
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -660,6 +671,7 @@ const SipParams = () => {
|
||||
onChange={(e: any) => {
|
||||
if (mode) {
|
||||
setMode(false);
|
||||
setEditingRow(null);
|
||||
}
|
||||
handleParamChange(e);
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user