Skip to content

Commit 37a4375

Browse files
committed
Dataset: does not need to save in session
1 parent 0f2ca41 commit 37a4375

1 file changed

Lines changed: 23 additions & 42 deletions

File tree

  • packages/components/src/internal/components/domainproperties/dataset

packages/components/src/internal/components/domainproperties/dataset/actions.ts

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { ActionURL, Domain } from '@labkey/api';
1617

17-
import { ActionURL, Ajax, Domain, Utils } from '@labkey/api';
18-
19-
import { fromJS, List } from 'immutable';
18+
import { List } from 'immutable';
2019

2120
import { SelectInputOption } from '../../forms/input/SelectInput';
22-
import { selectRowsDeprecated } from '../../../query/api';
2321
import { DomainDesign } from '../models';
2422

2523
import {
@@ -37,12 +35,14 @@ import {
3735
import { DatasetModel } from './models';
3836
import { StudyProperties } from './utils';
3937
import { executeSql } from '../../../query/executeSql';
38+
import { SCHEMAS } from '../../../schemas';
39+
import { selectRows } from '../../../query/selectRows';
40+
import { caseInsensitive } from '../../../util/utils';
41+
import { request } from '../../../request';
4042

4143
export async function fetchCategories(): Promise<SelectInputOption[]> {
42-
// TODO: Does this need to be using executeSql? Would selectRows be able to accomplish the same thing?
4344
const result = await executeSql({
44-
saveInSession: true,
45-
schemaName: 'study',
45+
schemaName: SCHEMAS.STUDY_TABLES.SCHEMA,
4646
sql: 'SELECT DISTINCT CategoryId.Label, CategoryId.RowId FROM DataSets',
4747
});
4848

@@ -87,30 +87,16 @@ export function getAdditionalKeyFields(domain: DomainDesign, timepointType: stri
8787
return additionalKeyFields;
8888
}
8989

90-
export function fetchCohorts(): Promise<SelectInputOption[]> {
91-
return new Promise((resolve, reject) => {
92-
selectRowsDeprecated({
93-
schemaName: 'study',
94-
queryName: 'Cohort',
95-
})
96-
.then(data => {
97-
const models = fromJS(data.models[data.key]);
98-
const cohorts = [];
99-
100-
data.orderedModels[data.key].forEach(modelKey => {
101-
const row = models.get(modelKey);
102-
const value = row.getIn(['rowid', 'value']);
103-
const label = row.getIn(['label', 'value']);
104-
105-
cohorts.push({ value, label });
106-
});
107-
108-
resolve(cohorts);
109-
})
110-
.catch(response => {
111-
reject(response.message);
112-
});
90+
export async function fetchCohorts(): Promise<SelectInputOption[]> {
91+
const results = await selectRows({
92+
columns: ['Label', 'RowId'],
93+
schemaQuery: SCHEMAS.STUDY_TABLES.COHORT,
11394
});
95+
96+
return results.rows.map(row => ({
97+
label: caseInsensitive(row, 'Label').value,
98+
value: caseInsensitive(row, 'RowId').value,
99+
}));
114100
}
115101

116102
export function getHelpTip(fieldName: string, studyProperties: StudyProperties): string {
@@ -159,19 +145,14 @@ export function getHelpTip(fieldName: string, studyProperties: StudyProperties):
159145
return helpTip;
160146
}
161147

162-
function getDatasetProperties(datasetId?: number): Promise<DatasetModel> {
163-
return new Promise((resolve, reject) => {
164-
Ajax.request({
165-
url: ActionURL.buildURL('study', 'getDataset.api'),
166-
params: { datasetId },
167-
success: Utils.getCallbackWrapper(data => {
168-
resolve(DatasetModel.create(data, undefined));
169-
}),
170-
failure: Utils.getCallbackWrapper(error => {
171-
reject(error);
172-
}),
173-
});
148+
async function getDatasetProperties(datasetId?: number): Promise<DatasetModel> {
149+
const result = await request({
150+
url: ActionURL.buildURL('study', 'getDataset.api'),
151+
params: { datasetId },
152+
errorLogMsg: 'Failed to load dataset properties',
174153
});
154+
155+
return DatasetModel.create(result);
175156
}
176157

177158
export function fetchDatasetDesign(datasetId?: number): Promise<DatasetModel> {

0 commit comments

Comments
 (0)