@overmap-ai/core 1.0.38-component-fields.8 → 1.0.38-component-fields.10

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.
@@ -5,6 +5,7 @@ interface FieldSectionWithActionsProps {
5
5
  field: SerializedFieldSection;
6
6
  index: number;
7
7
  dropState: DropState;
8
+ fieldsOnly: boolean;
8
9
  }
9
10
  export declare const FieldSectionWithActions: import("react").MemoExoticComponent<(props: FieldSectionWithActionsProps) => import("react/jsx-runtime").JSX.Element>;
10
11
  export {};
@@ -1,2 +1,6 @@
1
1
  /// <reference types="react" />
2
- export declare const FieldsEditor: import("react").MemoExoticComponent<() => import("react/jsx-runtime").JSX.Element>;
2
+ interface FieldsEditorProps {
3
+ fieldsOnly: boolean;
4
+ }
5
+ export declare const FieldsEditor: import("react").MemoExoticComponent<(props: FieldsEditorProps) => import("react/jsx-runtime").JSX.Element>;
6
+ export {};
@@ -9,8 +9,16 @@ interface FormBuilderProps {
9
9
  initialTitle?: string;
10
10
  /** @default true */
11
11
  showExplainerText?: boolean;
12
- /** @default false */
13
- showSectionsOnly?: boolean;
12
+ /** @default true */
13
+ showFormTitle?: boolean;
14
+ /** Show and edit non-section fields only. Functionally, these fields will be in a single section with no label
15
+ * @default false
16
+ */
17
+ fieldsOnly?: boolean;
18
+ /** Show the Edit and Preview tabs at the top of the component. If false, the preview is entirely inaccessible.
19
+ * @default true
20
+ */
21
+ showTabs?: boolean;
14
22
  }
15
23
  export declare const FormBuilder: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<FormBuilderProps & import("react").RefAttributes<HTMLDivElement>>>;
16
24
  export {};
@@ -3291,6 +3291,24 @@ const selectLatestRevisionsFromComponentTypeIds = restructureCreateSelectorWithA
3291
3291
  }
3292
3292
  )
3293
3293
  );
3294
+ const selectLatestRevisionsForComponentStageForms = restructureCreateSelectorWithArgs(
3295
+ createSelector(
3296
+ [
3297
+ selectUserFormMapping,
3298
+ selectRevisionMapping,
3299
+ (_state, componentStageId) => componentStageId
3300
+ ],
3301
+ (userForms, revisions, componentStageId) => {
3302
+ const latestRevisions = [];
3303
+ for (const form of Object.values(userForms)) {
3304
+ if (form.component_stage === componentStageId) {
3305
+ latestRevisions.push(_selectLatestFormRevision(revisions, form.offline_id));
3306
+ }
3307
+ }
3308
+ return latestRevisions;
3309
+ }
3310
+ )
3311
+ );
3294
3312
  const selectLatestRevisionByFormId = createSelector([selectRevisionMapping], (revisions) => {
3295
3313
  const latestRevisions = {};
3296
3314
  for (const revision of Object.values(revisions)) {
@@ -5468,10 +5486,13 @@ class UserFormService extends BaseApiService {
5468
5486
  });
5469
5487
  });
5470
5488
  }
5471
- async add(state, initialRevision, url, ownerUser, ownerOrganization, componentType) {
5489
+ async add(state, initialRevision, url, ownerUser, ownerOrganization, componentTypeId, componentStageId) {
5472
5490
  if (!!ownerUser === !!ownerOrganization) {
5473
5491
  throw new Error("Exactly one of ownerUser and ownerOrganization must be defined.");
5474
5492
  }
5493
+ if (componentTypeId && componentStageId) {
5494
+ throw new Error("At most one of componentTypeId and componentStageId should be defined.");
5495
+ }
5475
5496
  const ownerAttrs = {
5476
5497
  owner_user: ownerUser,
5477
5498
  owner_organization: ownerOrganization
@@ -5486,7 +5507,8 @@ class UserFormService extends BaseApiService {
5486
5507
  favorite: true,
5487
5508
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5488
5509
  created_by: currentUser.id,
5489
- ...componentType && { component_type: componentType },
5510
+ ...componentTypeId && { component_type: componentTypeId },
5511
+ ...componentStageId && { component_stage: componentStageId },
5490
5512
  ...ownerAttrs
5491
5513
  };
5492
5514
  const { payloadWithoutImage, images } = await separateImageFromFields(offlineRevisionPayload);
@@ -5508,10 +5530,11 @@ class UserFormService extends BaseApiService {
5508
5530
  } : void 0,
5509
5531
  payload: {
5510
5532
  ...offlineFormPayload,
5511
- ...componentType && { component_type: componentType },
5533
+ ...componentTypeId && { component_type: componentTypeId },
5534
+ ...componentStageId && { component_stage: componentStageId },
5512
5535
  initial_revision: payloadWithoutImage
5513
5536
  },
5514
- blockers: [],
5537
+ blockers: [componentTypeId, componentStageId].filter((x) => x !== void 0),
5515
5538
  blocks: [offlineFormPayload.offline_id, payloadWithoutImage.offline_id]
5516
5539
  });
5517
5540
  const attachImagesPromises = this.getAttachImagePromises(images, offlineRevisionPayload.offline_id);
@@ -5523,7 +5546,7 @@ class UserFormService extends BaseApiService {
5523
5546
  const settledPromise = Promise.all([formPromise, ...attachImagesPromises]).then(() => formPromise);
5524
5547
  return [retForm, retRevision, formPromise, settledPromise];
5525
5548
  }
5526
- async addForOrganization(initialRevision, componentType) {
5549
+ async addForOrganization(initialRevision, componentTypeId, componentStageId) {
5527
5550
  const state = this.client.store.getState();
5528
5551
  const activeOrganizationId = state.organizationReducer.activeOrganizationId;
5529
5552
  if (!activeOrganizationId) {
@@ -5535,13 +5558,22 @@ class UserFormService extends BaseApiService {
5535
5558
  `/forms/in-organization/${activeOrganizationId}/`,
5536
5559
  void 0,
5537
5560
  activeOrganizationId,
5538
- componentType
5561
+ componentTypeId,
5562
+ componentStageId
5539
5563
  );
5540
5564
  }
5541
- async addForCurrentUser(initialRevision, componentType) {
5565
+ async addForCurrentUser(initialRevision, componentTypeId, componentStageId) {
5542
5566
  const state = this.client.store.getState();
5543
5567
  const currentUser = state.userReducer.currentUser;
5544
- return await this.add(state, initialRevision, "/forms/my-forms/", currentUser.id, void 0, componentType);
5568
+ return await this.add(
5569
+ state,
5570
+ initialRevision,
5571
+ "/forms/my-forms/",
5572
+ currentUser.id,
5573
+ void 0,
5574
+ componentTypeId,
5575
+ componentStageId
5576
+ );
5545
5577
  }
5546
5578
  async createRevision(formId2, revision) {
5547
5579
  const offlineRevision = offline(revision);
@@ -11237,7 +11269,7 @@ const FieldWithActions = memo((props) => {
11237
11269
  FieldWithActions.displayName = "FieldWithActions";
11238
11270
  const FieldSectionWithActions = memo((props) => {
11239
11271
  var _a2;
11240
- const { field, index: sectionIndex, dropState } = props;
11272
+ const { field, index: sectionIndex, dropState, fieldsOnly } = props;
11241
11273
  const isDropDisabled = (_a2 = dropState[field.identifier]) == null ? void 0 : _a2.disabled;
11242
11274
  const { setFieldValue, values } = useFormikContext();
11243
11275
  const alertDialog = useAlertDialog();
@@ -11377,7 +11409,7 @@ const FieldSectionWithActions = memo((props) => {
11377
11409
  mb: "4",
11378
11410
  children: /* @__PURE__ */ jsxs(Flex, { gap: "3", justify: "between", align: "center", children: [
11379
11411
  /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "2", grow: "1", children: [
11380
- /* @__PURE__ */ jsx(FieldBuilder, { ...editSectionProps }),
11412
+ !fieldsOnly && /* @__PURE__ */ jsx(FieldBuilder, { ...editSectionProps }),
11381
11413
  /* @__PURE__ */ jsx(
11382
11414
  Droppable,
11383
11415
  {
@@ -11421,7 +11453,7 @@ const FieldSectionWithActions = memo((props) => {
11421
11453
  }
11422
11454
  )
11423
11455
  ] }),
11424
- /* @__PURE__ */ jsx(
11456
+ !fieldsOnly && /* @__PURE__ */ jsx(
11425
11457
  FieldActions,
11426
11458
  {
11427
11459
  index: sectionIndex,
@@ -11498,7 +11530,8 @@ const findSection = (fields, sectionId) => {
11498
11530
  return [section, i];
11499
11531
  }
11500
11532
  };
11501
- const FieldsEditor = memo(() => {
11533
+ const FieldsEditor = memo((props) => {
11534
+ const { fieldsOnly } = props;
11502
11535
  const { values, setFieldValue } = useFormikContext();
11503
11536
  const [dropState, dispatch] = useReducer(reducer, values.fields, initializer);
11504
11537
  const { reorderSection, reorderField } = useFieldReordering();
@@ -11551,8 +11584,16 @@ const FieldsEditor = memo(() => {
11551
11584
  gap: "0",
11552
11585
  children: [
11553
11586
  values.fields.map((field, index2) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
11554
- /* @__PURE__ */ jsx(FieldSectionWithActions, { field, index: index2, dropState }),
11555
- /* @__PURE__ */ jsxs(
11587
+ /* @__PURE__ */ jsx(
11588
+ FieldSectionWithActions,
11589
+ {
11590
+ field,
11591
+ index: index2,
11592
+ dropState,
11593
+ fieldsOnly
11594
+ }
11595
+ ),
11596
+ !fieldsOnly && /* @__PURE__ */ jsxs(
11556
11597
  Button,
11557
11598
  {
11558
11599
  className: styles$1.addSectionButton,
@@ -11580,7 +11621,16 @@ const previewSubmit = () => {
11580
11621
  };
11581
11622
  const FormBuilder = memo(
11582
11623
  forwardRef((props, ref) => {
11583
- const { onCancel, onSave, revision, initialTitle, showExplainerText = true, showSectionsOnly = false } = props;
11624
+ const {
11625
+ onCancel,
11626
+ onSave,
11627
+ revision,
11628
+ initialTitle,
11629
+ showExplainerText = true,
11630
+ showFormTitle = true,
11631
+ fieldsOnly = false,
11632
+ showTabs = true
11633
+ } = props;
11584
11634
  const { showError } = useToast();
11585
11635
  const validate = useCallback(
11586
11636
  (form) => {
@@ -11643,7 +11693,7 @@ const FormBuilder = memo(
11643
11693
  });
11644
11694
  const previewSchema = useMemo(() => formRevisionToSchema(formik.values), [formik.values]);
11645
11695
  return /* @__PURE__ */ jsx(Tabs.Root, { ref, defaultValue: "edit", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "2", children: [
11646
- /* @__PURE__ */ jsxs(Tabs.List, { className: styles$7.tabsList, children: [
11696
+ showTabs && /* @__PURE__ */ jsxs(Tabs.List, { className: styles$7.tabsList, children: [
11647
11697
  /* @__PURE__ */ jsx(Tabs.Trigger, { className: styles$7.tabTrigger, value: "edit", children: /* @__PURE__ */ jsxs(Flex, { align: "center", gap: "2", children: [
11648
11698
  /* @__PURE__ */ jsx(Pencil1Icon, {}),
11649
11699
  "Edit"
@@ -11664,7 +11714,7 @@ const FormBuilder = memo(
11664
11714
  ] }),
11665
11715
  /* @__PURE__ */ jsx(Flex, { asChild: true, direction: "column", gap: "2", mt: "3", children: /* @__PURE__ */ jsxs("form", { id: formId, onSubmit: formik.handleSubmit, children: [
11666
11716
  /* @__PURE__ */ jsxs(FormikProvider, { value: formik, children: [
11667
- !showSectionsOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
11717
+ showFormTitle && /* @__PURE__ */ jsxs(Fragment, { children: [
11668
11718
  /* @__PURE__ */ jsx(
11669
11719
  PatchField,
11670
11720
  {
@@ -11710,7 +11760,7 @@ const FormBuilder = memo(
11710
11760
  }
11711
11761
  )
11712
11762
  ] }),
11713
- /* @__PURE__ */ jsx(FieldsEditor, {}),
11763
+ /* @__PURE__ */ jsx(FieldsEditor, { fieldsOnly }),
11714
11764
  /* @__PURE__ */ jsx(Text, { severity: "danger", size: "1", children: typeof formik.errors.fields === "string" && formik.errors.fields })
11715
11765
  ] }),
11716
11766
  /* @__PURE__ */ jsxs(Flex, { className: styles$7.floatingButtonContainer, align: "center", justify: "end", gap: "2", children: [
@@ -11719,7 +11769,7 @@ const FormBuilder = memo(
11719
11769
  ] })
11720
11770
  ] }) })
11721
11771
  ] }),
11722
- /* @__PURE__ */ jsx(Tabs.Content, { value: "preview", children: /* @__PURE__ */ jsx(FormRenderer, { schema: previewSchema, onSubmit: previewSubmit, hideTitle: showSectionsOnly }) })
11772
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "preview", children: /* @__PURE__ */ jsx(FormRenderer, { schema: previewSchema, onSubmit: previewSubmit, hideTitle: !showFormTitle }) })
11723
11773
  ] }) });
11724
11774
  })
11725
11775
  );
@@ -12084,6 +12134,7 @@ export {
12084
12134
  selectLatestFormRevision,
12085
12135
  selectLatestRetryTime,
12086
12136
  selectLatestRevisionByFormId,
12137
+ selectLatestRevisionsForComponentStageForms,
12087
12138
  selectLatestRevisionsForComponentTypeForms,
12088
12139
  selectLatestRevisionsFromComponentTypeIds,
12089
12140
  selectMainWorkspace,