-
Notifications
You must be signed in to change notification settings - Fork 2
Molecule and PS bulk import by file #1998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
d0b1633
85e0163
68b71a2
c269008
30786ca
f278b64
7e9b06f
bef4b4b
0f2a21b
d55f6ea
a756c82
b51443e
04e8292
7cce3c4
868aab2
0ccf2dd
23d8443
d64fe3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,10 @@ import { resolveErrorMessage } from './util/messaging'; | |
|
|
||
| import { ViewInfo } from './ViewInfo'; | ||
| import { createGridModelId } from './models'; | ||
| import { SAMPLES_KEY } from './app/constants'; | ||
| import { SAMPLES_KEY, SOURCES_KEY } from './app/constants'; | ||
| import { SCHEMAS } from './schemas'; | ||
| import { selectRows } from './query/selectRows'; | ||
| import { caseInsensitive } from './util/utils'; | ||
|
|
||
| export function selectAll( | ||
| key: string, | ||
|
|
@@ -62,12 +64,19 @@ export function selectAll( | |
| }); | ||
| } | ||
|
|
||
| type DataTypeRowIdsFromTransactionIds = { | ||
| dataTypeRowCounts: Record<number, number>; | ||
| typeNameRowCounts?: Record<string, number>; | ||
| dataTypes?: string[]; | ||
| rowIds: string[]; | ||
| }; | ||
|
|
||
| export async function getGridIdsFromTransactionId( | ||
| transactionAuditId: number | string, | ||
| dataType: string, | ||
| containerPath?: string | ||
| ): Promise<string[]> { | ||
| if (!transactionAuditId) return; | ||
| ): Promise<DataTypeRowIdsFromTransactionIds> { | ||
| if (!transactionAuditId) return { rowIds: [], dataTypeRowCounts: {} }; | ||
|
|
||
| const failureMsg = `There was a problem retrieving the ${dataType} from the last action.`; | ||
| const errorLogMsg = `${failureMsg} (transactionAuditId = ${transactionAuditId})`; | ||
|
|
@@ -88,7 +97,11 @@ export async function getGridIdsFromTransactionId( | |
| } | ||
|
|
||
| // The server returns numbers, so we coerce to string; If we don't, it can lead to bugs (and has). | ||
| return response.rowIds.map(rowId => rowId.toString()); | ||
| const rowIds = response.rowIds.map(rowId => rowId.toString()); | ||
| return { | ||
| rowIds, | ||
| dataTypeRowCounts: response['dataTypeRowCounts'], | ||
| }; | ||
| } | ||
|
|
||
| export async function selectGridIdsFromTransactionId( | ||
|
|
@@ -97,32 +110,81 @@ export async function selectGridIdsFromTransactionId( | |
| transactionAuditId: number | string, | ||
| dataType: string, | ||
| actions: Actions | ||
| ): Promise<string[]> { | ||
| if (!transactionAuditId) return undefined; | ||
| ): Promise<DataTypeRowIdsFromTransactionIds> { | ||
| if (!transactionAuditId) return { rowIds: [], dataTypeRowCounts: {} }; | ||
|
|
||
| const modelId = createGridModelId(gridIdPrefix, schemaQuery); | ||
| const selected = await getGridIdsFromTransactionId(transactionAuditId, dataType); | ||
| actions.replaceSelections(modelId, selected); | ||
| actions.replaceSelections(modelId, selected.rowIds); | ||
| return selected; | ||
| } | ||
|
|
||
| type SampleTypesFromTransactionIds = { rowIds: string[]; sampleTypes: string[] }; | ||
|
|
||
| export async function getSampleTypesFromTransactionIds( | ||
| transactionAuditId: number | string | ||
| ): Promise<SampleTypesFromTransactionIds> { | ||
| if (!transactionAuditId) return undefined; | ||
|
|
||
| const rowIds = await getGridIdsFromTransactionId(transactionAuditId, SAMPLES_KEY); | ||
| const sampleTypes = await selectDistinctRows({ | ||
| schemaName: SCHEMAS.EXP_TABLES.MATERIALS.schemaName, | ||
| queryName: SCHEMAS.EXP_TABLES.MATERIALS.queryName, | ||
| column: 'SampleSet/Name', | ||
| async function getDataTypesFromTransactionId( | ||
| transactionAuditId: number | string, | ||
| auditDataType: string, | ||
| schemaName: string, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to accept a |
||
| queryName: string, | ||
| typeColumn: string | ||
| ): Promise<DataTypeRowIdsFromTransactionIds> { | ||
| if (!transactionAuditId) return { rowIds: [], dataTypeRowCounts: {}, dataTypes: [] }; | ||
|
|
||
| const { rowIds, dataTypeRowCounts } = await getGridIdsFromTransactionId(transactionAuditId, auditDataType); | ||
| const distinct = await selectDistinctRows({ | ||
| schemaName, | ||
| queryName, | ||
| column: typeColumn, | ||
| filterArray: [Filter.create('RowId', rowIds, Filter.Types.IN)], | ||
| }); | ||
| return { rowIds, dataTypeRowCounts, dataTypes: distinct.values }; | ||
| } | ||
|
|
||
| export function getSampleTypesFromTransactionIds( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| transactionAuditId: number | string | ||
| ): Promise<DataTypeRowIdsFromTransactionIds> { | ||
| return getDataTypesFromTransactionId( | ||
| transactionAuditId, | ||
| SAMPLES_KEY, | ||
| SCHEMAS.EXP_TABLES.MATERIALS.schemaName, | ||
| SCHEMAS.EXP_TABLES.MATERIALS.queryName, | ||
| 'SampleSet/Name' | ||
| ); | ||
| } | ||
|
|
||
| export async function getDataClassesFromTransactionIds( | ||
| transactionAuditId: number | string | ||
| ): Promise<DataTypeRowIdsFromTransactionIds> { | ||
| const results = await getDataTypesFromTransactionId( | ||
| transactionAuditId, | ||
| SOURCES_KEY, | ||
| SCHEMAS.EXP_TABLES.DATA.schemaName, | ||
| SCHEMAS.EXP_TABLES.DATA.queryName, | ||
| 'DataClass/Name' | ||
| ); | ||
|
|
||
| if (!results.rowIds.length) return { ...results, typeNameRowCounts: {} }; | ||
|
|
||
| const { dataTypeRowCounts, dataTypes } = results; | ||
| const dataTypeLcMap = Object.fromEntries((dataTypes ?? []).map(dt => [dt.toLowerCase(), dt])); | ||
|
|
||
| const typeNameRowCounts = {}; | ||
| if (Object.keys(dataTypeRowCounts).length > 0) { | ||
| const dataClasses = await selectRows({ | ||
| schemaQuery: SCHEMAS.EXP_TABLES.DATA_CLASSES, | ||
| columns: ['Name', 'RowId'], | ||
| filterArray: [Filter.create('rowId', Object.keys(dataTypeRowCounts), Filter.Types.IN)], | ||
| containerFilter: Query.containerFilter.currentPlusProjectAndShared, | ||
| }); | ||
|
|
||
| dataClasses.rows.forEach(row => { | ||
| const dataClassLc = caseInsensitive(row, 'Name')?.value?.toLowerCase(); | ||
| const rowId = caseInsensitive(row, 'RowId').value; | ||
| typeNameRowCounts[dataTypeLcMap[dataClassLc]] = dataTypeRowCounts[rowId]; | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| rowIds, | ||
| sampleTypes: sampleTypes.values, | ||
| ...results, | ||
| typeNameRowCounts, | ||
| }; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just escaping the typings. I would consider declaring a new type
using that on request:
and use a normal dereference: