Skip to content

Commit

Permalink
Improve parent/child tracking reactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-eyds committed Jun 5, 2024
1 parent 6f1756e commit f2a62d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ppr-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ppr-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ppr-ui",
"version": "3.2.8",
"version": "3.2.10",
"private": true,
"appName": "Assets UI",
"sbcName": "SBC Common Components",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ import { useStore } from '@/store/store'
import { storeToRefs } from 'pinia'
import { confirmRemoveNoticeDialog } from '@/resources/dialogOptions'
import { BaseDialog } from '@/components/dialogs'
import { cloneDeep, isEqual } from 'lodash'
import { cloneDeep, isEqual, omit } from 'lodash'
/** Composables **/
const { setSecuritiesActNotices, setSecuritiesActNoticeOrder } = useStore()
Expand Down Expand Up @@ -482,14 +482,15 @@ const removeOrder = (noticeIndex: number, orderIndex: number) => {
} else {
// Remove New/Added Orders
orders.splice(orderIndex, 1)
setSecuritiesActNotices([...getSecuritiesActNotices.value])
setAndCloseNotice(true)
}
}
/** Handle notice form edits **/
const handleEditNotice = (notice: AddEditSaNoticeIF, isUndo = false): void => {
// Set add edit notices
getSecuritiesActNotices.value[props.noticeIndex] = cloneDeep(notice)
const editNotice = !notice.effectiveDateTime ? omit(notice, 'effectiveDateTime') : notice
getSecuritiesActNotices.value[props.noticeIndex] = cloneDeep(editNotice)
setAndCloseNotice(isUndo)
}
Expand All @@ -499,15 +500,15 @@ const handleAddEditOrder = (order: CourtOrderIF, orderIndex: number = null, isUn
// Handle Undo
if (isUndo) {
setSecuritiesActNoticeOrder(props.noticeIndex, orderIndex, order)
setSecuritiesActNoticeOrder(props.noticeIndex, orderIndex, omit(order, 'action'))
} else if (editOrderIndex.value > -1) {
const isAmendedOrder = !isEqual(parentNotice.securitiesActOrders[editOrderIndex.value], order)
// Edit Order
parentNotice.securitiesActOrders[editOrderIndex.value] = {
...order,
...((props.isAmendment && order.action !== ActionTypes.ADDED) && {
action: isAmendedOrder ? ActionTypes.EDITED : null
...(props.isAmendment && order.action !== ActionTypes.ADDED && isAmendedOrder && {
action: ActionTypes.EDITED
})
}
} else {
Expand Down Expand Up @@ -546,11 +547,19 @@ const togglePanel = (isCancel: boolean = false) => {
/** Set Notices to Store and close active panels **/
const setAndCloseNotice = (isUndo = false): void => {
const notices = getSecuritiesActNotices.value.map(notice =>
notice?.securitiesActOrders?.some(order => !!order.action)
? { ...notice, action: ActionTypes.EDITED }
: { ...notice }
)
// Determine the action for each notice: mark as edited if it has changes,
// retain added/removed notices, otherwise omit the action property.
const notices = getSecuritiesActNotices.value.map((notice, index) => {
const originalNotice = getOriginalSecuritiesActNotices.value[index]
const isAdded = notice.action === ActionTypes.ADDED
const isRemoved = notice.action === ActionTypes.REMOVED
const isEdited = !isAdded && !isEqual(omit(notice, 'action'), omit(originalNotice, 'action'))
if (isEdited) {
return { ...notice, action: ActionTypes.EDITED }
}
return (isAdded || isRemoved) ? { ...notice } : omit(notice, 'action')
})
setSecuritiesActNotices([...notices])
// Close expanded panel
Expand Down
10 changes: 8 additions & 2 deletions ppr-ui/src/composables/pprRegistration/usePprRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ export const usePprRegistration = () => {

// Conditionally parse Securities Act Notices
if (!!statement?.securitiesActNotices){
setSecuritiesActNotices(statement.securitiesActNotices)
setOriginalSecuritiesActNotices(cloneDeep(statement.securitiesActNotices) as Array<AddEditSaNoticeIF>)
// Map the notices to include an empty array for Orders when there is no pre-existing orders on the notice
const mappedNotices = statement.securitiesActNotices.map(notice => ({
...notice,
securitiesActOrders: notice.securitiesActOrders || []
}))

setSecuritiesActNotices(mappedNotices)
setOriginalSecuritiesActNotices(cloneDeep(mappedNotices))
}

const collateral = {
Expand Down

0 comments on commit f2a62d1

Please sign in to comment.