-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor sap system and database reducers (#1745)
* Refactor sap system and database reducers * Destructure and rename signature variables * Rename to instancesMatch
- Loading branch information
1 parent
1fb9109
commit bea6a7c
Showing
24 changed files
with
803 additions
and
295 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,21 +1,22 @@ | ||
const payloadMatchesInstance = (payload, instance) => | ||
payload.sap_system_id === instance.sap_system_id && | ||
payload.host_id === instance.host_id && | ||
payload.instance_number === instance.instance_number; | ||
export const instancesMatch = (instance1, instance2) => | ||
instance1.sap_system_id === instance2.sap_system_id && | ||
instance1.host_id === instance2.host_id && | ||
instance1.instance_number === instance2.instance_number; | ||
|
||
const filterByInstances = (currentInstances, newInstances) => | ||
currentInstances.filter((currentInstance) => | ||
newInstances.every( | ||
(newInstance) => !payloadMatchesInstance(newInstance, currentInstance) | ||
(newInstance) => !instancesMatch(newInstance, currentInstance) | ||
) | ||
); | ||
|
||
export const upsertInstances = (currentInstances, newInstances) => | ||
filterByInstances(currentInstances, newInstances).concat(newInstances); | ||
|
||
export const maybeUpdateInstanceHealth = (payload, instance) => { | ||
if (payloadMatchesInstance(payload, instance)) { | ||
instance.health = payload.health; | ||
} | ||
return instance; | ||
}; | ||
export const updateInstance = (instances, instanceToUpdate, data) => | ||
instances.map((instance) => { | ||
if (instancesMatch(instanceToUpdate, instance)) { | ||
return { ...instance, ...data }; | ||
} | ||
return instance; | ||
}); |
Oops, something went wrong.