Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) {
modelName = singularModelName( modelName );
relationName = singularModelName( relationName );
relationState = yield resolveDispatch(
CORE_REDUCER_KEY,
'getRelationState',
modelName,
addRelation,
relationState
);
let entityIdChanged = false;
if ( isEmpty( relationState ) ) {
return 0;
}
// is the entityId a cuid? If so, then let's persist.
if ( cuid.isCuid( entityId ) ) {
entityId = yield resolveDispatch(
CORE_REDUCER_KEY,
'persistNewEntityAndRemoveDirtyRelations',
relationName,
relationId,
modelName,
entityId,
addRelation,
[ modelName, entityId ],
);
// if entityId is 0 bail because it didn't get persisted so relations
// can't be persisted either.
if ( entityId === 0 ) {
return entityId;
}
entityIdChanged = true;
);
return state.set(
'add',
updateRelationState(
Map( state.get( 'add' ) ),
action,
relationMap
)
);
case types.RECEIVE_DIRTY_RELATION_DELETION:
case types.REMOVE_DIRTY_RELATION_DELETION:
// if the relation or entity id is a cuid, then we skip this because
// the relation has never been persisted anyways.
if (
cuid.isCuid( action.relationEntityId ) ||
cuid.isCuid( action.entityId )
) {
return state;
}
state = state.set(
'index',
indexRelations(
Map( state.get( 'index' ) ),
action,
relationMap
)
);
return state.set(
'delete',
updateRelationState(
Map( state.get( 'delete' ) ),
action,
prefix,
updateField,
touchField
});
// entity properties we don't want to be editable
const exclude = [
'TKT_ID',
'sold',
'reserved',
'order',
'parent',
'wpUser',
'status'
];
const isNewTicket = cuid.isCuid(ticketEntity.TKT_ID);
if (isNewTicket) {
exclude.push('deleted');
}
const formRows = useEditEntityFormInputs(
ticketEntity,
inputConfig,
prefix,
currentValues,
exclude
);
return useMemo(() => {
// edit forms for existing objects must have initial values
return !(!newObject && isEmpty(initialValues)) ? (
prefix,
updateField,
touchField,
} );
// entity properties we don't want to be editable
const exclude = [
'TKT_ID',
'sold',
'reserved',
'order',
'parent',
'wpUser',
'status',
];
const isNewTicket = cuid.isCuid( ticketEntity.TKT_ID );
if ( isNewTicket ) {
exclude.push( 'deleted' );
}
const formRows = useEditEntityFormInputs(
ticketEntity,
inputConfig,
prefix,
currentValues,
exclude
);
return useMemo(
() => {
// edit forms for existing objects must have initial values
)
);
return state.set(
'add',
updateRelationState(
Map( state.get( 'add' ) ),
action,
relationMap
)
);
case types.RECEIVE_DIRTY_RELATION_DELETION:
case types.REMOVE_DIRTY_RELATION_DELETION:
// if the relation or entity id is a cuid, then we skip this because
// the relation has never been persisted anyways.
if (
cuid.isCuid( action.relationEntityId ) ||
cuid.isCuid( action.entityId )
) {
return state;
}
state = state.set(
'index',
indexRelations(
Map( state.get( 'index' ) ),
action,
relationMap
)
);
return state.set(
'delete',
updateRelationState(
Map( state.get( 'delete' ) ),
relationId,
modelName,
entityId,
addRelation,
[ modelName, entityId ],
);
// if entityId is 0 bail because it didn't get persisted so relations
// can't be persisted either.
if ( entityId === 0 ) {
return entityId;
}
entityIdChanged = true;
}
// is the relationId a cuid? If so, then let's persist
if ( cuid.isCuid( relationId ) ) {
relationId = yield resolveDispatch(
CORE_REDUCER_KEY,
'persistNewEntityAndRemoveDirtyRelations',
relationName,
relationId,
modelName,
entityId,
addRelation,
[ relationName, relationId ],
! entityIdChanged,
);
// if relationId is 0, bail because it didn't get persisted so relations
// can't be persisted either.
if ( relationId === 0 ) {
return relationId;
}
export const normalizeEntityId = ( id ) => cuid.isCuid( id ) ?
id :
toInteger( id );