@overmap-ai/core 1.0.38-component-fields.16 → 1.0.38-component-fields.18
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 +65 -37
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +65 -37
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/services/UserFormSubmissionService.d.ts +2 -0
- package/dist/store/slices/userFormSlice.d.ts +2 -2
- package/package.json +1 -1
package/dist/overmap-core.js
CHANGED
|
@@ -3017,7 +3017,7 @@ const userFormSlice = createSlice({
|
|
|
3017
3017
|
delete LATEST_REVISION_CACHE[userFormRevision.offline_id];
|
|
3018
3018
|
}
|
|
3019
3019
|
},
|
|
3020
|
-
|
|
3020
|
+
updateOrCreateUserFormSubmission: (state, action) => {
|
|
3021
3021
|
state.submissions[action.payload.offline_id] = action.payload;
|
|
3022
3022
|
},
|
|
3023
3023
|
addUserFormSubmissionAttachment: (state, action) => {
|
|
@@ -3106,7 +3106,7 @@ const {
|
|
|
3106
3106
|
addUserForm,
|
|
3107
3107
|
addUserForms,
|
|
3108
3108
|
addUserFormRevisions,
|
|
3109
|
-
|
|
3109
|
+
updateOrCreateUserFormSubmission,
|
|
3110
3110
|
addUserFormSubmissions,
|
|
3111
3111
|
deleteUserFormSubmission,
|
|
3112
3112
|
deleteUserFormSubmissions,
|
|
@@ -5709,6 +5709,43 @@ const separateFilesFromValues = (payload) => {
|
|
|
5709
5709
|
return { payloadWithoutFiles, files };
|
|
5710
5710
|
};
|
|
5711
5711
|
class UserFormSubmissionService extends BaseApiService {
|
|
5712
|
+
constructor() {
|
|
5713
|
+
super(...arguments);
|
|
5714
|
+
// Attach files to submission, after uploading them to S3
|
|
5715
|
+
__publicField(this, "getAttachFilesPromises", (files, payload) => {
|
|
5716
|
+
const { store } = this.client;
|
|
5717
|
+
return Object.entries(files).map(async ([key, fileArray]) => {
|
|
5718
|
+
const attachResults = [];
|
|
5719
|
+
for (const file of fileArray) {
|
|
5720
|
+
const sha1 = await hashFile(file);
|
|
5721
|
+
await this.client.files.addCache(file, sha1);
|
|
5722
|
+
const [fileProps] = await this.client.files.uploadFileToS3(sha1);
|
|
5723
|
+
const submissionAttachmentPayload = offline({
|
|
5724
|
+
...fileProps,
|
|
5725
|
+
submission: payload.offline_id,
|
|
5726
|
+
field_identifier: key
|
|
5727
|
+
});
|
|
5728
|
+
const attach = await this.enqueueRequest({
|
|
5729
|
+
description: "Attach file to form submission",
|
|
5730
|
+
method: HttpMethod.POST,
|
|
5731
|
+
url: `/forms/submission/${payload.offline_id}/attachments/`,
|
|
5732
|
+
payload: submissionAttachmentPayload,
|
|
5733
|
+
blockers: [payload.component, payload.issue, payload.form_revision].filter(
|
|
5734
|
+
(x) => x !== void 0
|
|
5735
|
+
),
|
|
5736
|
+
blocks: [submissionAttachmentPayload.offline_id]
|
|
5737
|
+
});
|
|
5738
|
+
const offlinePayload = {
|
|
5739
|
+
...submissionAttachmentPayload,
|
|
5740
|
+
file: URL.createObjectURL(file)
|
|
5741
|
+
};
|
|
5742
|
+
store.dispatch(addUserFormSubmissionAttachment(offlinePayload));
|
|
5743
|
+
attachResults.push(attach);
|
|
5744
|
+
}
|
|
5745
|
+
return attachResults;
|
|
5746
|
+
});
|
|
5747
|
+
});
|
|
5748
|
+
}
|
|
5712
5749
|
add(payload) {
|
|
5713
5750
|
const { store } = this.client;
|
|
5714
5751
|
const state = store.getState();
|
|
@@ -5725,36 +5762,7 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
5725
5762
|
blockers: [payload.issue, payload.component].filter((x) => x !== void 0),
|
|
5726
5763
|
blocks: [payload.offline_id]
|
|
5727
5764
|
});
|
|
5728
|
-
const attachFilesPromises =
|
|
5729
|
-
const attachResults = [];
|
|
5730
|
-
for (const file of fileArray) {
|
|
5731
|
-
const sha1 = await hashFile(file);
|
|
5732
|
-
await this.client.files.addCache(file, sha1);
|
|
5733
|
-
const [fileProps] = await this.client.files.uploadFileToS3(sha1);
|
|
5734
|
-
const submissionAttachmentPayload = offline({
|
|
5735
|
-
...fileProps,
|
|
5736
|
-
submission: payload.offline_id,
|
|
5737
|
-
field_identifier: key
|
|
5738
|
-
});
|
|
5739
|
-
const attach = await this.enqueueRequest({
|
|
5740
|
-
description: "Attach file to form submission",
|
|
5741
|
-
method: HttpMethod.POST,
|
|
5742
|
-
url: `/forms/submission/${payload.offline_id}/attachments/`,
|
|
5743
|
-
payload: submissionAttachmentPayload,
|
|
5744
|
-
blockers: [payload.component, payload.issue, payload.form_revision].filter(
|
|
5745
|
-
(x) => x !== void 0
|
|
5746
|
-
),
|
|
5747
|
-
blocks: [submissionAttachmentPayload.offline_id]
|
|
5748
|
-
});
|
|
5749
|
-
const offlinePayload = {
|
|
5750
|
-
...submissionAttachmentPayload,
|
|
5751
|
-
file: URL.createObjectURL(file)
|
|
5752
|
-
};
|
|
5753
|
-
store.dispatch(addUserFormSubmissionAttachment(offlinePayload));
|
|
5754
|
-
attachResults.push(attach);
|
|
5755
|
-
}
|
|
5756
|
-
return attachResults;
|
|
5757
|
-
});
|
|
5765
|
+
const attachFilesPromises = this.getAttachFilesPromises(files, payload);
|
|
5758
5766
|
const fullOfflineResult = {
|
|
5759
5767
|
...payload,
|
|
5760
5768
|
created_by: state.userReducer.currentUser.id,
|
|
@@ -5764,9 +5772,9 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
5764
5772
|
...fullOfflineResult,
|
|
5765
5773
|
...payloadWithoutFiles
|
|
5766
5774
|
};
|
|
5767
|
-
store.dispatch(
|
|
5775
|
+
store.dispatch(updateOrCreateUserFormSubmission(offlineResultWithoutFiles));
|
|
5768
5776
|
void promise.then((result) => {
|
|
5769
|
-
store.dispatch(
|
|
5777
|
+
store.dispatch(updateOrCreateUserFormSubmission(result));
|
|
5770
5778
|
return result;
|
|
5771
5779
|
}).catch(() => {
|
|
5772
5780
|
store.dispatch(deleteUserFormSubmission(payload.offline_id));
|
|
@@ -5774,6 +5782,26 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
5774
5782
|
const settledPromise = Promise.all([promise, ...attachFilesPromises]).then(() => promise);
|
|
5775
5783
|
return [fullOfflineResult, settledPromise];
|
|
5776
5784
|
}
|
|
5785
|
+
update(submission) {
|
|
5786
|
+
const { store } = this.client;
|
|
5787
|
+
const { payloadWithoutFiles, files } = separateFilesFromValues(submission);
|
|
5788
|
+
if (!("created_by" in payloadWithoutFiles) || !("created_at" in payloadWithoutFiles)) {
|
|
5789
|
+
throw new Error("Expected payloadWithoutFiles to have created_by and created_at fields.");
|
|
5790
|
+
}
|
|
5791
|
+
const attachFilesPromises = this.getAttachFilesPromises(files, submission);
|
|
5792
|
+
store.dispatch(updateOrCreateUserFormSubmission(payloadWithoutFiles));
|
|
5793
|
+
const promise = this.enqueueRequest({
|
|
5794
|
+
description: "Patch form submission",
|
|
5795
|
+
method: HttpMethod.PATCH,
|
|
5796
|
+
url: `/forms/submissions/${submission.offline_id}/`,
|
|
5797
|
+
payload: payloadWithoutFiles,
|
|
5798
|
+
blockers: [payloadWithoutFiles.issue, payloadWithoutFiles.component].filter(
|
|
5799
|
+
(x) => x !== void 0
|
|
5800
|
+
),
|
|
5801
|
+
blocks: [payloadWithoutFiles.offline_id]
|
|
5802
|
+
});
|
|
5803
|
+
return Promise.all([promise, ...attachFilesPromises]).then(() => promise);
|
|
5804
|
+
}
|
|
5777
5805
|
async delete(submissionId) {
|
|
5778
5806
|
const { store } = this.client;
|
|
5779
5807
|
const state = store.getState();
|
|
@@ -5789,7 +5817,7 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
5789
5817
|
});
|
|
5790
5818
|
} catch (e) {
|
|
5791
5819
|
if (submission) {
|
|
5792
|
-
store.dispatch(
|
|
5820
|
+
store.dispatch(updateOrCreateUserFormSubmission(submission));
|
|
5793
5821
|
}
|
|
5794
5822
|
throw e;
|
|
5795
5823
|
}
|
|
@@ -10336,7 +10364,7 @@ const FormRenderer = memo(
|
|
|
10336
10364
|
] }) }),
|
|
10337
10365
|
inputs,
|
|
10338
10366
|
!readonly && /* @__PURE__ */ jsxs(Flex, { className: styles$6.floatingButtonContainer, align: "center", justify: "end", gap: "2", children: [
|
|
10339
|
-
cancelText && /* @__PURE__ */ jsx(Button, { type: "button", variant: "solid", onClick: onCancel, children: cancelText }),
|
|
10367
|
+
cancelText && /* @__PURE__ */ jsx(Button, { type: "button", variant: "solid", severity: "info", onClick: onCancel, children: cancelText }),
|
|
10340
10368
|
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: !formik.isValid, children: submitText })
|
|
10341
10369
|
] })
|
|
10342
10370
|
] }) }) });
|
|
@@ -11915,7 +11943,6 @@ export {
|
|
|
11915
11943
|
addUserFormRevision,
|
|
11916
11944
|
addUserFormRevisionAttachment,
|
|
11917
11945
|
addUserFormRevisions,
|
|
11918
|
-
addUserFormSubmission,
|
|
11919
11946
|
addUserFormSubmissionAttachment,
|
|
11920
11947
|
addUserFormSubmissions,
|
|
11921
11948
|
addUserForms,
|
|
@@ -12249,6 +12276,7 @@ export {
|
|
|
12249
12276
|
updateComponent,
|
|
12250
12277
|
updateIssue,
|
|
12251
12278
|
updateOrCreateProject,
|
|
12279
|
+
updateOrCreateUserFormSubmission,
|
|
12252
12280
|
updateOrganizationAccess,
|
|
12253
12281
|
updateProjectAccess,
|
|
12254
12282
|
updateStages,
|