@overmap-ai/core 1.0.51-bulk-form-submission.0 → 1.0.51-bulk-form-submission.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/overmap-core.js +38 -49
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +38 -49
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/services/UserFormSubmissionService.d.ts +1 -1
- package/dist/store/slices/formRevisionSlice.d.ts +32 -40
- package/dist/store/slices/formSlice.d.ts +5 -13
- package/dist/typings/models/base.d.ts +1 -1
- package/dist/typings/models/forms.d.ts +2 -1
- package/dist/utils/forms.d.ts +2 -0
- package/package.json +1 -1
|
@@ -3472,33 +3472,19 @@ var __publicField = (obj, key, value) => {
|
|
|
3472
3472
|
const settingReducer = settingSlice.reducer;
|
|
3473
3473
|
const selectIsFetchingInitialData = (state) => state.settingReducer.isFetchingInitialData;
|
|
3474
3474
|
const selectIsLoading = (state) => state.settingReducer.isLoading;
|
|
3475
|
-
const
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
if (
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
return;
|
|
3487
|
-
}
|
|
3488
|
-
if (formRevision.revision === "Pending") {
|
|
3489
|
-
if (preferPending) {
|
|
3490
|
-
LATEST_FORM_REVISION_CACHE[formRevision.form] = formRevision;
|
|
3491
|
-
}
|
|
3492
|
-
return;
|
|
3493
|
-
}
|
|
3494
|
-
const cachedFormRevision = (_a2 = LATEST_FORM_REVISION_CACHE[formRevision.form]) == null ? void 0 : _a2.revision;
|
|
3495
|
-
if (formRevision.revision > (typeof cachedFormRevision === "number" ? cachedFormRevision : -1)) {
|
|
3496
|
-
LATEST_FORM_REVISION_CACHE[formRevision.form] = formRevision;
|
|
3475
|
+
const formRevisionSortFn = (formRevisionA, formRevisionB) => {
|
|
3476
|
+
const revisionA = formRevisionA.revision;
|
|
3477
|
+
const revisionB = formRevisionB.revision;
|
|
3478
|
+
if (revisionA === "Pending" && revisionB === "Pending") {
|
|
3479
|
+
return formRevisionA.submitted_at < formRevisionB.submitted_at ? 1 : -1;
|
|
3480
|
+
} else if (revisionA === "Pending") {
|
|
3481
|
+
return -1;
|
|
3482
|
+
} else if (revisionB === "Pending") {
|
|
3483
|
+
return 1;
|
|
3484
|
+
} else {
|
|
3485
|
+
return revisionA < revisionB ? 1 : -1;
|
|
3497
3486
|
}
|
|
3498
|
-
}
|
|
3499
|
-
function getLatestFormRevisionFromCache(formId2) {
|
|
3500
|
-
return LATEST_FORM_REVISION_CACHE[formId2];
|
|
3501
|
-
}
|
|
3487
|
+
};
|
|
3502
3488
|
const initialState$5 = {
|
|
3503
3489
|
formRevisions: {},
|
|
3504
3490
|
attachments: {}
|
|
@@ -3511,13 +3497,11 @@ var __publicField = (obj, key, value) => {
|
|
|
3511
3497
|
// revision related actions
|
|
3512
3498
|
setFormRevision: (state, action) => {
|
|
3513
3499
|
state.formRevisions[action.payload.offline_id] = action.payload;
|
|
3514
|
-
considerCachingFormRevision(action.payload);
|
|
3515
3500
|
},
|
|
3516
3501
|
setFormRevisions: (state, action) => {
|
|
3517
3502
|
state.formRevisions = {};
|
|
3518
3503
|
for (const revision of action.payload) {
|
|
3519
3504
|
state.formRevisions[revision.offline_id] = revision;
|
|
3520
|
-
considerCachingFormRevision(revision);
|
|
3521
3505
|
}
|
|
3522
3506
|
},
|
|
3523
3507
|
addFormRevision: (state, action) => {
|
|
@@ -3525,9 +3509,7 @@ var __publicField = (obj, key, value) => {
|
|
|
3525
3509
|
throw new Error(`Revision with offline_id ${action.payload.offline_id} already exists`);
|
|
3526
3510
|
}
|
|
3527
3511
|
state.formRevisions[action.payload.offline_id] = action.payload;
|
|
3528
|
-
considerCachingFormRevision(action.payload);
|
|
3529
3512
|
},
|
|
3530
|
-
// TODO: @Audiopolis / Magnus - do we want to standardize using PayloadAction?
|
|
3531
3513
|
addFormRevisions: (state, action) => {
|
|
3532
3514
|
for (const userFormRevision of action.payload) {
|
|
3533
3515
|
if (state.formRevisions[userFormRevision.offline_id] !== void 0) {
|
|
@@ -3536,7 +3518,6 @@ var __publicField = (obj, key, value) => {
|
|
|
3536
3518
|
}
|
|
3537
3519
|
for (const userFormRevision of action.payload) {
|
|
3538
3520
|
state.formRevisions[userFormRevision.offline_id] = userFormRevision;
|
|
3539
|
-
considerCachingFormRevision(userFormRevision);
|
|
3540
3521
|
}
|
|
3541
3522
|
},
|
|
3542
3523
|
// UserFormRevisions do not get updated
|
|
@@ -3545,7 +3526,6 @@ var __publicField = (obj, key, value) => {
|
|
|
3545
3526
|
throw new Error(`Revision with offline_id ${action.payload} does not exist`);
|
|
3546
3527
|
}
|
|
3547
3528
|
delete state.formRevisions[action.payload];
|
|
3548
|
-
delete LATEST_FORM_REVISION_CACHE[action.payload];
|
|
3549
3529
|
},
|
|
3550
3530
|
deleteFormRevisions: (state, action) => {
|
|
3551
3531
|
for (const offlineId of action.payload) {
|
|
@@ -3555,7 +3535,6 @@ var __publicField = (obj, key, value) => {
|
|
|
3555
3535
|
}
|
|
3556
3536
|
for (const offlineId of action.payload) {
|
|
3557
3537
|
delete state.formRevisions[offlineId];
|
|
3558
|
-
delete LATEST_FORM_REVISION_CACHE[offlineId];
|
|
3559
3538
|
}
|
|
3560
3539
|
},
|
|
3561
3540
|
// attachment related actions
|
|
@@ -3633,11 +3612,8 @@ var __publicField = (obj, key, value) => {
|
|
|
3633
3612
|
return ret;
|
|
3634
3613
|
};
|
|
3635
3614
|
const selectLatestFormRevisionOfForm = restructureCreateSelectorWithArgs(
|
|
3636
|
-
toolkit.createSelector([
|
|
3637
|
-
|
|
3638
|
-
throw new Error("formId is required");
|
|
3639
|
-
}
|
|
3640
|
-
return _selectLatestFormRevision(revisions, formId2);
|
|
3615
|
+
toolkit.createSelector([selectFormRevisions, (_state, formId2) => formId2], (revisions, formId2) => {
|
|
3616
|
+
return revisions.filter((revision) => revision.form === formId2).sort(formRevisionSortFn).pop();
|
|
3641
3617
|
})
|
|
3642
3618
|
);
|
|
3643
3619
|
const selectFormRevisionsOfForm = restructureCreateSelectorWithArgs(
|
|
@@ -3656,12 +3632,19 @@ var __publicField = (obj, key, value) => {
|
|
|
3656
3632
|
],
|
|
3657
3633
|
(userForms, revisions, componentTypeIds) => {
|
|
3658
3634
|
const componentTypeIdsSet = new Set(componentTypeIds);
|
|
3635
|
+
const formsOfComponentTypes = {};
|
|
3659
3636
|
const ret = {};
|
|
3660
3637
|
for (const form of Object.values(userForms)) {
|
|
3661
3638
|
if (form.component_type && componentTypeIdsSet.has(form.component_type)) {
|
|
3662
|
-
|
|
3639
|
+
formsOfComponentTypes[form.component_type] = form;
|
|
3663
3640
|
}
|
|
3664
3641
|
}
|
|
3642
|
+
for (const revision of Object.values(revisions)) {
|
|
3643
|
+
const form = formsOfComponentTypes[revision.form];
|
|
3644
|
+
if (!form || !form.component_type || !ret[form.component_type] || formRevisionSortFn(ret[form.component_type], revision) < 0)
|
|
3645
|
+
continue;
|
|
3646
|
+
ret[form.component_type] = revision;
|
|
3647
|
+
}
|
|
3665
3648
|
return ret;
|
|
3666
3649
|
}
|
|
3667
3650
|
)
|
|
@@ -3707,9 +3690,9 @@ var __publicField = (obj, key, value) => {
|
|
|
3707
3690
|
state.forms[action.payload.offline_id] = action.payload;
|
|
3708
3691
|
},
|
|
3709
3692
|
addForms: (state, action) => {
|
|
3710
|
-
action.payload
|
|
3693
|
+
for (const userForm of action.payload) {
|
|
3711
3694
|
state.forms[userForm.offline_id] = userForm;
|
|
3712
|
-
}
|
|
3695
|
+
}
|
|
3713
3696
|
},
|
|
3714
3697
|
favoriteForm: (state, action) => {
|
|
3715
3698
|
const { formId: formId2 } = action.payload;
|
|
@@ -3811,7 +3794,7 @@ var __publicField = (obj, key, value) => {
|
|
|
3811
3794
|
}
|
|
3812
3795
|
},
|
|
3813
3796
|
addFormSubmission: (state, action) => {
|
|
3814
|
-
if (
|
|
3797
|
+
if (action.payload.offline_id in state.formSubmissions) {
|
|
3815
3798
|
throw new Error(`Submission with offline_id ${action.payload.offline_id} already exists`);
|
|
3816
3799
|
}
|
|
3817
3800
|
state.formSubmissions[action.payload.offline_id] = action.payload;
|
|
@@ -6994,13 +6977,14 @@ var __publicField = (obj, key, value) => {
|
|
|
6994
6977
|
};
|
|
6995
6978
|
const currentUser = state.userReducer.currentUser;
|
|
6996
6979
|
const activeWorkspaceId = state.workspaceReducer.activeWorkspaceId;
|
|
6980
|
+
const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6997
6981
|
const offlineFormPayload = offline({});
|
|
6998
|
-
const offlineRevisionPayload = offline(initialRevision);
|
|
6982
|
+
const offlineRevisionPayload = offline({ ...initialRevision, submitted_at: submittedAt });
|
|
6999
6983
|
const retForm = {
|
|
7000
6984
|
...offlineFormPayload,
|
|
7001
6985
|
index_workspace: activeWorkspaceId,
|
|
7002
6986
|
favorite: true,
|
|
7003
|
-
submitted_at:
|
|
6987
|
+
submitted_at: submittedAt,
|
|
7004
6988
|
created_by: currentUser.id,
|
|
7005
6989
|
...componentTypeId && { component_type: componentTypeId },
|
|
7006
6990
|
...ownerAttrs
|
|
@@ -7010,7 +6994,8 @@ var __publicField = (obj, key, value) => {
|
|
|
7010
6994
|
...payloadWithoutImage,
|
|
7011
6995
|
created_by: currentUser.id,
|
|
7012
6996
|
form: retForm.offline_id,
|
|
7013
|
-
revision: 0
|
|
6997
|
+
revision: 0,
|
|
6998
|
+
submitted_at: submittedAt
|
|
7014
6999
|
};
|
|
7015
7000
|
const { store } = this.client;
|
|
7016
7001
|
store.dispatch(addForm(retForm));
|
|
@@ -7073,7 +7058,8 @@ var __publicField = (obj, key, value) => {
|
|
|
7073
7058
|
...payloadWithoutImage,
|
|
7074
7059
|
created_by: currentUserId,
|
|
7075
7060
|
revision: "Pending",
|
|
7076
|
-
form: formId2
|
|
7061
|
+
form: formId2,
|
|
7062
|
+
submitted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
7077
7063
|
};
|
|
7078
7064
|
store.dispatch(addFormRevision(fullRevision));
|
|
7079
7065
|
const promise = this.enqueueRequest({
|
|
@@ -7280,7 +7266,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7280
7266
|
// Note currently the bulkAdd method is specific to form submissions for components
|
|
7281
7267
|
// TODO: adapt the support bulk adding to any model type
|
|
7282
7268
|
async bulkAdd(args) {
|
|
7283
|
-
const {
|
|
7269
|
+
const { formRevision, values: argsValues, componentOfflineIds } = args;
|
|
7284
7270
|
const { store } = this.client;
|
|
7285
7271
|
const offlineSubmissions = [];
|
|
7286
7272
|
const offlineAttachments = [];
|
|
@@ -7292,7 +7278,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7292
7278
|
const createdBy = store.getState().userReducer.currentUser.id;
|
|
7293
7279
|
for (const component_id of componentOfflineIds) {
|
|
7294
7280
|
const submission = offline({
|
|
7295
|
-
form_revision,
|
|
7281
|
+
form_revision: formRevision,
|
|
7296
7282
|
values,
|
|
7297
7283
|
created_by: createdBy,
|
|
7298
7284
|
submitted_at: submittedAt,
|
|
@@ -7338,7 +7324,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7338
7324
|
const promise = this.enqueueRequest({
|
|
7339
7325
|
description: "Bulk add form submissions",
|
|
7340
7326
|
method: HttpMethod.POST,
|
|
7341
|
-
url: `/forms/revisions/${
|
|
7327
|
+
url: `/forms/revisions/${formRevision}/bulk-respond/`,
|
|
7342
7328
|
payload: {
|
|
7343
7329
|
form_data: values,
|
|
7344
7330
|
submitted_at: submittedAt,
|
|
@@ -7405,8 +7391,10 @@ var __publicField = (obj, key, value) => {
|
|
|
7405
7391
|
const { store } = this.client;
|
|
7406
7392
|
const state = store.getState();
|
|
7407
7393
|
const submission = state.formSubmissionReducer.formSubmissions[submissionId];
|
|
7394
|
+
const submissionAttachments = selectAttachmentsOfFormSubmission(submissionId)(state);
|
|
7408
7395
|
store.dispatch(deleteFormSubmission(submissionId));
|
|
7409
7396
|
store.dispatch(addActiveProjectFormSubmissionsCount(-1));
|
|
7397
|
+
store.dispatch(deleteFormSubmissionAttachments(submissionAttachments.map((x) => x.offline_id)));
|
|
7410
7398
|
try {
|
|
7411
7399
|
return await this.enqueueRequest({
|
|
7412
7400
|
description: "Delete user form submissions",
|
|
@@ -7418,6 +7406,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7418
7406
|
} catch (e) {
|
|
7419
7407
|
store.dispatch(addActiveProjectFormSubmissionsCount(1));
|
|
7420
7408
|
store.dispatch(addFormSubmission(submission));
|
|
7409
|
+
store.dispatch(addFormSubmissionAttachments(submissionAttachments));
|
|
7421
7410
|
throw e;
|
|
7422
7411
|
}
|
|
7423
7412
|
}
|