Skip to content

Commit fc91638

Browse files
committed
InferDomain API call and response to include distinctValues for specified column keys
1 parent 7065171 commit fc91638

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

packages/components/src/public/InferDomainResponse.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fromJS, List, Record } from 'immutable';
1+
import { fromJS, List, Map, Record } from 'immutable';
22

33
import { ActionURL, Ajax, Utils } from '@labkey/api';
44

@@ -9,16 +9,19 @@ export class InferDomainResponse extends Record({
99
fields: List<QueryColumn>(),
1010
reservedFields: List<QueryColumn>(),
1111
commentLineCount: undefined,
12+
distinctValues: Map<string, List<string>>(),
1213
}) {
1314
declare data: List<any>;
1415
declare fields: List<QueryColumn>;
1516
declare reservedFields: List<QueryColumn>;
1617
declare commentLineCount?: number;
18+
declare distinctValues: Map<string, List<string>>;
1719

1820
static create(rawModel): InferDomainResponse {
1921
let data = List<any>();
2022
let fields = List<QueryColumn>();
2123
let reservedFields = List<QueryColumn>();
24+
let distinctValues = Map<string, List<string>>();
2225

2326
if (rawModel) {
2427
if (rawModel.data) {
@@ -32,21 +35,37 @@ export class InferDomainResponse extends Record({
3235
if (rawModel.reservedFields) {
3336
reservedFields = List(rawModel.reservedFields.map(field => new QueryColumn(field)));
3437
}
38+
39+
if (rawModel.distinctValues) {
40+
distinctValues = Map<string, List<string>>(
41+
Object.entries(rawModel.distinctValues).map(([key, value]) => [
42+
key,
43+
List<string>(value),
44+
])
45+
);
46+
}
3547
}
3648

3749
return new InferDomainResponse({
3850
data,
3951
fields,
4052
reservedFields,
4153
commentLineCount: rawModel.commentLineCount,
54+
distinctValues,
4255
});
4356
}
57+
58+
// get the distinct values for a specific column, return empty list if the column doesn't exist
59+
getDistinctValuesForColumn(columnName: string): List<string> {
60+
return this.distinctValues.get(columnName, List<string>());
61+
}
4462
}
4563

4664
export function inferDomainFromFile(
4765
file: File | string, // file or webdav url path
4866
numLinesToInclude: number,
49-
domainKindName?: string
67+
domainKindName?: string,
68+
distinctValueColumns?: string[]
5069
): Promise<InferDomainResponse> {
5170
return new Promise((resolve, reject) => {
5271
const form = new FormData();
@@ -56,6 +75,10 @@ export function inferDomainFromFile(
5675
if (domainKindName) {
5776
form.append('domainKindName', domainKindName);
5877
}
78+
if (distinctValueColumns && distinctValueColumns.length > 0) {
79+
// append each value separately so they are received as an array on the server
80+
distinctValueColumns.forEach(col => form.append('distinctValueColumns', col));
81+
}
5982

6083
Ajax.request({
6184
url: ActionURL.buildURL('property', 'inferDomain.api'),

packages/components/src/public/files/FileAttachmentForm.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,13 @@ export class FileAttachmentForm extends PureComponent<FileAttachmentFormProps, S
306306
}
307307
}
308308

309-
this.updatePreviewStatus('Uploading file...');
310-
311-
inferDomainFromFile(file, previewGridProps.previewCount, previewGridProps.domainKindName)
309+
this.updatePreviewStatus('Loading file preview...');
310+
inferDomainFromFile(
311+
file,
312+
previewGridProps.previewCount,
313+
previewGridProps.domainKindName,
314+
previewGridProps.distinctValueColumns
315+
)
312316
.then(response => {
313317
this.updatePreviewStatus(null);
314318

packages/components/src/public/files/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface FileSizeLimitProps {
1919

2020
export interface FileGridPreviewProps {
2121
acceptedFormats?: string; // comma-separated list of allowed extensions i.e. '.png, .jpg, .jpeg'
22+
distinctValueColumns?: string[];
2223
domainKindName?: string;
2324
errorStyle?: string;
2425
header?: string;

0 commit comments

Comments
 (0)