Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Hofixes for the localunit #1624

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Conversation

shreeyash07
Copy link
Collaborator

@shreeyash07 shreeyash07 commented Jan 15, 2025

Summary

Small hotfixes for the locaunit

Addresses

  • Issue(s): No issues was Created

Depends On

Changes

  • Add new logic for the isNewLocalUnit
  • Remove pristine from LocalUnitValidationButton
  • Add missing form fields in localunit view component
  • Add global validator permission
  • Add check of the changes in localunitview component

This PR Ensures:

  • No typos or grammatical errors
  • No conflict markers left in the code
  • No unwanted comments, temporary files, or auto-generated files
  • No inclusion of secret keys or sensitive data
  • No console.log statements meant for debugging
  • All CI checks have passed

Copy link

changeset-bot bot commented Jan 15, 2025

⚠️ No Changeset found

Latest commit: 53d8804

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines 449 to 456
const isNewLocalUnit = useMemo(() => {
if (isObject(previousData)) {
if (Object.keys(previousData).length <= 0) {
return true;
}
}
return false;
}, [previousData]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isNewLocalUnit = useMemo(() => {
if (isObject(previousData)) {
if (Object.keys(previousData).length <= 0) {
return true;
}
}
return false;
}, [previousData]);
const isNewLocalUnit = useMemo(() => {
return isNotDefined(previousData) || Object.keys(previousData).length === 0;
}, [previousData]);

@@ -45,6 +45,8 @@ function usePermissions() {

const isSuperUser = !isGuestUser && !!userMe?.is_superuser;

const isGlobalValidator = !isGuestUser && !!userMe?.is_global_validator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this role generic or specific to local units?

Also I feel like this should be permission instead of role @thenav56 @tnagorra @samshara

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frozenhelium this is specific to local units.

Comment on lines +31 to +49
health,
...formValues
// Note: the cast is safe as we're only trying to
// remove fields if they exist
} = removeNull(value) as LocalUnitResponse;

const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_by_details: healthModifiedByDetails,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_at: healthModifiedAt,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_by: healthModifiedby,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
created_at: healthCreatedAt,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
created_by_details: healthCreatedByDetails,
...formHealthValues
} = health ?? {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
health,
...formValues
// Note: the cast is safe as we're only trying to
// remove fields if they exist
} = removeNull(value) as LocalUnitResponse;
const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_by_details: healthModifiedByDetails,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_at: healthModifiedAt,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_by: healthModifiedby,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
created_at: healthCreatedAt,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
created_by_details: healthCreatedByDetails,
...formHealthValues
} = health ?? {};
health = {},
...formValues
// Note: the cast is safe as we're only trying to
// remove fields if they exist
} = removeNull(value) as LocalUnitResponse;
const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_by_details: healthModifiedByDetails,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_at: healthModifiedAt,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
modified_by: healthModifiedby,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
created_at: healthCreatedAt,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
created_by_details: healthCreatedByDetails,
...formHealthValues
} = health;

Comment on lines +76 to +81
const newValueKeys = Object.keys(removeNull(newValue));
const oldValueKeys = Object.keys(removeNull(oldValue));

if (newValueKeys.length !== oldValueKeys.length) {
return true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets verify removeNull might not actually remove null, lets verify it

Alternatively we can check length for list of defined values only

// FIXME: Handle case when there is no change.
// We need to display message to the user
const hasDifference = useMemo(() => {
if (!newValue || !oldValue) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use isNotDefined just in case

@@ -0,0 +1,3 @@
.local-unit-view-children-container {
max-height: 36rem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we trying to set max-height? Lets use min function to ensure that it does not go beyond 100vh for smaller screens

@@ -430,22 +435,40 @@ function LocalUnitsForm(props: Props) {
const healthFormError = getErrorObject(error?.health);
const revertChangesFormError = getErrorObject(revertChangesError);

const previousData = (
localUnitPreviousResponse?.previous_data_details as unknown as LocalUnitResponse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add FIXME or NOTE why we're casting this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants