Skip to content

Commit

Permalink
add more features
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustav-Eikaas committed Jun 12, 2024
1 parent 6e38d79 commit 0ec6021
Showing 1 changed file with 93 additions and 6 deletions.
99 changes: 93 additions & 6 deletions apps/transfer/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createRender } from '@cc-components/shared';
import { ColDef, ClientGrid, GridOptions } from '@equinor/workspace-ag-grid';
import { BaseStatus, StatusCell, createRender, statusColorMap } from '@cc-components/shared';
import {
ComponentRenderArgs,
IAppConfigurator,
Expand All @@ -7,8 +8,16 @@ import { enableContext } from '@equinor/fusion-framework-react-module-context';
import buildQuery from 'odata-query';
import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query'
import { useHttpClient } from '@equinor/fusion-framework-react/http';
import React from 'react';
import { Autocomplete, CircularProgress } from '@equinor/eds-core-react'
import React, { useState } from 'react';
import { Autocomplete, Button, CircularProgress } from '@equinor/eds-core-react'
import { ICellRendererProps } from '@equinor/workspace-fusion/dist/lib/integrations/grid';

const mccr_status_map = {
0: "OS",
1: "PA",
2: "PB",
3: "OK"
}

export interface FamCommPkg {
messageTimestamp: string
Expand Down Expand Up @@ -37,15 +46,23 @@ export interface FamCommPkg {
updatedDate: string
urlId: string
}
export interface Famtag {
tagNo: string
worstStatus: 0 | 1 | 2 | 3
mccrStatus: "OS" | "OK" | "PA" | "PB"
}

const CommPkg = () => {
const [facility, setFacility] = useState("JCA")
const [commpkg, setcommpkg] = useState<FamCommPkg | null>(null)
const client = useHttpClient("cc-api")
const { isLoading, data, error } = useQuery<FamCommPkg[]>({
queryKey: ["commpkgs"], queryFn: async () => {
var res = await client.fetch("/v2/dynamic", {
method: "POST",
headers: { ["content-type"]: "application/json" },
body: JSON.stringify({
"query": "SELECT * FROM Completion.CommissioningPackage_v3",
"query": `SELECT * FROM Completion.CommissioningPackage_v3 where facility = '${facility}'`,
"pagination": null,
"options": null
})
Expand All @@ -54,20 +71,90 @@ const CommPkg = () => {
return data.data as FamCommPkg[]
}
})



const { isLoading: tagsLoading, data: tags, error: tagsError } = useQuery<Famtag[]>({
enabled: !!commpkg,
queryKey: ["tags", commpkg?.commissioningPackageNo],
queryFn: async () => {
var res = await client.fetch("/v2/dynamic", {
method: "POST",
headers: { ["content-type"]: "application/json" },
body: JSON.stringify({
"query": `SELECT tag.tagNo,min(c.tagStatus) as worstStatus
FROM Completion.CompletionTag_v3 as tag
JOIN (
SELECT
sourceIdentity,
tagId,
CASE
WHEN status='OS' THEN 0
WHEN status='PA' THEN 1
WHEN status='PB' THEN 2
ELSE 3
END as tagStatus
FROM Completion.CompletionChecklist_v2
) as c ON c.tagId = tag.sourceIdentity
WHERE tag.commIssioningPackageNo = '${commpkg?.commissioningPackageNo}' and tag.facility = '${facility}'
GROUP BY tag.tagNo
`,
"pagination": null,
"options": null
})
})
var data = await res.json();
var tags = data.data as Famtag[]
return tags.map(s => ({ ...s, mccrStatus: mccr_status_map[s.worstStatus] })) as Famtag[]
}
})



if (isLoading) {
return <CircularProgress />
}
if (!data) {
return <div>uh-oh</div>
}
return (
<div style={{ height: "100%", width: "100%", display: "flex", alignItems: "center", justifyContent: "center" }}>
<div style={{ height: "100%", width: "100%", display: "flex", alignItems: "center", justifyContent: "center", flexDirection: "column" }}>
<div style={{ width: "500px" }}>
<Autocomplete optionLabel={s => s.commissioningPackageNo} selectedOptions={[]} multiple={false} onSelect={(a) => { console.log(a) }} options={data} label={"Search commpkg for transfer"} />
<Autocomplete onOptionsChange={(a) => {
setcommpkg(a.selectedItems[0] ?? null)
}} optionLabel={s => s.commissioningPackageNo} selectedOptions={[]} multiple={false} onSelect={(a) => { console.log(a) }} options={data} label={"Search commpkg for transfer"} />
</div>
<div style={{ width: "500px" }}>
{tagsLoading ? <CircularProgress /> : !!tags ? <div><ClientGrid height={500} rowData={tags} colDefs={tagsDef} /></div> : <div>uh-oh</div>}
</div>
<Button disabled={!tags || tags?.some(s => s.worstStatus < 2)} onClick={() => {
console.log("Certificate started")
}}>Generate certificate</Button>
</div>)
}

const tagsDef: ColDef<Famtag>[] = [
{
headerName: "TagNo",
valueGetter: (s) => s.data?.tagNo
},
{
headerName: "MCCR status",
valueGetter: (s) => s.data?.mccrStatus,
cellRenderer: (props: ICellRendererProps) => {
if (!props.value) return null;
const statusColor = statusColorMap[(props.value as BaseStatus) ?? 'OS'];
return (
<StatusCell
content={props.value}
cellAttributeFn={() => ({
style: { backgroundColor: statusColor },
})}
/>
);
},
}
]
const queryclient = new QueryClient()
const TransferApp = () => {
return (
Expand Down

0 comments on commit 0ec6021

Please sign in to comment.