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(ui): handle null oldObj in deepDiff to prevent refresh failure #515

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions web/ui/react-app/src/components/approvals/service-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export const ServiceInfo: FC<Props> = ({
() => ({
// If the version hasn't been found.
not_found:
isEmptyOrNull(service?.status?.deployed_version) ||
isEmptyOrNull(service?.status?.latest_version) ||
isEmptyOrNull(service?.status?.last_queried),
isEmptyOrNull(service.status?.deployed_version) ||
isEmptyOrNull(service.status?.latest_version) ||
isEmptyOrNull(service.status?.last_queried),
// If a new version has been found (and not skipped).
warning: updateAvailable && !updateSkipped,
// If the latest version is the same as the approved version.
Expand Down
2 changes: 1 addition & 1 deletion web/ui/react-app/src/utils/is-empty-or-null.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param value - The value to check.
* @returns true when value is empty, null, or undefined. false otherwise.
*/
const isEmptyOrNull = (value: unknown): boolean => {
const isEmptyOrNull = (value: unknown): value is null | undefined | '' => {
return (value ?? '') === '';
};

Expand Down
5 changes: 3 additions & 2 deletions web/ui/react-app/src/utils/query-params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

import { ArgType } from 'types/service-edit';
import { isEmptyObject } from './is-empty';
import isEmptyOrNull from './is-empty-or-null';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type DiffObject = { [key: string]: any };
Expand All @@ -22,9 +23,9 @@ export const deepDiff = (
): DiffObject => {
const diff: DiffObject = {};

// If oldObj undefined, return newObj,
// If oldObj empty/undefined/null, return newObj,
// e.g. DeployedVersion has no defaults.
if (oldObj === undefined) return newObj;
if (isEmptyOrNull(oldObj)) return newObj;

// get all keys from both objects.
const keys = Object.keys(oldObj).concat(Object.keys(newObj));
Expand Down
Loading