-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX-2589 Add object count for the result in the query view (#2591)
- Loading branch information
1 parent
8a4684b
commit abd56cb
Showing
3 changed files
with
53 additions
and
2 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
42 changes: 42 additions & 0 deletions
42
...lExplorer.Frontend/components/ContentViews/QueryView/components/ResultMeta/ResultMeta.tsx
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,42 @@ | ||
import { Typography } from "@equinor/eds-core-react"; | ||
import { QueryContext } from "contexts/queryContext"; | ||
import { XMLParser } from "fast-xml-parser"; | ||
import { FC, useContext } from "react"; | ||
import styled from "styled-components"; | ||
|
||
const ResultMeta: FC = () => { | ||
const { | ||
queryState: { queries, tabIndex } | ||
} = useContext(QueryContext); | ||
|
||
const { result } = queries[tabIndex]; | ||
const parser = new XMLParser(); | ||
const resultObj = parser.parse(result); | ||
const templateObject = Object.keys(resultObj)?.[0]?.slice(0, -1); | ||
const resultCount = countItemsAtDepth2(resultObj, templateObject); | ||
|
||
return ( | ||
<Layout> | ||
{resultCount > 0 && ( | ||
<Typography>{`Number of ${templateObject}s: ${resultCount}`}</Typography> | ||
)} | ||
</Layout> | ||
); | ||
}; | ||
|
||
const Layout = styled.div` | ||
padding-left: 46px; | ||
`; | ||
|
||
function countItemsAtDepth2(obj: any, templateObject: string) { | ||
try { | ||
const depth1object = Object.values(obj)[0] as any; | ||
const depth2objects = depth1object[templateObject]; | ||
const depth2length = depth2objects.length; | ||
return depth2length; | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
export default ResultMeta; |
1 change: 1 addition & 0 deletions
1
Src/WitsmlExplorer.Frontend/components/ContentViews/QueryView/components/ResultMeta/index.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 @@ | ||
export { default } from "./ResultMeta"; |