-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dashboard): fix table item creation
- Loading branch information
Showing
6 changed files
with
84 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
packages/dashboard/src/customization/widgets/table/component.spec.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/dashboard/src/customization/widgets/table/useTableItems.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { toId } from '@iot-app-kit/source-iotsitewise'; | ||
import { useQueries } from '@tanstack/react-query'; | ||
import { useClients } from '~/components/dashboard/clientContext'; | ||
import { AssetCacheKeyFactory } from '~/components/queryEditor/iotSiteWiseQueryEditor/modeledDataStreamQueryEditor/assetExplorer/useAsset/assetCacheKeyFactory'; | ||
import { createQueryFn } from '~/components/queryEditor/iotSiteWiseQueryEditor/modeledDataStreamQueryEditor/assetExplorer/useAsset/useAsset'; | ||
import { SiteWiseQueryConfig } from '../types'; | ||
|
||
export const useTableItems = (query: SiteWiseQueryConfig['query']) => { | ||
const { iotSiteWiseClient } = useClients(); | ||
|
||
const assets = query?.assets ?? []; | ||
const assetIds = assets.map(({ assetId }) => assetId); | ||
|
||
const queries = useQueries({ | ||
queries: iotSiteWiseClient | ||
? assetIds.map((assetId) => ({ | ||
enabled: Boolean(assetId), | ||
queryKey: new AssetCacheKeyFactory(assetId).create(), | ||
queryFn: createQueryFn(iotSiteWiseClient), | ||
})) | ||
: [], | ||
}); | ||
|
||
const assetItems = assets.flatMap(({ assetId, properties }) => | ||
properties.map(({ propertyId }) => { | ||
const assetDescription = queries.find(({ data }) => data?.assetId === assetId)?.data; | ||
const { unit, name } = assetDescription?.assetProperties?.find(({ id }) => id === propertyId) ?? { unit: '' }; | ||
return { | ||
property: `${name} (${assetDescription?.assetName ?? ''})`, | ||
unit, | ||
value: { | ||
$cellRef: { | ||
id: toId({ | ||
assetId, | ||
propertyId, | ||
}), | ||
resolution: 0, | ||
}, | ||
}, | ||
}; | ||
}) | ||
); | ||
|
||
const unmodeledItems = | ||
query?.properties?.map(({ propertyAlias }) => ({ | ||
property: propertyAlias, | ||
unit: '', | ||
value: { | ||
$cellRef: { | ||
id: propertyAlias, | ||
resolution: 0, | ||
}, | ||
}, | ||
})) ?? []; | ||
|
||
return [...assetItems, ...unmodeledItems]; | ||
}; |