Skip to content

Commit

Permalink
Access case in revision (#1317)
Browse files Browse the repository at this point in the history
* bad working example

* Fixed cases list so when in a revision, the cases list on the left side refers to the revision cases

* check for revision when getting case data

* Merge branch 'main' of https://github.com/equinor/dcd into revision-bug-cases

* update columndefs when isrevsion changes

* a

* cleanup

* Merge branch 'main' of https://github.com/equinor/dcd into revision-bug-cases

---------

Co-authored-by: Tord Austad <toaus@equinor.com>
  • Loading branch information
JonasABach and taustad authored Oct 22, 2024
1 parent 34f7145 commit 8ebebad
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 77 deletions.
8 changes: 5 additions & 3 deletions frontend/src/Components/Case/Components/CaseDropMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
unarchive,
history,
} from "@equinor/eds-icons"
import { useNavigate } from "react-router-dom"
import { useNavigate, useParams } from "react-router-dom"
import { useModuleCurrentContext } from "@equinor/fusion-framework-react-module-context"
import { useQuery, useQueryClient } from "@tanstack/react-query"

Expand Down Expand Up @@ -55,6 +55,8 @@ const CaseDropMenu: React.FC<CaseDropMenuProps> = ({

const [isRevisionMenuOpen, setIsRevisionMenuOpen] = useState<boolean>(false)
const [revisionMenuAnchorEl, setRevisionMenuAnchorEl] = useState<any | null>(null)
const { isRevision } = useProjectContext()
const { revisionId } = useParams()

const { data: projectData } = useQuery({
queryKey: ["projectApiData", externalId],
Expand All @@ -63,8 +65,8 @@ const CaseDropMenu: React.FC<CaseDropMenuProps> = ({
})

const { data: caseApiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { ColDef } from "@ag-grid-community/core"
import { useQuery } from "@tanstack/react-query"

import {
casePath, productionStrategyOverviewToString, cellStyleRightAlign, unwrapProjectId,
productionStrategyOverviewToString, cellStyleRightAlign, unwrapProjectId,
caseRevisionPath,
} from "@/Utils/common"
import { GetProjectService } from "@/Services/ProjectService"
import { GetSTEAService } from "@/Services/STEAService"
Expand Down Expand Up @@ -105,7 +106,8 @@ const CasesAgGridTable = ({

const selectCase = (p: any) => {
if (!currentContext || !p.node.data) { return null }
navigate(casePath(currentContext.id, p.node.data.id))

navigate(caseRevisionPath(currentContext.id, p.node.data.id, isRevision, revisionId))
return null
}

Expand Down Expand Up @@ -141,7 +143,7 @@ const CasesAgGridTable = ({
return <div>{stringValue}</div>
}

const [columnDefs] = useState<ColDef[]>([
const GetColumnDefs = () => [
{
field: "name",
cellRenderer: nameWithReferenceCase,
Expand Down Expand Up @@ -184,7 +186,13 @@ const CasesAgGridTable = ({
cellRenderer: menuButton,
width: 120,
},
])
]

const [columnDefs, setColumnDefs] = useState<ColDef[]>(GetColumnDefs())

useEffect(() => {
setColumnDefs(GetColumnDefs())
}, [isRevision])

const casesToRowData = (isArchived: boolean) => {
let data = apiData
Expand Down
21 changes: 0 additions & 21 deletions frontend/src/Components/Case/OverviewCasesTable/CasesDropMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
library_add,
archive,
unarchive,
history,
} from "@equinor/eds-icons"
import { useMemo, useState } from "react"
import { useQuery, useQueryClient } from "@tanstack/react-query"
Expand All @@ -23,7 +22,6 @@ import { useSubmitToApi } from "@/Hooks/UseSubmitToApi"
import { projectQueryFn } from "@/Services/QueryFunctions"
import useEditProject from "@/Hooks/useEditProject"
import Modal from "../../Modal/Modal"
import RevisionsDropMenu from "@/Components/Controls/RevisionsDropMenu"
import useEditDisabled from "@/Hooks/useEditDisabled"

interface CasesDropMenuProps {
Expand All @@ -47,8 +45,6 @@ const CasesDropMenu = ({
const { updateCase } = useSubmitToApi()
const { currentContext } = useModuleCurrentContext()
const externalId = currentContext?.externalId
const [isRevisionMenuOpen, setIsRevisionMenuOpen] = useState<boolean>(false)
const [revisionMenuAnchorEl, setRevisionMenuAnchorEl] = useState<any | null>(null)
const { isEditDisabled } = useEditDisabled()

const { data: projectData } = useQuery({
Expand Down Expand Up @@ -198,23 +194,6 @@ const CasesDropMenu = ({
</Typography>
</Menu.Item>
)}
{/* Uncomment to show project revisions button */}
{/* <Menu.Item
ref={setRevisionMenuAnchorEl}
onMouseEnter={() => setIsRevisionMenuOpen(!isRevisionMenuOpen)}
>
<Icon data={history} size={16} />
<Typography group="navigation" variant="menu_title" as="span">
Project revisions
</Typography>
</Menu.Item>
<RevisionsDropMenu
isMenuOpen={isRevisionMenuOpen}
setIsMenuOpen={setIsMenuOpen}
setIsRevisionMenuOpen={setIsRevisionMenuOpen}
menuAnchorEl={revisionMenuAnchorEl}
isCaseMenu
/> */}
</Menu>
</>
)
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/Components/Case/Tabs/CaseCost/CaseCostTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { useProjectContext } from "../../../../Context/ProjectContext"

const CaseCostTab = ({ addEdit }: { addEdit: any }) => {
const { activeTabCase } = useCaseContext()
const { caseId } = useParams()
const { projectId } = useProjectContext()
const { caseId, revisionId } = useParams()
const { projectId, isRevision } = useProjectContext()

const [startYear, setStartYear] = useState<number>(2020)
const [endYear, setEndYear] = useState<number>(2030)
Expand Down Expand Up @@ -58,8 +58,8 @@ const CaseCostTab = ({ addEdit }: { addEdit: any }) => {
}

const { data: apiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/Components/Case/Tabs/CaseDescriptionTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { useProjectContext } from "../../../Context/ProjectContext"

const CaseDescriptionTab = ({ addEdit }: { addEdit: any }) => {
const { editMode } = useAppContext()
const { caseId, tab } = useParams()
const { projectId } = useProjectContext()
const { caseId, revisionId, tab } = useParams()
const { projectId, isRevision } = useProjectContext()

const [description, setDescription] = useState("")

Expand All @@ -35,8 +35,8 @@ const CaseDescriptionTab = ({ addEdit }: { addEdit: any }) => {
}

const { data: apiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { useProjectContext } from "../../../../Context/ProjectContext"

const CaseDrillingScheduleTab = ({ addEdit }: { addEdit: any }) => {
const { activeTabCase } = useCaseContext()
const { caseId } = useParams()
const { projectId } = useProjectContext()
const { caseId, revisionId } = useParams()
const { projectId, isRevision } = useProjectContext()

const [startYear, setStartYear] = useState<number>(2020)
const [endYear, setEndYear] = useState<number>(2030)
Expand All @@ -41,8 +41,8 @@ const CaseDrillingScheduleTab = ({ addEdit }: { addEdit: any }) => {
const explorationWellsGridRef = useRef(null)

const { data: apiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/Components/Case/Tabs/CaseFacilitiesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { useProjectContext } from "../../../Context/ProjectContext"
const CaseFacilitiesTab = ({ addEdit }: { addEdit: any }) => {
const { currentContext } = useModuleCurrentContext()
const externalId = currentContext?.externalId
const { caseId } = useParams()
const { projectId } = useProjectContext()
const { caseId, revisionId } = useParams()
const { projectId, isRevision } = useProjectContext()

const platformConceptValues: { [key: number]: string } = {
0: "No Concept",
Expand Down Expand Up @@ -54,8 +54,8 @@ const CaseFacilitiesTab = ({ addEdit }: { addEdit: any }) => {
})

const { data: apiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { caseQueryFn } from "../../../Services/QueryFunctions"
import { useProjectContext } from "../../../Context/ProjectContext"

const CaseProductionProfilesTab = ({ addEdit }: { addEdit: any }) => {
const { caseId } = useParams()
const { caseId, revisionId } = useParams()
const { activeTabCase } = useCaseContext()
const { projectId } = useProjectContext()
const { projectId, isRevision } = useProjectContext()
const [startYear, setStartYear] = useState<number>(2020)
const [endYear, setEndYear] = useState<number>(2030)
const [tableYears, setTableYears] = useState<[number, number]>([2020, 2030])
Expand Down Expand Up @@ -50,8 +50,8 @@ const CaseProductionProfilesTab = ({ addEdit }: { addEdit: any }) => {
}

const { data: apiData, isLoading } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/Components/Case/Tabs/CaseScheduleTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { caseQueryFn } from "../../../Services/QueryFunctions"
import { useProjectContext } from "../../../Context/ProjectContext"

const CaseScheduleTab = ({ addEdit }: { addEdit: any }) => {
const { caseId, tab } = useParams()
const { editMode } = useAppContext()
const { projectId } = useProjectContext()
const { caseId, revisionId, tab } = useParams()
const { projectId, isRevision } = useProjectContext()

const { data: apiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
7 changes: 4 additions & 3 deletions frontend/src/Components/Case/Tabs/CaseSummaryTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { useProjectContext } from "@/Context/ProjectContext"
const CaseSummaryTab = ({ addEdit }: { addEdit: any }) => {
const { activeTabCase } = useCaseContext()
const { caseId } = useParams()
const { projectId } = useProjectContext()
const { projectId, isRevision } = useProjectContext()
const { revisionId } = useParams()
const [tableYears, setTableYears] = useState<[number, number]>([2020, 2030])
const [allTimeSeriesData, setAllTimeSeriesData] = useState<ITimeSeriesData[][]>([])

Expand All @@ -32,8 +33,8 @@ const CaseSummaryTab = ({ addEdit }: { addEdit: any }) => {
})

const { data: apiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
7 changes: 4 additions & 3 deletions frontend/src/Components/Case/Tabs/Co2Emissions/CaseCO2Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import { AgChartsTimeseries, setValueToCorrespondingYear } from "../../../AgGrid
const CaseCO2Tab = ({ addEdit }: { addEdit: any }) => {
const { caseId } = useParams()
const { activeTabCase } = useCaseContext()
const { projectId } = useProjectContext()
const { projectId, isRevision } = useProjectContext()
const { revisionId } = useParams()

const { data: apiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand Down
7 changes: 4 additions & 3 deletions frontend/src/Components/Controls/CaseControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
visibility,
edit,
} from "@equinor/eds-icons"
import { useNavigate, useLocation } from "react-router-dom"
import { useNavigate, useLocation, useParams } from "react-router-dom"
import Tabs from "@mui/material/Tabs"
import Tab from "@mui/material/Tab"
import styled from "styled-components"
Expand Down Expand Up @@ -99,10 +99,11 @@ const CaseControls: React.FC<props> = ({
const [caseName, setCaseName] = useState("")
const [menuAnchorEl, setMenuAnchorEl] = useState<any | null>(null)
const [isMenuOpen, setIsMenuOpen] = useState<boolean>(false)
const { revisionId } = useParams()

const { data: apiData, error } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
refetchInterval: 20000,
})
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/Components/Controls/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const Controls = () => {
const [caseLastUpdated, setCaseLastUpdated] = useState<string>("")

const { data: apiData } = useQuery({
queryKey: ["caseApiData", projectId, caseId],
queryFn: () => caseQueryFn(projectId, caseId),
queryKey: ["caseApiData", isRevision ? revisionId : projectId, caseId],
queryFn: () => caseQueryFn(isRevision ? revisionId ?? "" : projectId, caseId),
enabled: !!projectId && !!caseId,
})

Expand All @@ -52,7 +52,11 @@ const Controls = () => {

const backToProject = async () => {
cancelEdit()
navigate(projectPath(currentContext?.id!))
if (isRevision && revisionId) {
navigate(`${projectPath(currentContext?.id!)}/revision/${revisionId}`)
} else {
navigate(projectPath(currentContext?.id!))
}
}

const handleEdit = () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Controls/RevisionChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const RevisionChip = () => {
const { data: revisionData } = useQuery({
queryKey: ["revisionApiData", revisionId],
queryFn: () => revisionQueryFn(projectId, revisionId),
enabled: !!revisionId,
enabled: !!revisionId && !!projectId,
})

const handleMouseOver = () => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Components/Controls/RevisionsDropMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ const RevisionsDropMenu: React.FC<RevisionsDropMenuProps> = ({

const navToRevision = (revision: Revision) => {
setIsMenuOpen(false)
setIsRevision(true)
navigateToRevision(revision.id, setIsRevision, queryClient, externalId, navigate)
}

const exitRevision = () => {
setIsMenuOpen(false)
setIsRevision(false)
exitRevisionView(setIsRevision, queryClient, externalId, currentContext, navigate)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ const ArchivedCasesList: React.FC = () => {
return null
}

const archivedCases = useMemo(() =>
projectData.cases.filter((c) => c.archived),
[projectData.cases]);
const archivedCases = useMemo(
() => projectData.cases.filter((c) => c.archived),
[projectData.cases],
)

return (
<>
Expand Down
Loading

0 comments on commit 8ebebad

Please sign in to comment.