@overmap-ai/core 1.0.38-component-fields.31 → 1.0.38-component-fields.33

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.
@@ -6,4 +6,4 @@ import { UserFormRevision } from "../typings";
6
6
  export declare const hasKeys: (errors: object) => boolean;
7
7
  export declare const validateForm: (schema: ISchema, form: Form | FormikUserFormRevision) => FormikErrors<Form> | FormikErrors<import('./builder/typings').NewForm> | undefined;
8
8
  export declare const initialFormValues: (fields: BaseFormElement[], values: Form) => Form;
9
- export declare const useAttachImagesToFormRevisionFields: (revision: UserFormRevision) => UserFormRevision;
9
+ export declare const useAttachImagesToFormRevisionFields: (revision: UserFormRevision | undefined) => UserFormRevision | undefined;
@@ -3216,7 +3216,6 @@ const selectUserForm = (formId2) => (state) => {
3216
3216
  const selectSubmissionMapping = (state) => state.userFormReducer.submissions;
3217
3217
  const selectSubmissions = createSelector([selectSubmissionMapping], (submissions) => Object.values(submissions));
3218
3218
  const selectRevisionMapping = (state) => state.userFormReducer.revisions;
3219
- const selectRevisionAttachmentsMapping = (state) => state.userFormReducer.revisionAttachments;
3220
3219
  const selectRevisions = createSelector([selectRevisionMapping], (revisions) => Object.values(revisions));
3221
3220
  const selectRevisionsForForm = restructureCreateSelectorWithArgs(
3222
3221
  createSelector([selectRevisions, (_state, formId2) => formId2], (revisions, formId2) => {
@@ -3329,19 +3328,6 @@ const selectLatestRevisionByFormId = createSelector([selectRevisionMapping], (re
3329
3328
  }
3330
3329
  return latestRevisions;
3331
3330
  });
3332
- const selectAllRevisionAttachmentsByLatestRevisionId = createSelector(
3333
- [selectUserFormMapping, selectRevisionMapping, selectRevisionAttachmentsMapping],
3334
- (forms, revisions, attachments) => {
3335
- const mappedAttachments = {};
3336
- for (const form of Object.values(forms)) {
3337
- const latestRevision = _selectLatestFormRevision(revisions, form.offline_id);
3338
- if (attachments[latestRevision.offline_id] !== void 0) {
3339
- mappedAttachments[latestRevision.offline_id] = attachments[latestRevision.offline_id];
3340
- }
3341
- }
3342
- return mappedAttachments;
3343
- }
3344
- );
3345
3331
  const selectNumberOfUserForms = createSelector([selectUserFormMapping], (userForms) => {
3346
3332
  return Object.keys(userForms).length;
3347
3333
  });
@@ -5660,21 +5646,13 @@ class UserFormService extends BaseApiService {
5660
5646
  }
5661
5647
  async attachToComponentStage(formId2, componentStageId) {
5662
5648
  const { store } = this.client;
5663
- const activeProjectId = store.getState().projectReducer.activeProjectId;
5664
- if (!activeProjectId) {
5665
- throw new Error("Expected an active project.");
5666
- }
5667
5649
  store.dispatch(attachFormToComponentStage({ formId: formId2, componentStageId }));
5668
5650
  try {
5669
5651
  await this.enqueueRequest({
5670
5652
  description: "Attach form to component stage",
5671
- method: HttpMethod.PATCH,
5672
- url: `/forms/${formId2}/`,
5653
+ method: HttpMethod.POST,
5654
+ url: `/forms/${formId2}/associate-with-stage/`,
5673
5655
  payload: { component_stage: componentStageId },
5674
- queryParams: {
5675
- project_id: activeProjectId.toString(),
5676
- component_stage: componentStageId
5677
- },
5678
5656
  blockers: [formId2, componentStageId],
5679
5657
  blocks: [formId2]
5680
5658
  });
@@ -5685,21 +5663,12 @@ class UserFormService extends BaseApiService {
5685
5663
  }
5686
5664
  async removeFromComponentStage(formId2, componentStageId) {
5687
5665
  const { store } = this.client;
5688
- const activeProjectId = store.getState().projectReducer.activeProjectId;
5689
- if (!activeProjectId) {
5690
- throw new Error("Expected an active project.");
5691
- }
5692
5666
  store.dispatch(removeFormFromComponentStage({ formId: formId2 }));
5693
5667
  try {
5694
5668
  await this.enqueueRequest({
5695
5669
  description: "Remove form from component stage",
5696
- method: HttpMethod.PATCH,
5697
- url: `/forms/${formId2}/`,
5698
- payload: { component_stage: void 0 },
5699
- queryParams: {
5700
- project_id: activeProjectId.toString(),
5701
- component_stage: componentStageId
5702
- },
5670
+ method: HttpMethod.DELETE,
5671
+ url: `/forms/${formId2}/associate-with-stage/`,
5703
5672
  blockers: [formId2, componentStageId],
5704
5673
  blocks: [formId2]
5705
5674
  });
@@ -10388,10 +10357,12 @@ const initialFormValues = (fields, values) => {
10388
10357
  };
10389
10358
  const useAttachImagesToFormRevisionFields = (revision) => {
10390
10359
  const { sdk } = useSDK();
10391
- const attachments = useAppSelector(selectRevisionAttachments(revision.offline_id));
10360
+ const attachments = useAppSelector(selectRevisionAttachments((revision == null ? void 0 : revision.offline_id) ?? ""));
10392
10361
  return useMemo(() => {
10362
+ if (!revision || !attachments)
10363
+ return revision;
10393
10364
  const revisionCopy = structuredClone(revision);
10394
- for (const attachment of attachments ?? []) {
10365
+ for (const attachment of attachments) {
10395
10366
  const filePromise = sdk.files.fetchFileFromUrl(attachment.file, attachment.file_sha1, attachment.file_name);
10396
10367
  let sectionIndex = -1;
10397
10368
  let fieldIndex = -1;
@@ -10476,6 +10447,9 @@ const FormSubmissionViewer = memo(
10476
10447
  );
10477
10448
  }
10478
10449
  const revisionWithImages = useAttachImagesToFormRevisionFields(revision);
10450
+ if (!revisionWithImages) {
10451
+ throw new Error("Expected revisionWithImages to be defined");
10452
+ }
10479
10453
  const schema = useMemo(() => {
10480
10454
  return formRevisionToSchema(revisionWithImages, { readonly: true });
10481
10455
  }, [revisionWithImages]);
@@ -11801,8 +11775,9 @@ const FormBuilder = memo(
11801
11775
  }),
11802
11776
  [initialTitle]
11803
11777
  );
11778
+ const revisionWithImages = useAttachImagesToFormRevisionFields(revision);
11804
11779
  const formik = useFormik({
11805
- initialValues: wrapRootFieldsWithFieldSection(revision) ?? initialValues,
11780
+ initialValues: wrapRootFieldsWithFieldSection(revisionWithImages) ?? initialValues,
11806
11781
  validate,
11807
11782
  onSubmit: onSave,
11808
11783
  validateOnChange: false,
@@ -12200,7 +12175,6 @@ export {
12200
12175
  selectActiveWorkspace,
12201
12176
  selectActiveWorkspaceId,
12202
12177
  selectAllAttachments,
12203
- selectAllRevisionAttachmentsByLatestRevisionId,
12204
12178
  selectAppearance,
12205
12179
  selectCategories,
12206
12180
  selectCategoriesOfWorkspace,