-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add diff table to location list (#661)
- Loading branch information
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/frinx-gamma/src/pages/location-list/location-helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { CustomerLocation } from '../../network-types'; | ||
|
||
export type Status = 'CREATED' | 'UPDATED' | 'DELETED' | 'NO_CHANGE'; | ||
|
||
export type CustomerLocationWithStatus = CustomerLocation & { status: Status }; | ||
|
||
export function getChangedLocationsWithStatus( | ||
createdLocations: CustomerLocation[] | null, | ||
updatedLocations: CustomerLocation[] | null, | ||
deletedLocations: CustomerLocation[] | null, | ||
): CustomerLocationWithStatus[] { | ||
const createdDevicesWithStatus: CustomerLocationWithStatus[] = | ||
createdLocations?.map((location) => { | ||
return { | ||
...location, | ||
status: 'CREATED', | ||
}; | ||
}) || []; | ||
|
||
const updatedDevicesWithStatus: CustomerLocationWithStatus[] = | ||
updatedLocations?.map((location) => { | ||
return { | ||
...location, | ||
status: 'UPDATED', | ||
}; | ||
}) || []; | ||
|
||
const deletedDevicesWithStatus: CustomerLocationWithStatus[] = | ||
deletedLocations?.map((location) => { | ||
return { | ||
...location, | ||
status: 'DELETED', | ||
}; | ||
}) || []; | ||
|
||
return [...createdDevicesWithStatus, ...updatedDevicesWithStatus, ...deletedDevicesWithStatus]; | ||
} | ||
|
||
export function getSavedLocationsWithStatus( | ||
locations: CustomerLocation[] | null, | ||
updatedLocations: CustomerLocation[] | null, | ||
deletedLocations: CustomerLocation[] | null, | ||
): CustomerLocationWithStatus[] { | ||
return ( | ||
locations?.map((location) => { | ||
const updatedSite = updatedLocations?.filter((i) => i.locationId === location.locationId) || []; | ||
if (updatedSite.length) { | ||
return { | ||
...updatedSite[0], | ||
status: 'UPDATED', | ||
}; | ||
} | ||
|
||
const deletedSite = deletedLocations?.filter((i) => i.locationId === location.locationId) || []; | ||
if (deletedSite.length) { | ||
return { | ||
...deletedSite[0], | ||
status: 'DELETED', | ||
}; | ||
} | ||
|
||
return { | ||
...location, | ||
status: 'NO_CHANGE', | ||
}; | ||
}) || [] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters