Skip to content

Commit 1ec2254

Browse files
authored
AssayDOM.importRun: support "plateMetadata" property (#155)
1 parent 928b577 commit 1ec2254

File tree

6 files changed

+31
-39
lines changed

6 files changed

+31
-39
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.22.0 - 2023-07-14
2+
- Support `plateMetadata` JSON property on `AssayDOM.importRun`.
3+
- Rename `IImportRunOptions` to `ImportRunOptions`.
4+
- Extend `RequestCallbackOptions` to streamline usage of common request options.
5+
- Factor out superfluous `FormWindow` type. TypeScript typings for DOM libraries have improved since initial implementation.
6+
17
## 1.21.0 - 2023-05-23
28
- Fixes the implementation of `List.create()` to support `keyName` and `keyType` as they were originally documented.
39
- Deprecate `keyName` in favor of specifying `options.keyName` as specified on `Domain.create()`.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@labkey/api",
3-
"version": "1.21.0",
3+
"version": "1.22.0",
44
"description": "JavaScript client API for LabKey Server",
55
"scripts": {
66
"build": "npm run build:dist && npm run build:docs",

src/labkey/dom/Assay.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
*/
1616
import { buildURL } from '../ActionURL';
1717
import { request } from '../Ajax';
18-
import { getCallbackWrapper, getOnFailure, getOnSuccess, isObject } from '../Utils';
18+
import { getCallbackWrapper, getOnFailure, getOnSuccess, isObject, RequestCallbackOptions } from '../Utils';
1919

20-
import { FormWindow } from './constants';
21-
22-
declare let window: FormWindow;
23-
24-
export interface IImportRunOptions {
20+
export interface ImportRunOptions extends RequestCallbackOptions {
2521
allowCrossRunFileInputs?: boolean;
2622
allowLookupByAlternateKey?: boolean;
2723
assayId?: number | string;
@@ -31,23 +27,21 @@ export interface IImportRunOptions {
3127
comments?: string;
3228
containerPath?: string;
3329
dataRows?: any[];
34-
failure?: Function;
3530
files?: any[];
3631
forceAsync?: boolean;
3732
jobDescription?: string;
3833
jobNotificationProvider?: string;
3934
name?: string;
35+
plateMetadata?: any;
4036
properties?: any;
4137
reRunId?: number | string;
4238
runFilePath?: string;
4339
saveDataAsFile?: boolean;
44-
scope?: any;
45-
success: Function;
4640
workflowTask?: number;
4741
}
4842

49-
export function importRun(options: IImportRunOptions): void {
50-
if (!window.FormData) {
43+
export function importRun(options: ImportRunOptions): XMLHttpRequest {
44+
if (!FormData) {
5145
throw new Error('modern browser required');
5246
}
5347

@@ -59,7 +53,7 @@ export function importRun(options: IImportRunOptions): void {
5953
if (options.files) {
6054
for (let i = 0; i < options.files.length; i++) {
6155
const f = options.files[i];
62-
if (f instanceof window.File) {
56+
if (f instanceof File) {
6357
files.push(f);
6458
} else if (f.tagName == 'INPUT') {
6559
for (let j = 0; j < f.files.length; j++) {
@@ -114,25 +108,21 @@ export function importRun(options: IImportRunOptions): void {
114108
}
115109

116110
if (options.properties) {
117-
for (const key in options.properties) {
118-
if (options.properties.hasOwnProperty(key)) {
119-
if (isObject(options.properties[key])) {
120-
formData.append("properties['" + key + "']", JSON.stringify(options.properties[key]));
121-
} else {
122-
formData.append("properties['" + key + "']", options.properties[key]);
123-
}
111+
for (const [key, value] of Object.entries(options.properties)) {
112+
if (isObject(value)) {
113+
formData.append(`properties['${key}']`, JSON.stringify(value));
114+
} else {
115+
formData.append(`properties['${key}']`, options.properties[key]);
124116
}
125117
}
126118
}
127119

128120
if (options.batchProperties) {
129-
for (const key in options.batchProperties) {
130-
if (options.batchProperties.hasOwnProperty(key)) {
131-
if (isObject(options.batchProperties[key])) {
132-
formData.append("batchProperties['" + key + "']", JSON.stringify(options.batchProperties[key]));
133-
} else {
134-
formData.append("batchProperties['" + key + "']", options.batchProperties[key]);
135-
}
121+
for (const [key, value] of Object.entries(options.batchProperties)) {
122+
if (isObject(value)) {
123+
formData.append(`batchProperties['${key}']`, JSON.stringify(value));
124+
} else {
125+
formData.append(`batchProperties['${key}']`, options.batchProperties[key]);
136126
}
137127
}
138128
}
@@ -152,7 +142,11 @@ export function importRun(options: IImportRunOptions): void {
152142
}
153143
}
154144

155-
request({
145+
if (options.plateMetadata) {
146+
formData.append('plateMetadata', JSON.stringify(options.plateMetadata));
147+
}
148+
149+
return request({
156150
url: buildURL('assay', 'importRun.api', options.containerPath),
157151
method: 'POST',
158152
success: getCallbackWrapper(getOnSuccess(options), options.scope),

src/labkey/dom/Query.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ import { getCallbackWrapper, getOnFailure, getOnSuccess, merge } from '../Utils'
1919
import { appendFilterParams } from '../filter/Filter';
2020
import { ContainerFilter } from '../query/Utils';
2121

22-
import { FormWindow } from './constants';
2322
import { postToAction } from './Utils';
2423

25-
declare let window: FormWindow;
26-
2724
export interface IExportSqlOptions {
2825
containerFilter?: ContainerFilter;
2926
containerPath?: string;
@@ -120,7 +117,7 @@ export interface IImportDataOptions {
120117
}
121118

122119
export function importData(options: IImportDataOptions): XMLHttpRequest {
123-
if (!window.FormData) {
120+
if (!FormData) {
124121
throw new Error('modern browser required');
125122
}
126123

src/labkey/dom/constants.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
*/
1616
import { LabKey } from '../constants';
1717

18-
export interface FormWindow extends Window {
19-
File: any;
20-
FormData: any;
21-
}
22-
2318
export interface LabKeyDOM extends LabKey {
2419
$: any;
2520
requiresExt4ClientAPI: Function;

0 commit comments

Comments
 (0)