Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
GAOChengzhan committed Dec 17, 2024
1 parent 33e46b9 commit 90f6ed5
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/components/ToolBar/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 48,10 @@ import { useNetworkSummaryStore } from '../../store/NetworkSummaryStore'
import { generateUniqueName } from '../../utils/network-utils'
import { VisualStyleOptions } from '../../models/VisualStyleModel/VisualStyleOptions'
import { useUiStateStore } from '../../store/UiStateStore'
import { Aspect } from '../../models/CxModel/Cx2/Aspect'
import { getOptionalAspects } from '../../utils/cx-utils'
import { useOpaqueAspectStore } from '../../store/OpaqueAspectStore'
import { useMessageStore } from '../../store/MessageStore'
import { OpaqueAspects } from '../../models/OpaqueAspectModel'

interface FileUploadProps {
show: boolean
Expand All @@ -66,7 66,7 @@ export function FileUpload(props: FileUploadProps) {
visualStyle: VisualStyle
networkView: NetworkView
visualStyleOptions: VisualStyleOptions
otherAspects: Aspect[]
otherAspects: OpaqueAspects[]
}

const setCurrentNetworkId = useWorkspaceStore(
Expand Down Expand Up @@ -117,7 117,7 @@ export function FileUpload(props: FileUploadProps) {
const visualStyleOptions: VisualStyleOptions =
VisualStyleFn.createVisualStyleOptionsFromCx(cxData)

const otherAspects: Aspect[] = getOptionalAspects(cxData)
const otherAspects: OpaqueAspects[] = getOptionalAspects(cxData)

return {
network,
Expand Down
3 changes: 2 additions & 1 deletion src/models/NetworkWithViewModel/NetworkWithView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@ import { Table } from '../TableModel'
import { NetworkView } from '../ViewModel'
import { VisualStyle } from '../VisualStyleModel'
import { VisualStyleOptions } from '../VisualStyleModel/VisualStyleOptions'
import { OpaqueAspects } from '../OpaqueAspectModel'

/**
* An utility interface to hold all the data needed to build a network view
Expand All @@ -15,5 16,5 @@ export interface NetworkWithView {
visualStyle: VisualStyle
networkViews: NetworkView[]
visualStyleOptions?: VisualStyleOptions
otherAspects?: any[] // All other optional aspects found in the CX2 stream
otherAspects?: OpaqueAspects[] // All other optional aspects found in the CX2 stream
}
9 changes: 6 additions & 3 deletions src/models/VisualStyleModel/impl/cxVisualPropertyConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 107,15 @@ export const convertPassthroughMappingToCX = (
vs: VisualStyle,
vp: VisualProperty<VisualPropertyValueType>,
mapping: PassthroughMappingFunction,
isNameInTable: boolean,
): CXPassthroughMappingFunction => {
const { attribute } = mapping

return {
type: 'PASSTHROUGH',
definition: {
attribute,
type:mapping.attributeType
...(isNameInTable ? {} : { type: mapping.attributeType }),
},
}
}
Expand All @@ -123,6 124,7 @@ export const convertDiscreteMappingToCX = (
vs: VisualStyle,
vp: VisualProperty<VisualPropertyValueType>,
mapping: DiscreteMappingFunction,
isNameInTable: boolean,
): CXDiscreteMappingFunction<CXVisualPropertyValue> => {
const { vpValueMap, attribute } = mapping

Expand All @@ -134,14 136,15 @@ export const convertDiscreteMappingToCX = (
v: value,
vp: vpToCX(vp.name, vpValue),
})),
type:mapping.attributeType
...(isNameInTable ? {} : { type: mapping.attributeType }),
},
}
}
export const convertContinuousMappingToCX = (
vs: VisualStyle,
vp: VisualProperty<VisualPropertyValueType>,
mapping: ContinuousMappingFunction,
isNameInTable: boolean,
): CXContinuousMappingFunction<CXVisualPropertyValue> => {
const { min, max, controlPoints, attribute, ltMinVpValue, gtMaxVpValue } =
mapping
Expand Down Expand Up @@ -183,7 186,7 @@ export const convertContinuousMappingToCX = (
},
],
attribute,
type:mapping.attributeType // must be number type
...(isNameInTable ? {} : { type: mapping.attributeType }),
},
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/store/io/exportCX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 15,7 @@ import VisualStyleFn, {
VisualPropertyName,
VisualProperty,
VisualPropertyValueType,
NodeVisualPropertyName,
} from '../../models/VisualStyleModel'

import { translateEdgeIdToCX } from '../../models/NetworkModel/impl/CyNetwork'
Expand Down Expand Up @@ -96,6 97,12 @@ export const exportNetworkToCx2 = (
): { [key: CXVPName]: CXVisualMappingFunction<CXVisualPropertyValue> } => {
const { name, mapping } = vp
const cxVPName = vpNameToCXName(name)
const attributeName = mapping?.attribute
// whether attributeName is in nodeTable or edgeTable
let isNameInTable = false
if(attributeName){
isNameInTable = Object.values(NodeVisualPropertyName).includes(name as NodeVisualPropertyName) ? nodeTable.columns.map((col)=>col.name).includes(attributeName) : edgeTable.columns.map((col)=>col.name).includes(attributeName)
}

if (mapping != null) {
switch (mapping.type) {
Expand All @@ -104,6 111,7 @@ export const exportNetworkToCx2 = (
vs,
vp,
mapping as ContinuousMappingFunction,
isNameInTable
)
mappings[cxVPName] = convertedMapping
break
Expand All @@ -113,6 121,7 @@ export const exportNetworkToCx2 = (
vs,
vp,
mapping as DiscreteMappingFunction,
isNameInTable
)
mappings[cxVPName] = convertedMapping
break
Expand All @@ -122,6 131,7 @@ export const exportNetworkToCx2 = (
vs,
vp,
mapping as PassthroughMappingFunction,
isNameInTable
)
mappings[cxVPName] = convertedMapping
break
Expand Down
8 changes: 7 additions & 1 deletion src/store/persist/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 697,12 @@ export const deleteServiceAppFromDb = async (url: string): Promise<void> => {
})
}

// opaque aspects
export interface OpaqueAspectsDB {
id: IdType
aspects: Record<string, any[]>
}

export const putOpaqueAspectsToDb = async (
networkId: IdType,
aspects: Record<string, any[]>,
Expand All @@ -708,7 714,7 @@ export const putOpaqueAspectsToDb = async (

export const getOpaqueAspectsFromDb = async (
networkId: IdType,
): Promise< any[] | undefined> => {
): Promise< OpaqueAspectsDB | undefined> => {
return await db.opaqueAspects.get({ id: networkId })
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/CachedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@ import { Table } from '../models/TableModel'
import { NetworkView } from '../models/ViewModel'
import { VisualStyle } from '../models/VisualStyleModel'
import { VisualStyleOptions } from '../models/VisualStyleModel/VisualStyleOptions'
import { OpaqueAspects } from '../models/OpaqueAspectModel'

export interface CachedData {
network?: Network
Expand All @@ -11,5 12,5 @@ export interface CachedData {
visualStyle?: VisualStyle
networkViews?: NetworkView[]
visualStyleOptions?: VisualStyleOptions
otherAspects?: any[]
otherAspects?: OpaqueAspects[]
}
15 changes: 10 additions & 5 deletions src/utils/cx-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@ import {
getVisualStyleFromDb,
getUiStateFromDb,
getOpaqueAspectsFromDb,
OpaqueAspectsDB,
} from '../store/persist/db'
import { CachedData } from './CachedData'
import { createNetworkAttributesFromCx } from '../models/TableModel/impl/NetworkAttributesImpl'
Expand All @@ -20,6 21,7 @@ import { NetworkWithView } from '../models/NetworkWithViewModel'
import { VisualStyleOptions } from '../models/VisualStyleModel/VisualStyleOptions'
import { Ui } from '../models/UiModel'
import { IdType } from '../models/IdType'
import { OpaqueAspects } from '../models/OpaqueAspectModel'

/**
*
Expand Down Expand Up @@ -73,7 75,10 @@ export const getCachedData = async (id: string): Promise<CachedData> => {
uiState?.visualStyleOptions ?? {}
// Fall back to an empty object if the visual style options are not found
const visualStyleOptions: VisualStyleOptions = vsOptions[id] ?? {}
const otherAspects: any[] | undefined = await getOpaqueAspectsFromDb(id)
const opaqueAspects: OpaqueAspectsDB|undefined = await getOpaqueAspectsFromDb(id)
const otherAspects: OpaqueAspects[] = opaqueAspects
? Object.entries(opaqueAspects.aspects).map(([key, value]) => ({ [key]: value }))
: []
return {
network,
visualStyle,
Expand Down Expand Up @@ -109,7 114,7 @@ export const createDataFromCx = async (
)
const visualStyleOptions: VisualStyleOptions =
VisualStyleFn.createVisualStyleOptionsFromCx(cxData)
const otherAspects: Aspect[] = getOptionalAspects(cxData)
const otherAspects: OpaqueAspects[] = getOptionalAspects(cxData)

return {
network,
Expand All @@ -132,8 137,8 @@ const CoreAspectTagValueSet = new Set<string>(
* @param cx2
* @returns Array of optional Aspects
*/
export const getOptionalAspects = (cx2: Cx2): Aspect[] => {
const optionalAspects: Aspect[] = []
export const getOptionalAspects = (cx2: Cx2): OpaqueAspects[] => {
const optionalAspects: OpaqueAspects[] = []
for (const entry of cx2) {
if (entry !== undefined) {
const key = Object.keys(entry)[0]
Expand All @@ -142,7 147,7 @@ export const getOptionalAspects = (cx2: Cx2): Aspect[] => {
key !== 'status' &&
key !== 'CXVersion'
) {
optionalAspects.push(entry as Aspect)
optionalAspects.push(entry as OpaqueAspects)
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/utils/ndex-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 15,6 @@ import { exportNetworkToCx2 } from '../store/io/exportCX'
import { TableRecord } from '../models/StoreModel/TableStoreModel'
import { useNdexNetwork } from '../store/hooks/useNdexNetwork'
import { OpaqueAspects } from '../models/OpaqueAspectModel'
import { Aspect } from '../models/CxModel/Cx2/Aspect'
import { ndexSummaryFetcher } from '../store/hooks/useNdexNetworkSummary'

export const ndexDuplicateKeyErrorMessage =
Expand Down Expand Up @@ -145,6 144,9 @@ export const saveNetworkToNDEx = async (
)
await ndexClient.updateNetworkFromRawCX2(networkId, cx)
const ndexSummary = await ndexClient.getNetworkSummary(networkId)
if(ndexSummary.completed === false || ndexSummary.errorMessage){
throw new Error('The network is rejected by NDEx')
}
const newNdexModificationTime = ndexSummary.modificationTime
updateSummary(networkId, {
modificationTime: newNdexModificationTime,
Expand Down Expand Up @@ -195,11 197,12 @@ export const saveAllNetworks = async (

if (res.otherAspects) {
opaqueAspect = res.otherAspects.reduce(
(acc: OpaqueAspects, aspect: Aspect) => {
(acc: OpaqueAspects, aspect: OpaqueAspects) => {
const [aspectName, aspectData] = Object.entries(aspect)[0]
acc[aspectName] = aspectData
return acc
},
{},
{} as OpaqueAspects,
)
} else {
opaqueAspect = {}
Expand Down

0 comments on commit 90f6ed5

Please sign in to comment.