Skip to content

Commit

Permalink
Add isLocked check for the edit dropdown in table action
Browse files Browse the repository at this point in the history
  • Loading branch information
shreeyash07 authored and samshara committed Dec 18, 2024
1 parent fc7e9a5 commit 285dbd7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"successMessage": "Local unit added successfully!",
"revertChangesSuccessMessage": "Local unit reverted successfully!",
"failedMessage": "Failed to add local unit",
"revertChangesFailedMessage": "Failed to revert changes in local unit",
"revertChangesFailedMessage": "Failed to revert changes in the local unit",
"updateMessage": "Local unit updated successfully!",
"updateFailedMessage": "Failed to update local unit",
"specialitiesAndCapacityTitle": "Specialities & Capacity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ function LocalUnitsForm(props: Props) {

const readOnly = readOnlyFromProps
|| isNotDefined(localUnitDetailsResponse)
|| localUnitDetailsResponse?.is_locked;
|| localUnitDetailsResponse.is_locked;

const {
response: localUnitsOptions,
Expand Down Expand Up @@ -640,9 +640,8 @@ function LocalUnitsForm(props: Props) {

return (
<div className={styles.localUnitsForm}>
{!localUnitDetailsResponse?.is_locked
&& readOnlyFromProps
&& isNotDefined(localUnitDetailsResponse)
{isDefined(localUnitDetailsResponse)
&& !readOnly
&& isDefined(actionsContainerRef.current) && (
<Portal container={actionsContainerRef.current}>
{(environment !== 'production') && (
Expand Down Expand Up @@ -748,7 +747,7 @@ function LocalUnitsForm(props: Props) {
readOnly={!pristine}
/>
)}
{localUnitDetailsResponse?.is_locked && (
{localUnitDetailsResponse.is_locked && (
<Button
name={undefined}
onClick={setShowRevertChangesModalTrue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Props {
isValidated: boolean;
onDeleteActionSuccess: () => void;
onValidationActionSuccess: () => void;
isLocked: boolean;
}

function LocalUnitsTableActions(props: Props) {
Expand All @@ -40,6 +41,7 @@ function LocalUnitsTableActions(props: Props) {
isValidated,
onValidationActionSuccess,
onDeleteActionSuccess,
isLocked,
} = props;

const strings = useTranslation(i18n);
Expand Down Expand Up @@ -120,14 +122,6 @@ function LocalUnitsTableActions(props: Props) {
>
{strings.localUnitsView}
</DropdownMenuItem>
<DropdownMenuItem
type="button"
name={localUnitId}
onClick={handleEditLocalUnitClick}
disabled={isGuestUser}
>
{strings.localUnitsEdit}
</DropdownMenuItem>
{hasDeletePermission && (
<DropdownMenuItem
type="button"
Expand All @@ -137,6 +131,16 @@ function LocalUnitsTableActions(props: Props) {
{strings.localUnitsDelete}
</DropdownMenuItem>
)}
{!isLocked && (
<DropdownMenuItem
type="button"
name={localUnitId}
onClick={handleEditLocalUnitClick}
disabled={isGuestUser}
>
{strings.localUnitsEdit}
</DropdownMenuItem>
)}
</>
)}
>
Expand All @@ -153,6 +157,7 @@ function LocalUnitsTableActions(props: Props) {
name={localUnitId}
variant="tertiary"
onClick={handleViewLocalUnitClick}
disabled={isGuestUser}
>
{strings.localUnitsView}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function LocalUnitsTable(props: Props) {
countryId: item.country,
localUnitId: item.id,
isValidated: item.validated,
isLocked: item.is_locked,
localUnitName: getFirstTruthyString(
item.local_branch_name,
item.english_branch_name,
Expand Down

0 comments on commit 285dbd7

Please sign in to comment.