@overmap-ai/core 1.0.58-asset-description.10 → 1.0.58-csv-parse-fix.0

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.
@@ -3822,17 +3822,15 @@ var __publicField = (obj, key, value) => {
3822
3822
  (_state, search) => search
3823
3823
  ],
3824
3824
  (userForms, revisions, search) => {
3825
- const { searchTerm, maxResults, favorites, owner_organization, owner_user } = search;
3825
+ const { searchTerm, maxResults, favorites, organization } = search;
3826
3826
  const favoriteMatches = [];
3827
3827
  const regularMatches = [];
3828
3828
  for (const [userFormId, userForm] of Object.entries(userForms)) {
3829
3829
  if (favorites !== void 0 && userForm.favorite != favorites)
3830
3830
  continue;
3831
- if (Number.isInteger(owner_organization) && owner_organization !== userForm.owner_organization) {
3831
+ if (Number.isInteger(organization) && organization !== userForm.organization) {
3832
3832
  continue;
3833
3833
  }
3834
- if (Number.isInteger(owner_user) && owner_user !== userForm.owner_user)
3835
- continue;
3836
3834
  const latestRevision = _selectLatestFormRevision(revisions, userFormId);
3837
3835
  if (latestRevision.title.toLowerCase().includes(searchTerm.toLowerCase())) {
3838
3836
  if (userForm.favorite) {
@@ -4617,10 +4615,6 @@ var __publicField = (obj, key, value) => {
4617
4615
  throw new Error(`Failed to update index_workspace of issue ${issue.offline_id} to main workspace`);
4618
4616
  }
4619
4617
  }
4620
- const indexedForms = Object.values(draft.formReducer.forms).filter((form) => form.index_workspace === workspaceId);
4621
- for (const form of indexedForms) {
4622
- form.index_workspace = mainWorkspace.offline_id;
4623
- }
4624
4618
  }
4625
4619
  const rootReducer = (state, action) => {
4626
4620
  if (action.type === "auth/setLoggedIn" && !action.payload) {
@@ -5479,6 +5473,7 @@ var __publicField = (obj, key, value) => {
5479
5473
  bulkAdd(assetsToCreate, workspaceId, assetTypeId, batchSize) {
5480
5474
  const { store } = this.client;
5481
5475
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
5476
+ const transactionId = uuid.v4();
5482
5477
  const assetBatches = chunkArray(assetsToCreate, batchSize).map((assetBatch) => {
5483
5478
  const assetPayloads = assetBatch.map((assetPayload) => {
5484
5479
  return offline({
@@ -5489,6 +5484,7 @@ var __publicField = (obj, key, value) => {
5489
5484
  return {
5490
5485
  batchId: uuid.v4(),
5491
5486
  payload: {
5487
+ transaction_id: transactionId,
5492
5488
  assets: assetPayloads
5493
5489
  }
5494
5490
  };
@@ -7013,8 +7009,7 @@ var __publicField = (obj, key, value) => {
7013
7009
  });
7014
7010
  }
7015
7011
  }
7016
- const separateImageFromFields = async (payload) => {
7017
- const { fields } = payload;
7012
+ const separateImageFromFields = async (fields) => {
7018
7013
  const images = {};
7019
7014
  const newFields = [];
7020
7015
  for (const section of fields) {
@@ -7040,11 +7035,7 @@ var __publicField = (obj, key, value) => {
7040
7035
  }
7041
7036
  newFields.push({ ...section, fields: newSectionFields });
7042
7037
  }
7043
- const payloadWithoutImage = {
7044
- ...payload,
7045
- fields: newFields
7046
- };
7047
- return { payloadWithoutImage, images };
7038
+ return { fields: newFields, images };
7048
7039
  };
7049
7040
  class UserFormService extends BaseApiService {
7050
7041
  constructor() {
@@ -7078,93 +7069,90 @@ var __publicField = (obj, key, value) => {
7078
7069
  });
7079
7070
  });
7080
7071
  }
7081
- async add(state, initialRevision, url, ownerUser, ownerOrganization, assetTypeId, issueTypeId) {
7082
- if (!!ownerUser === !!ownerOrganization) {
7083
- throw new Error("Exactly one of ownerUser and ownerOrganization must be defined.");
7084
- }
7085
- const ownerAttrs = {
7086
- owner_user: ownerUser,
7087
- owner_organization: ownerOrganization
7088
- };
7089
- const currentUser = state.userReducer.currentUser;
7090
- const activeWorkspaceId = state.workspaceReducer.activeWorkspaceId;
7091
- const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
7092
- const offlineFormPayload = offline({ ...ownerAttrs });
7093
- const offlineRevisionPayload = offline({ ...initialRevision, submitted_at: submittedAt });
7094
- const retForm = {
7095
- ...offlineFormPayload,
7096
- index_workspace: activeWorkspaceId,
7097
- favorite: true,
7098
- submitted_at: submittedAt,
7099
- created_by: currentUser.id,
7100
- ...assetTypeId && { asset_type: assetTypeId },
7101
- ...issueTypeId && { issue_type: issueTypeId },
7102
- ...ownerAttrs
7103
- };
7104
- const { payloadWithoutImage, images } = await separateImageFromFields(offlineRevisionPayload);
7105
- const retRevision = {
7106
- ...payloadWithoutImage,
7107
- created_by: currentUser.id,
7108
- form: retForm.offline_id,
7109
- revision: 0,
7110
- submitted_at: submittedAt
7111
- };
7072
+ async add(ownerId, form, initialRevision, urlPrefix) {
7112
7073
  const { store } = this.client;
7113
- store.dispatch(addForm(retForm));
7114
- store.dispatch(addFormRevision(retRevision));
7074
+ const { fields, images } = await separateImageFromFields(initialRevision.fields);
7075
+ const offlineFormRevision = offline({
7076
+ ...initialRevision,
7077
+ fields,
7078
+ created_by: form.created_by,
7079
+ form: form.offline_id,
7080
+ submitted_at: form.submitted_at,
7081
+ revision: "Pending"
7082
+ });
7083
+ store.dispatch(addForm(form));
7084
+ store.dispatch(addFormRevision(offlineFormRevision));
7115
7085
  const formPromise = this.client.enqueueRequest({
7116
7086
  description: "Create form",
7117
7087
  method: HttpMethod.POST,
7118
- url,
7119
- queryParams: activeWorkspaceId ? {
7120
- workspace_id: activeWorkspaceId
7121
- } : void 0,
7088
+ url: urlPrefix,
7122
7089
  payload: {
7123
- ...offlineFormPayload,
7124
- ...assetTypeId && { asset_type: assetTypeId },
7125
- ...issueTypeId && { issue_type: issueTypeId },
7126
- initial_revision: payloadWithoutImage
7090
+ // Sending exactly what is currently needed for the endpoint
7091
+ offline_id: form.offline_id,
7092
+ initial_revision: {
7093
+ offline_id: offlineFormRevision.offline_id,
7094
+ submitted_at: offlineFormRevision.submitted_at,
7095
+ title: offlineFormRevision.title,
7096
+ description: offlineFormRevision.description,
7097
+ fields: offlineFormRevision.fields
7098
+ }
7127
7099
  },
7128
- blockers: assetTypeId ? [assetTypeId] : issueTypeId ? [issueTypeId] : [],
7129
- blocks: [offlineFormPayload.offline_id, payloadWithoutImage.offline_id]
7100
+ blockers: [ownerId],
7101
+ blocks: [form.offline_id, offlineFormRevision.offline_id]
7130
7102
  });
7131
- const attachImagesPromises = this.getAttachImagePromises(images, offlineRevisionPayload.offline_id);
7103
+ const attachImagesPromises = this.getAttachImagePromises(images, offlineFormRevision.offline_id);
7132
7104
  void formPromise.catch((e) => {
7133
- store.dispatch(deleteForm(retForm.offline_id));
7134
- store.dispatch(deleteFormRevision(retRevision.offline_id));
7105
+ store.dispatch(deleteForm(form.offline_id));
7106
+ store.dispatch(deleteFormRevision(offlineFormRevision.offline_id));
7135
7107
  throw e;
7136
7108
  });
7137
7109
  const settledPromise = Promise.all([formPromise, ...attachImagesPromises]).then(() => formPromise);
7138
- return [retForm, retRevision, formPromise, settledPromise];
7110
+ return [form, offlineFormRevision, formPromise, settledPromise];
7139
7111
  }
7140
- async addForOrganization(initialRevision, attachedTo) {
7112
+ addForOrganization(organizationId, initialRevision) {
7141
7113
  const state = this.client.store.getState();
7142
- const activeOrganizationId = state.organizationReducer.activeOrganizationId;
7143
- if (!activeOrganizationId) {
7144
- throw new Error("Cannot add forms for organization when there is no active organization.");
7145
- }
7146
- return await this.add(
7147
- state,
7114
+ const offlineForm = offline({
7115
+ favorite: false,
7116
+ created_by: state.userReducer.currentUser.id,
7117
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
7118
+ organization: organizationId
7119
+ });
7120
+ return this.add(
7121
+ organizationId.toString(),
7122
+ offlineForm,
7148
7123
  initialRevision,
7149
- `/forms/in-organization/${activeOrganizationId}/`,
7150
- void 0,
7151
- activeOrganizationId,
7152
- attachedTo && "assetTypeId" in attachedTo ? attachedTo.assetTypeId : void 0,
7153
- attachedTo && "issueTypeId" in attachedTo ? attachedTo.issueTypeId : void 0
7124
+ `/organizations/${organizationId}/create-form/`
7154
7125
  );
7155
7126
  }
7156
- async addForCurrentUser(initialRevision, attachedTo) {
7127
+ addForProject(projectId, initialRevision) {
7157
7128
  const state = this.client.store.getState();
7158
- const currentUser = state.userReducer.currentUser;
7159
- return await this.add(
7160
- state,
7161
- initialRevision,
7162
- "/forms/my-forms/",
7163
- currentUser.id,
7164
- void 0,
7165
- attachedTo && "assetTypeId" in attachedTo ? attachedTo.assetTypeId : void 0,
7166
- attachedTo && "issueTypeId" in attachedTo ? attachedTo.issueTypeId : void 0
7167
- );
7129
+ const offlineForm = offline({
7130
+ favorite: false,
7131
+ created_by: state.userReducer.currentUser.id,
7132
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
7133
+ project: projectId
7134
+ });
7135
+ return this.add(projectId.toString(), offlineForm, initialRevision, `/projects/${projectId}/create-form/`);
7136
+ }
7137
+ addForIssueType(issueTypeId, initialRevision) {
7138
+ const state = this.client.store.getState();
7139
+ const offlineForm = offline({
7140
+ favorite: false,
7141
+ created_by: state.userReducer.currentUser.id,
7142
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
7143
+ issue_type: issueTypeId
7144
+ });
7145
+ return this.add(issueTypeId, offlineForm, initialRevision, `/issues/types/${issueTypeId}/create-form/`);
7146
+ }
7147
+ addForAssetType(assetTypeId, initialRevision) {
7148
+ const state = this.client.store.getState();
7149
+ const offlineForm = offline({
7150
+ favorite: false,
7151
+ created_by: state.userReducer.currentUser.id,
7152
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
7153
+ asset_type: assetTypeId
7154
+ });
7155
+ return this.add(assetTypeId, offlineForm, initialRevision, `/assets/types/${assetTypeId}/create-form/`);
7168
7156
  }
7169
7157
  async createRevision(formId2, revision) {
7170
7158
  const offlineRevision = offline(revision);
@@ -7175,9 +7163,10 @@ var __publicField = (obj, key, value) => {
7175
7163
  throw new Error("Cannot create form revision when there is no active project.");
7176
7164
  }
7177
7165
  const currentUserId = state.userReducer.currentUser.id;
7178
- const { payloadWithoutImage, images } = await separateImageFromFields(offlineRevision);
7166
+ const { fields, images } = await separateImageFromFields(offlineRevision.fields);
7179
7167
  const fullRevision = {
7180
- ...payloadWithoutImage,
7168
+ ...offlineRevision,
7169
+ fields,
7181
7170
  created_by: currentUserId,
7182
7171
  revision: "Pending",
7183
7172
  form: formId2,
@@ -7188,9 +7177,14 @@ var __publicField = (obj, key, value) => {
7188
7177
  description: "Create form revision",
7189
7178
  method: HttpMethod.PATCH,
7190
7179
  url: `/forms/${formId2}/`,
7191
- payload: { initial_revision: payloadWithoutImage },
7192
- queryParams: {
7193
- project_id: activeProjectId.toString()
7180
+ payload: {
7181
+ initial_revision: {
7182
+ offline_id: fullRevision.offline_id,
7183
+ submitted_at: fullRevision.submitted_at,
7184
+ title: fullRevision.title,
7185
+ description: fullRevision.description,
7186
+ fields: fullRevision.fields
7187
+ }
7194
7188
  },
7195
7189
  blockers: [formId2],
7196
7190
  blocks: [offlineRevision.offline_id]
@@ -7275,16 +7269,68 @@ var __publicField = (obj, key, value) => {
7275
7269
  }
7276
7270
  async refreshStore() {
7277
7271
  const { store } = this.client;
7278
- const result = await this.client.enqueueRequest({
7279
- description: "Fetch user forms",
7272
+ const activeProjectId = store.getState().projectReducer.activeProjectId;
7273
+ if (!activeProjectId) {
7274
+ throw new Error("No active project");
7275
+ }
7276
+ const forms = [];
7277
+ const revisions = [];
7278
+ const attachments = [];
7279
+ const projectFormsResult = await this.client.enqueueRequest({
7280
+ description: "Fetch project forms",
7280
7281
  method: HttpMethod.GET,
7281
- url: `/forms/in-project/${store.getState().projectReducer.activeProjectId}/forms/`,
7282
- blockers: [],
7282
+ url: `/projects/${activeProjectId}/forms/`,
7283
+ blockers: [activeProjectId.toString()],
7283
7284
  blocks: []
7284
7285
  });
7285
- store.dispatch(setForms(Object.values(result.forms)));
7286
- store.dispatch(setFormRevisions(Object.values(result.revisions)));
7287
- store.dispatch(setFormRevisionAttachments(Object.values(result.attachments)));
7286
+ for (const form of projectFormsResult.forms)
7287
+ forms.push(form);
7288
+ for (const revision of projectFormsResult.revisions)
7289
+ revisions.push(revision);
7290
+ for (const attachment of projectFormsResult.attachments)
7291
+ attachments.push(attachment);
7292
+ const organizationFormsResult = await this.client.enqueueRequest({
7293
+ description: "Fetch organization forms",
7294
+ method: HttpMethod.GET,
7295
+ url: `/projects/${activeProjectId}/organizations/forms/`,
7296
+ blockers: [activeProjectId.toString()],
7297
+ blocks: []
7298
+ });
7299
+ for (const form of organizationFormsResult.forms)
7300
+ forms.push(form);
7301
+ for (const revision of organizationFormsResult.revisions)
7302
+ revisions.push(revision);
7303
+ for (const attachment of organizationFormsResult.attachments)
7304
+ attachments.push(attachment);
7305
+ const assetTypeFormsResult = await this.client.enqueueRequest({
7306
+ description: "Fetch asset type forms",
7307
+ method: HttpMethod.GET,
7308
+ url: `/projects/${activeProjectId}/asset-types/forms/`,
7309
+ blockers: [activeProjectId.toString()],
7310
+ blocks: []
7311
+ });
7312
+ for (const form of assetTypeFormsResult.forms)
7313
+ forms.push(form);
7314
+ for (const revision of assetTypeFormsResult.latest_revisions)
7315
+ revisions.push(revision);
7316
+ for (const attachment of assetTypeFormsResult.attachments)
7317
+ attachments.push(attachment);
7318
+ const issueTypeFormsResult = await this.client.enqueueRequest({
7319
+ description: "Fetch issue type forms",
7320
+ method: HttpMethod.GET,
7321
+ url: `/projects/${activeProjectId}/issue-types/forms/`,
7322
+ blockers: [activeProjectId.toString()],
7323
+ blocks: []
7324
+ });
7325
+ for (const form of issueTypeFormsResult.forms)
7326
+ forms.push(form);
7327
+ for (const revision of issueTypeFormsResult.latest_revisions)
7328
+ revisions.push(revision);
7329
+ for (const attachment of issueTypeFormsResult.attachments)
7330
+ attachments.push(attachment);
7331
+ store.dispatch(setForms(forms));
7332
+ store.dispatch(setFormRevisions(revisions));
7333
+ store.dispatch(setFormRevisionAttachments(attachments));
7288
7334
  }
7289
7335
  }
7290
7336
  const isArrayOfFiles = (value) => {
@@ -7393,6 +7439,7 @@ var __publicField = (obj, key, value) => {
7393
7439
  const allFilesRecord = {};
7394
7440
  const { values: fileSeperatedCommonFieldValues, files: commonFiles } = separateFilesFromValues(commonFieldValues);
7395
7441
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
7442
+ const transactionId = uuid.v4();
7396
7443
  const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), batchSize);
7397
7444
  const bulkAddBatches = await Promise.all(
7398
7445
  assetIdBatches.map(async (assetIdBatch) => {
@@ -7437,6 +7484,7 @@ var __publicField = (obj, key, value) => {
7437
7484
  return {
7438
7485
  batchId,
7439
7486
  payload: {
7487
+ transaction_id: transactionId,
7440
7488
  form_data: fileSeperatedCommonFieldValues,
7441
7489
  submitted_at: submittedAt,
7442
7490
  submissions: submissionPayloads,
@@ -8854,6 +8902,9 @@ var __publicField = (obj, key, value) => {
8854
8902
  return [...this.formValidators];
8855
8903
  }
8856
8904
  encodeValueToJson(value) {
8905
+ if (typeof value === "string") {
8906
+ return value;
8907
+ }
8857
8908
  return JSON.stringify(value);
8858
8909
  }
8859
8910
  decodeJsonToValue(json) {
@@ -13233,7 +13284,10 @@ var __publicField = (obj, key, value) => {
13233
13284
  mb: "1",
13234
13285
  asChild: true,
13235
13286
  children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Badge, { color: "gray", size: "2", children: [
13236
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: option }),
13287
+ /* @__PURE__ */ jsxRuntime.jsx("span", {
13288
+ // TODO: remove this, its just a saftey check for old compatibility of what was acceptable as a value for multi string
13289
+ children: typeof option === "object" && "label" in option ? option.label : option
13290
+ }),
13237
13291
  /* @__PURE__ */ jsxRuntime.jsx(
13238
13292
  blocks.IconButton,
13239
13293
  {
@@ -15342,7 +15396,6 @@ var __publicField = (obj, key, value) => {
15342
15396
  regularIcon
15343
15397
  };
15344
15398
  const orgOptionPrefix = "organization:";
15345
- const userOptionPrefix = "user:";
15346
15399
  const FormBrowser = React.memo(
15347
15400
  React.forwardRef((props, ref) => {
15348
15401
  const { maxResults = 20, ...entryProps } = props;
@@ -15353,9 +15406,7 @@ var __publicField = (obj, key, value) => {
15353
15406
  const ret = { maxResults, searchTerm: filter };
15354
15407
  if (ownerFilter) {
15355
15408
  if (ownerFilter.startsWith(orgOptionPrefix)) {
15356
- ret.owner_organization = parseInt(ownerFilter.slice(orgOptionPrefix.length));
15357
- } else if (ownerFilter.startsWith(userOptionPrefix)) {
15358
- ret.owner_user = parseInt(ownerFilter.slice(userOptionPrefix.length));
15409
+ ret.organization = parseInt(ownerFilter.slice(orgOptionPrefix.length));
15359
15410
  }
15360
15411
  }
15361
15412
  return ret;
@@ -15380,14 +15431,10 @@ var __publicField = (obj, key, value) => {
15380
15431
  const state = sdk.store.getState();
15381
15432
  const accumulator = {};
15382
15433
  for (const form of attachableUserFormMapping) {
15383
- const organization = selectOrganization(form.owner_organization || -1)(state);
15434
+ const organization = selectOrganization(form.organization || -1)(state);
15384
15435
  if (organization) {
15385
15436
  accumulator[`${orgOptionPrefix}${organization.id}`] = organization.name;
15386
15437
  }
15387
- const user = selectUser(form.owner_user || -1)(state);
15388
- if (user) {
15389
- accumulator[`${userOptionPrefix}${user.id}`] = user.username;
15390
- }
15391
15438
  }
15392
15439
  return Object.entries(accumulator).map(([value, label]) => ({ itemContent: label, value }));
15393
15440
  }, [sdk.store, attachableUserFormMapping]);
@@ -15429,11 +15476,7 @@ var __publicField = (obj, key, value) => {
15429
15476
  const FormBrowserEntry = (props) => {
15430
15477
  var _a2;
15431
15478
  const { form, onSelectForm, isFavoriteEditable, handleToggleFavorite } = props;
15432
- const ownerOrganization = (_a2 = useAppSelector(selectOrganization(form.owner_organization || -1))) == null ? void 0 : _a2.name;
15433
- const ownerUser = useAppSelector(selectUser(form.owner_user || -1));
15434
- const currentUserId = useAppSelector(selectCurrentUser).id;
15435
- const ownedByCurrentUser = !!ownerUser && ownerUser.id === currentUserId;
15436
- const owner = ownerOrganization ?? (ownedByCurrentUser ? "You" : ownerUser == null ? void 0 : ownerUser.username) ?? "Unknown";
15479
+ const ownerOrganization = (_a2 = useAppSelector(selectOrganization(form.organization || -1))) == null ? void 0 : _a2.name;
15437
15480
  const handleFavoriteClick = React.useCallback(
15438
15481
  (e) => {
15439
15482
  e.stopPropagation();
@@ -15464,10 +15507,10 @@ var __publicField = (obj, key, value) => {
15464
15507
  /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { noWrap: true, children: form.latestRevision.title }),
15465
15508
  form.latestRevision.description && /* @__PURE__ */ jsxRuntime.jsx(blocks.RiIcon, { icon: "RiQuestionLine" })
15466
15509
  ] }),
15467
- owner && /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { align: "center", gap: "2", children: [
15510
+ ownerOrganization && /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { align: "center", gap: "2", children: [
15468
15511
  /* @__PURE__ */ jsxRuntime.jsx(blocks.RiIcon, { icon: "RiUserLine" }),
15469
15512
  " ",
15470
- owner
15513
+ ownerOrganization
15471
15514
  ] })
15472
15515
  ] })
15473
15516
  }