11import { InspectionArea } from 'models/InspectionArea'
2- import { MissionDefinition } from 'models/MissionDefinition'
3- import { InspectionAreaInspectionTuple } from './InspectionSection'
42import { useLanguageContext } from 'components/Contexts/LanguageContext'
53import {
64 CardComponent ,
75 Content ,
86 InspectionAreaText ,
9- Placeholder ,
107 StyledCard ,
118 StyledInspectionAreaCard ,
12- StyledInspectionAreaCards ,
139 TopInspectionAreaText ,
1410} from './InspectionUtilities'
1511import { Button , Icon , Tooltip , Typography } from '@equinor/eds-core-react'
1612import { Icons } from 'utils/icons'
1713import { tokens } from '@equinor/eds-tokens'
18- import { useMissionsContext } from 'components/Contexts/MissionRunsContext'
1914import { useAssetContext } from 'components/Contexts/AssetContext'
2015
2116interface InspectionAreaCardProps {
22- inspectionAreaData : InspectionAreaInspectionTuple
17+ inspectionArea : InspectionArea
18+ nMissions : number
2319 onClickInspectionArea : ( inspectionArea : InspectionArea ) => void
24- selectedInspectionArea : InspectionArea | undefined
25- handleScheduleAll : ( missionDefinitions : MissionDefinition [ ] ) => void
20+ isSelected : boolean
21+ isMissionOngoing : boolean
22+ onClickScheduleAll : ( inspectionArea : InspectionArea ) => void
2623}
2724
28- const InspectionAreaCard = ( {
29- inspectionAreaData,
25+ export const InspectionAreaCard = ( {
26+ inspectionArea,
27+ nMissions,
3028 onClickInspectionArea,
31- selectedInspectionArea,
32- handleScheduleAll,
29+ isSelected,
30+ isMissionOngoing,
31+ onClickScheduleAll,
3332} : InspectionAreaCardProps ) => {
3433 const { TranslateText } = useLanguageContext ( )
35- const { ongoingMissions } = useMissionsContext ( )
3634 const { enabledRobots } = useAssetContext ( )
3735
38- const isScheduleMissionsDisabled = enabledRobots . length === 0 || inspectionAreaData . missionDefinitions . length === 0
36+ const isScheduleMissionsDisabled = enabledRobots . length === 0 || nMissions === 0
3937
4038 let queueMissionsTooltip = ''
41- if ( inspectionAreaData . missionDefinitions . length === 0 ) queueMissionsTooltip = TranslateText ( 'No available mission' )
39+ if ( nMissions === 0 ) queueMissionsTooltip = TranslateText ( 'No available mission' )
4240 else if ( isScheduleMissionsDisabled ) queueMissionsTooltip = TranslateText ( 'No robot available' )
4341
4442 return (
45- < StyledInspectionAreaCard key = { inspectionAreaData . inspectionArea . inspectionAreaName } >
43+ < StyledInspectionAreaCard key = { inspectionArea . inspectionAreaName } >
4644 < StyledCard
47- key = { inspectionAreaData . inspectionArea . inspectionAreaName }
48- onClick = { ( ) => onClickInspectionArea ( inspectionAreaData . inspectionArea ) }
49- style = {
50- selectedInspectionArea === inspectionAreaData . inspectionArea
51- ? { border : `solid ${ tokens . colors . interactive . focus . hex } 1px` }
52- : { }
53- }
45+ key = { inspectionArea . inspectionAreaName }
46+ onClick = { ( ) => onClickInspectionArea ( inspectionArea ) }
47+ style = { isSelected ? { border : `solid ${ tokens . colors . interactive . focus . hex } 1px` } : { } }
5448 >
5549 < InspectionAreaText >
5650 < TopInspectionAreaText >
5751 < Typography variant = { 'body_short_bold' } >
58- { inspectionAreaData . inspectionArea . inspectionAreaName . toString ( ) }
52+ { inspectionArea . inspectionAreaName . toString ( ) }
5953 </ Typography >
60- { inspectionAreaData . missionDefinitions
61- . filter ( ( m ) => ongoingMissions . find ( ( om ) => om . missionId === m . id ) )
62- . map ( ( mission ) => (
63- < Content key = { mission . id } >
64- < Icon name = { Icons . Ongoing } size = { 16 } />
65- { TranslateText ( 'InProgress' ) }
66- </ Content >
67- ) ) }
54+ { isMissionOngoing && (
55+ < Content >
56+ < Icon name = { Icons . Ongoing } size = { 16 } />
57+ { TranslateText ( 'InProgress' ) }
58+ </ Content >
59+ ) }
6860 </ TopInspectionAreaText >
6961 < Typography color = { tokens . colors . text . static_icons__secondary . hex } >
70- { inspectionAreaData . missionDefinitions . length } { ' ' }
71- { inspectionAreaData . missionDefinitions . length === 1
62+ { nMissions } { ' ' }
63+ { nMissions === 1
7264 ? TranslateText ( 'Mission' ) . toLowerCase ( )
7365 : TranslateText ( 'Missions' ) . toLowerCase ( ) }
7466 </ Typography >
@@ -78,13 +70,10 @@ const InspectionAreaCard = ({
7870 < Button
7971 disabled = { isScheduleMissionsDisabled }
8072 variant = "ghost"
81- onClick = { ( ) => handleScheduleAll ( inspectionAreaData . missionDefinitions ) }
73+ onClick = { ( ) => onClickScheduleAll ( inspectionArea ) }
8274 color = "secondary"
8375 >
84- < Icon
85- name = { Icons . Add }
86- color = { inspectionAreaData . missionDefinitions . length > 0 ? '' : 'grey' }
87- />
76+ < Icon name = { Icons . Add } color = { nMissions > 0 ? '' : 'grey' } />
8877 < Typography color = { tokens . colors . text . static_icons__secondary . hex } >
8978 { TranslateText ( 'Queue the missions' ) }
9079 </ Typography >
@@ -95,43 +84,3 @@ const InspectionAreaCard = ({
9584 </ StyledInspectionAreaCard >
9685 )
9786}
98-
99- interface IInspectionAreaCardProps {
100- inspectionAreaMissions : InspectionAreaInspectionTuple [ ]
101- onClickInspectionArea : ( inspectionArea : InspectionArea ) => void
102- selectedInspectionArea : InspectionArea | undefined
103- handleScheduleAll : ( missionDefinitions : MissionDefinition [ ] ) => void
104- }
105-
106- export const InspectionAreaCards = ( {
107- inspectionAreaMissions,
108- onClickInspectionArea,
109- selectedInspectionArea,
110- handleScheduleAll,
111- } : IInspectionAreaCardProps ) => {
112- const { TranslateText } = useLanguageContext ( )
113-
114- return (
115- < >
116- { Object . keys ( inspectionAreaMissions ) . length > 0 ? (
117- < StyledInspectionAreaCards >
118- { inspectionAreaMissions . map ( ( inspectionAreaMission ) => (
119- < InspectionAreaCard
120- key = { 'inspectionAreaCard' + inspectionAreaMission . inspectionArea . inspectionAreaName }
121- inspectionAreaData = { inspectionAreaMission }
122- onClickInspectionArea = { onClickInspectionArea }
123- selectedInspectionArea = { selectedInspectionArea }
124- handleScheduleAll = { handleScheduleAll }
125- />
126- ) ) }
127- </ StyledInspectionAreaCards >
128- ) : (
129- < Placeholder >
130- < Typography variant = "h4" color = "disabled" >
131- { TranslateText ( 'No inspections available' ) }
132- </ Typography >
133- </ Placeholder >
134- ) }
135- </ >
136- )
137- }
0 commit comments