@overmap-ai/core 1.0.58-export-overmap-reducer.14 → 1.0.58-export-overmap-reducer.15

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.
@@ -3578,17 +3578,15 @@ const selectFilteredForms = restructureCreateSelectorWithArgs(
3578
3578
  (_state, search) => search
3579
3579
  ],
3580
3580
  (userForms, revisions, search) => {
3581
- const { searchTerm, maxResults, favorites, owner_organization, owner_user } = search;
3581
+ const { searchTerm, maxResults, favorites, organization } = search;
3582
3582
  const favoriteMatches = [];
3583
3583
  const regularMatches = [];
3584
3584
  for (const [userFormId, userForm] of Object.entries(userForms)) {
3585
3585
  if (favorites !== void 0 && userForm.favorite != favorites)
3586
3586
  continue;
3587
- if (Number.isInteger(owner_organization) && owner_organization !== userForm.owner_organization) {
3587
+ if (Number.isInteger(organization) && organization !== userForm.organization) {
3588
3588
  continue;
3589
3589
  }
3590
- if (Number.isInteger(owner_user) && owner_user !== userForm.owner_user)
3591
- continue;
3592
3590
  const latestRevision = _selectLatestFormRevision(revisions, userFormId);
3593
3591
  if (latestRevision.title.toLowerCase().includes(searchTerm.toLowerCase())) {
3594
3592
  if (userForm.favorite) {
@@ -4373,10 +4371,6 @@ function handleWorkspaceRemoval(draft, action) {
4373
4371
  throw new Error(`Failed to update index_workspace of issue ${issue.offline_id} to main workspace`);
4374
4372
  }
4375
4373
  }
4376
- const indexedForms = Object.values(draft.formReducer.forms).filter((form) => form.index_workspace === workspaceId);
4377
- for (const form of indexedForms) {
4378
- form.index_workspace = mainWorkspace.offline_id;
4379
- }
4380
4374
  }
4381
4375
  const overmapRootReducer = (state, action) => {
4382
4376
  if (action.type === "auth/setLoggedIn" && !action.payload) {
@@ -6758,8 +6752,7 @@ class ProjectService extends BaseApiService {
6758
6752
  });
6759
6753
  }
6760
6754
  }
6761
- const separateImageFromFields = async (payload) => {
6762
- const { fields } = payload;
6755
+ const separateImageFromFields = async (fields) => {
6763
6756
  const images = {};
6764
6757
  const newFields = [];
6765
6758
  for (const section of fields) {
@@ -6785,11 +6778,7 @@ const separateImageFromFields = async (payload) => {
6785
6778
  }
6786
6779
  newFields.push({ ...section, fields: newSectionFields });
6787
6780
  }
6788
- const payloadWithoutImage = {
6789
- ...payload,
6790
- fields: newFields
6791
- };
6792
- return { payloadWithoutImage, images };
6781
+ return { fields: newFields, images };
6793
6782
  };
6794
6783
  class UserFormService extends BaseApiService {
6795
6784
  constructor() {
@@ -6823,93 +6812,90 @@ class UserFormService extends BaseApiService {
6823
6812
  });
6824
6813
  });
6825
6814
  }
6826
- async add(state, initialRevision, url, ownerUser, ownerOrganization, assetTypeId, issueTypeId) {
6827
- if (!!ownerUser === !!ownerOrganization) {
6828
- throw new Error("Exactly one of ownerUser and ownerOrganization must be defined.");
6829
- }
6830
- const ownerAttrs = {
6831
- owner_user: ownerUser,
6832
- owner_organization: ownerOrganization
6833
- };
6834
- const currentUser = state.userReducer.currentUser;
6835
- const activeWorkspaceId = state.workspaceReducer.activeWorkspaceId;
6836
- const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
6837
- const offlineFormPayload = offline({ ...ownerAttrs });
6838
- const offlineRevisionPayload = offline({ ...initialRevision, submitted_at: submittedAt });
6839
- const retForm = {
6840
- ...offlineFormPayload,
6841
- index_workspace: activeWorkspaceId,
6842
- favorite: true,
6843
- submitted_at: submittedAt,
6844
- created_by: currentUser.id,
6845
- ...assetTypeId && { asset_type: assetTypeId },
6846
- ...issueTypeId && { issue_type: issueTypeId },
6847
- ...ownerAttrs
6848
- };
6849
- const { payloadWithoutImage, images } = await separateImageFromFields(offlineRevisionPayload);
6850
- const retRevision = {
6851
- ...payloadWithoutImage,
6852
- created_by: currentUser.id,
6853
- form: retForm.offline_id,
6854
- revision: 0,
6855
- submitted_at: submittedAt
6856
- };
6815
+ async add(ownerId, form, initialRevision, urlPrefix) {
6857
6816
  const { store } = this.client;
6858
- store.dispatch(addForm(retForm));
6859
- store.dispatch(addFormRevision(retRevision));
6817
+ const { fields, images } = await separateImageFromFields(initialRevision.fields);
6818
+ const offlineFormRevision = offline({
6819
+ ...initialRevision,
6820
+ fields,
6821
+ created_by: form.created_by,
6822
+ form: form.offline_id,
6823
+ submitted_at: form.submitted_at,
6824
+ revision: "Pending"
6825
+ });
6826
+ store.dispatch(addForm(form));
6827
+ store.dispatch(addFormRevision(offlineFormRevision));
6860
6828
  const formPromise = this.client.enqueueRequest({
6861
6829
  description: "Create form",
6862
6830
  method: HttpMethod.POST,
6863
- url,
6864
- queryParams: activeWorkspaceId ? {
6865
- workspace_id: activeWorkspaceId
6866
- } : void 0,
6831
+ url: urlPrefix,
6867
6832
  payload: {
6868
- ...offlineFormPayload,
6869
- ...assetTypeId && { asset_type: assetTypeId },
6870
- ...issueTypeId && { issue_type: issueTypeId },
6871
- initial_revision: payloadWithoutImage
6833
+ // Sending exactly what is currently needed for the endpoint
6834
+ offline_id: form.offline_id,
6835
+ initial_revision: {
6836
+ offline_id: offlineFormRevision.offline_id,
6837
+ submitted_at: offlineFormRevision.submitted_at,
6838
+ title: offlineFormRevision.title,
6839
+ description: offlineFormRevision.description,
6840
+ fields: offlineFormRevision.fields
6841
+ }
6872
6842
  },
6873
- blockers: assetTypeId ? [assetTypeId] : issueTypeId ? [issueTypeId] : [],
6874
- blocks: [offlineFormPayload.offline_id, payloadWithoutImage.offline_id]
6843
+ blockers: [ownerId],
6844
+ blocks: [form.offline_id, offlineFormRevision.offline_id]
6875
6845
  });
6876
- const attachImagesPromises = this.getAttachImagePromises(images, offlineRevisionPayload.offline_id);
6846
+ const attachImagesPromises = this.getAttachImagePromises(images, offlineFormRevision.offline_id);
6877
6847
  void formPromise.catch((e) => {
6878
- store.dispatch(deleteForm(retForm.offline_id));
6879
- store.dispatch(deleteFormRevision(retRevision.offline_id));
6848
+ store.dispatch(deleteForm(form.offline_id));
6849
+ store.dispatch(deleteFormRevision(offlineFormRevision.offline_id));
6880
6850
  throw e;
6881
6851
  });
6882
6852
  const settledPromise = Promise.all([formPromise, ...attachImagesPromises]).then(() => formPromise);
6883
- return [retForm, retRevision, formPromise, settledPromise];
6853
+ return [form, offlineFormRevision, formPromise, settledPromise];
6884
6854
  }
6885
- async addForOrganization(initialRevision, attachedTo) {
6855
+ addForOrganization(organizationId, initialRevision) {
6886
6856
  const state = this.client.store.getState();
6887
- const activeOrganizationId = state.organizationReducer.activeOrganizationId;
6888
- if (!activeOrganizationId) {
6889
- throw new Error("Cannot add forms for organization when there is no active organization.");
6890
- }
6891
- return await this.add(
6892
- state,
6857
+ const offlineForm = offline({
6858
+ favorite: false,
6859
+ created_by: state.userReducer.currentUser.id,
6860
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
6861
+ organization: organizationId
6862
+ });
6863
+ return this.add(
6864
+ organizationId.toString(),
6865
+ offlineForm,
6893
6866
  initialRevision,
6894
- `/forms/in-organization/${activeOrganizationId}/`,
6895
- void 0,
6896
- activeOrganizationId,
6897
- attachedTo && "assetTypeId" in attachedTo ? attachedTo.assetTypeId : void 0,
6898
- attachedTo && "issueTypeId" in attachedTo ? attachedTo.issueTypeId : void 0
6867
+ `/organizations/${organizationId}/create-form/`
6899
6868
  );
6900
6869
  }
6901
- async addForCurrentUser(initialRevision, attachedTo) {
6870
+ addForProject(projectId, initialRevision) {
6902
6871
  const state = this.client.store.getState();
6903
- const currentUser = state.userReducer.currentUser;
6904
- return await this.add(
6905
- state,
6906
- initialRevision,
6907
- "/forms/my-forms/",
6908
- currentUser.id,
6909
- void 0,
6910
- attachedTo && "assetTypeId" in attachedTo ? attachedTo.assetTypeId : void 0,
6911
- attachedTo && "issueTypeId" in attachedTo ? attachedTo.issueTypeId : void 0
6912
- );
6872
+ const offlineForm = offline({
6873
+ favorite: false,
6874
+ created_by: state.userReducer.currentUser.id,
6875
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
6876
+ project: projectId
6877
+ });
6878
+ return this.add(projectId.toString(), offlineForm, initialRevision, `/projects/${projectId}/create-form/`);
6879
+ }
6880
+ addForIssueType(issueTypeId, initialRevision) {
6881
+ const state = this.client.store.getState();
6882
+ const offlineForm = offline({
6883
+ favorite: false,
6884
+ created_by: state.userReducer.currentUser.id,
6885
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
6886
+ issue_type: issueTypeId
6887
+ });
6888
+ return this.add(issueTypeId, offlineForm, initialRevision, `/issues/types/${issueTypeId}/create-form/`);
6889
+ }
6890
+ addForAssetType(assetTypeId, initialRevision) {
6891
+ const state = this.client.store.getState();
6892
+ const offlineForm = offline({
6893
+ favorite: false,
6894
+ created_by: state.userReducer.currentUser.id,
6895
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
6896
+ asset_type: assetTypeId
6897
+ });
6898
+ return this.add(assetTypeId, offlineForm, initialRevision, `/assets/types/${assetTypeId}/create-form/`);
6913
6899
  }
6914
6900
  async createRevision(formId2, revision) {
6915
6901
  const offlineRevision = offline(revision);
@@ -6920,9 +6906,10 @@ class UserFormService extends BaseApiService {
6920
6906
  throw new Error("Cannot create form revision when there is no active project.");
6921
6907
  }
6922
6908
  const currentUserId = state.userReducer.currentUser.id;
6923
- const { payloadWithoutImage, images } = await separateImageFromFields(offlineRevision);
6909
+ const { fields, images } = await separateImageFromFields(offlineRevision.fields);
6924
6910
  const fullRevision = {
6925
- ...payloadWithoutImage,
6911
+ ...offlineRevision,
6912
+ fields,
6926
6913
  created_by: currentUserId,
6927
6914
  revision: "Pending",
6928
6915
  form: formId2,
@@ -6933,9 +6920,14 @@ class UserFormService extends BaseApiService {
6933
6920
  description: "Create form revision",
6934
6921
  method: HttpMethod.PATCH,
6935
6922
  url: `/forms/${formId2}/`,
6936
- payload: { initial_revision: payloadWithoutImage },
6937
- queryParams: {
6938
- project_id: activeProjectId.toString()
6923
+ payload: {
6924
+ initial_revision: {
6925
+ offline_id: fullRevision.offline_id,
6926
+ submitted_at: fullRevision.submitted_at,
6927
+ title: fullRevision.title,
6928
+ description: fullRevision.description,
6929
+ fields: fullRevision.fields
6930
+ }
6939
6931
  },
6940
6932
  blockers: [formId2],
6941
6933
  blocks: [offlineRevision.offline_id]
@@ -7020,16 +7012,68 @@ class UserFormService extends BaseApiService {
7020
7012
  }
7021
7013
  async refreshStore() {
7022
7014
  const { store } = this.client;
7023
- const result = await this.client.enqueueRequest({
7024
- description: "Fetch user forms",
7015
+ const activeProjectId = store.getState().projectReducer.activeProjectId;
7016
+ if (!activeProjectId) {
7017
+ throw new Error("No active project");
7018
+ }
7019
+ const forms = [];
7020
+ const revisions = [];
7021
+ const attachments = [];
7022
+ const projectFormsResult = await this.client.enqueueRequest({
7023
+ description: "Fetch project forms",
7025
7024
  method: HttpMethod.GET,
7026
- url: `/forms/in-project/${store.getState().projectReducer.activeProjectId}/forms/`,
7027
- blockers: [],
7025
+ url: `/projects/${activeProjectId}/forms/`,
7026
+ blockers: [activeProjectId.toString()],
7028
7027
  blocks: []
7029
7028
  });
7030
- store.dispatch(setForms(Object.values(result.forms)));
7031
- store.dispatch(setFormRevisions(Object.values(result.revisions)));
7032
- store.dispatch(setFormRevisionAttachments(Object.values(result.attachments)));
7029
+ for (const form of projectFormsResult.forms)
7030
+ forms.push(form);
7031
+ for (const revision of projectFormsResult.revisions)
7032
+ revisions.push(revision);
7033
+ for (const attachment of projectFormsResult.attachments)
7034
+ attachments.push(attachment);
7035
+ const organizationFormsResult = await this.client.enqueueRequest({
7036
+ description: "Fetch organization forms",
7037
+ method: HttpMethod.GET,
7038
+ url: `/projects/${activeProjectId}/organizations/forms/`,
7039
+ blockers: [activeProjectId.toString()],
7040
+ blocks: []
7041
+ });
7042
+ for (const form of organizationFormsResult.forms)
7043
+ forms.push(form);
7044
+ for (const revision of organizationFormsResult.revisions)
7045
+ revisions.push(revision);
7046
+ for (const attachment of organizationFormsResult.attachments)
7047
+ attachments.push(attachment);
7048
+ const assetTypeFormsResult = await this.client.enqueueRequest({
7049
+ description: "Fetch asset type forms",
7050
+ method: HttpMethod.GET,
7051
+ url: `/projects/${activeProjectId}/asset-types/forms/`,
7052
+ blockers: [activeProjectId.toString()],
7053
+ blocks: []
7054
+ });
7055
+ for (const form of assetTypeFormsResult.forms)
7056
+ forms.push(form);
7057
+ for (const revision of assetTypeFormsResult.latest_revisions)
7058
+ revisions.push(revision);
7059
+ for (const attachment of assetTypeFormsResult.attachments)
7060
+ attachments.push(attachment);
7061
+ const issueTypeFormsResult = await this.client.enqueueRequest({
7062
+ description: "Fetch issue type forms",
7063
+ method: HttpMethod.GET,
7064
+ url: `/projects/${activeProjectId}/issue-types/forms/`,
7065
+ blockers: [activeProjectId.toString()],
7066
+ blocks: []
7067
+ });
7068
+ for (const form of issueTypeFormsResult.forms)
7069
+ forms.push(form);
7070
+ for (const revision of issueTypeFormsResult.latest_revisions)
7071
+ revisions.push(revision);
7072
+ for (const attachment of issueTypeFormsResult.attachments)
7073
+ attachments.push(attachment);
7074
+ store.dispatch(setForms(forms));
7075
+ store.dispatch(setFormRevisions(revisions));
7076
+ store.dispatch(setFormRevisionAttachments(attachments));
7033
7077
  }
7034
7078
  }
7035
7079
  const isArrayOfFiles = (value) => {
@@ -18485,7 +18529,6 @@ const styles$2 = {
18485
18529
  regularIcon
18486
18530
  };
18487
18531
  const orgOptionPrefix = "organization:";
18488
- const userOptionPrefix = "user:";
18489
18532
  const FormBrowser = memo(
18490
18533
  forwardRef((props, ref) => {
18491
18534
  const { maxResults = 20, ...entryProps } = props;
@@ -18496,9 +18539,7 @@ const FormBrowser = memo(
18496
18539
  const ret = { maxResults, searchTerm: filter };
18497
18540
  if (ownerFilter) {
18498
18541
  if (ownerFilter.startsWith(orgOptionPrefix)) {
18499
- ret.owner_organization = parseInt(ownerFilter.slice(orgOptionPrefix.length));
18500
- } else if (ownerFilter.startsWith(userOptionPrefix)) {
18501
- ret.owner_user = parseInt(ownerFilter.slice(userOptionPrefix.length));
18542
+ ret.organization = parseInt(ownerFilter.slice(orgOptionPrefix.length));
18502
18543
  }
18503
18544
  }
18504
18545
  return ret;
@@ -18523,14 +18564,10 @@ const FormBrowser = memo(
18523
18564
  const state = sdk.store.getState();
18524
18565
  const accumulator = {};
18525
18566
  for (const form of attachableUserFormMapping) {
18526
- const organization = selectOrganization(form.owner_organization || -1)(state);
18567
+ const organization = selectOrganization(form.organization || -1)(state);
18527
18568
  if (organization) {
18528
18569
  accumulator[`${orgOptionPrefix}${organization.id}`] = organization.name;
18529
18570
  }
18530
- const user = selectUser(form.owner_user || -1)(state);
18531
- if (user) {
18532
- accumulator[`${userOptionPrefix}${user.id}`] = user.username;
18533
- }
18534
18571
  }
18535
18572
  return Object.entries(accumulator).map(([value, label]) => ({ itemContent: label, value }));
18536
18573
  }, [sdk.store, attachableUserFormMapping]);
@@ -18572,11 +18609,7 @@ const FormBrowser = memo(
18572
18609
  const FormBrowserEntry = (props) => {
18573
18610
  var _a2;
18574
18611
  const { form, onSelectForm, isFavoriteEditable, handleToggleFavorite } = props;
18575
- const ownerOrganization = (_a2 = useSelector(selectOrganization(form.owner_organization || -1))) == null ? void 0 : _a2.name;
18576
- const ownerUser = useSelector(selectUser(form.owner_user || -1));
18577
- const currentUserId = useSelector(selectCurrentUser).id;
18578
- const ownedByCurrentUser = !!ownerUser && ownerUser.id === currentUserId;
18579
- const owner = ownerOrganization ?? (ownedByCurrentUser ? "You" : ownerUser == null ? void 0 : ownerUser.username) ?? "Unknown";
18612
+ const ownerOrganization = (_a2 = useSelector(selectOrganization(form.organization || -1))) == null ? void 0 : _a2.name;
18580
18613
  const handleFavoriteClick = useCallback(
18581
18614
  (e) => {
18582
18615
  e.stopPropagation();
@@ -18607,10 +18640,10 @@ const FormBrowserEntry = (props) => {
18607
18640
  /* @__PURE__ */ jsx(Text, { children: form.latestRevision.title }),
18608
18641
  form.latestRevision.description && /* @__PURE__ */ jsx(RiIcon, { icon: "RiQuestionLine" })
18609
18642
  ] }),
18610
- owner && /* @__PURE__ */ jsxs(Flex, { align: "center", gap: "2", children: [
18643
+ ownerOrganization && /* @__PURE__ */ jsxs(Flex, { align: "center", gap: "2", children: [
18611
18644
  /* @__PURE__ */ jsx(RiIcon, { icon: "RiUserLine" }),
18612
18645
  " ",
18613
- owner
18646
+ ownerOrganization
18614
18647
  ] })
18615
18648
  ] })
18616
18649
  }