Skip to content

Commit

Permalink
Work on control mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
lwih committed Oct 16, 2023
1 parent 46e06e6 commit 96bf240
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: "Release"

on:
push:
branches: ["main"]
# push:
# branches: ["main"]
release:
types: [published]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdmi
import java.util.*

data class ControlAdministrativeInput(
val id: UUID,
val id: UUID?,
val missionId: Int,
val actionControlId: UUID,
val confirmed: Boolean?,
Expand All @@ -15,7 +15,7 @@ data class ControlAdministrativeInput(
) {
fun toControlAdministrative(): ControlAdministrative {
return ControlAdministrative(
id = id,
id = id ?: UUID.randomUUID(),
missionId = missionId,
actionControlId = actionControlId,
confirmed = confirmed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGens
import java.util.*

data class ControlGensDeMerInput(
val id: UUID,
val id: UUID?,
val missionId: Int,
val actionControlId: UUID,
val confirmed: Boolean?,
Expand All @@ -15,7 +15,7 @@ data class ControlGensDeMerInput(
) {
fun toControlGensDeMer(): ControlGensDeMer {
return ControlGensDeMer(
id = id,
id = id ?: UUID.randomUUID(),
missionId = missionId,
actionControlId = actionControlId,
confirmed = confirmed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavi
import java.util.*

data class ControlNavigationInput(
val id: UUID,
val id: UUID?,
val missionId: Int,
val actionControlId: UUID,
val confirmed: Boolean?,
val observations: String?
) {
fun toControlNavigation(): ControlNavigation {
return ControlNavigation(
id = id,
id = id ?: UUID.randomUUID(),
missionId = missionId,
actionControlId = actionControlId,
confirmed = confirmed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecu
import java.util.*

data class ControlSecurityInput(
val id: UUID,
val id: UUID?,
val missionId: Int,
val actionControlId: UUID,
val confirmed: Boolean?,
val observations: String?
) {
fun toControlSecurity(): ControlSecurity {
return ControlSecurity(
id = id,
id = id ?: UUID.randomUUID(),
missionId = missionId,
actionControlId = actionControlId,
confirmed = confirmed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ data class ControlAdministrativeModel(
fun toControlAdministrative() = ControlAdministrative(
id = id,
missionId = missionId,
actionControlId = actionControl!!.id,
actionControlId = actionControlId,
confirmed = confirmed,
compliantOperatingPermit = compliantOperatingPermit,
upToDateNavigationPermit = upToDateNavigationPermit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ data class ControlGensDeMerModel(
fun toControlGensDeMer() = ControlGensDeMer(
id = id,
missionId = missionId,
actionControlId = actionControl!!.id,
actionControlId = actionControlId,
confirmed = confirmed,
staffOutnumbered = staffOutnumbered,
upToDateMedicalCheck = upToDateMedicalCheck,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class ControlNavigationModel(
fun toControlNavigation() = ControlNavigation(
id = id,
missionId = missionId,
actionControlId = actionControl!!.id,
actionControlId = actionControlId,
confirmed = confirmed,
observations = observations
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class ControlSecurityModel(
fun toControlSecurity() = ControlSecurity(
id = id,
missionId = missionId,
actionControlId = actionControl!!.id,
actionControlId = actionControlId,
confirmed = confirmed,
observations = observations
)
Expand Down
8 changes: 4 additions & 4 deletions backend/src/main/resources/graphql/controls.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ControlGensDeMer {
}

input ControlNavigationInput {
id: String!
id: String
missionId: String!
actionControlId: String!
confirmed: Boolean
Expand All @@ -46,15 +46,15 @@ input ControlNavigationInput {


input ControlSecurityInput {
id: String!
id: String
missionId: String!
actionControlId: String!
confirmed: Boolean
observations: String
}

input ControlAdministrativeInput {
id: String!
id: String
missionId: String!
actionControlId: String!
confirmed: Boolean
Expand All @@ -65,7 +65,7 @@ input ControlAdministrativeInput {
}

input ControlGensDeMerInput {
id: String!
id: String
missionId: String!
actionControlId: String!
confirmed: Boolean
Expand Down
16 changes: 12 additions & 4 deletions frontend/src/pam/mission/actions/action-control-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ const ActionControlNav: React.FC<ActionControlNavProps> = ({ action, resetSelect
collapsible
style={{ backgroundColor: THEME.color.white, borderRadius: 0 }}
>
<ControlAdministrativeForm data={control.controlAdministrative} />{' '}
<ControlAdministrativeForm
missionId={missionId}
actionControlId={action.id}
data={control.controlAdministrative}
/>{' '}
</Panel>
</Stack.Item>
<Stack.Item style={{ width: '100%' }}>
Expand All @@ -243,7 +247,11 @@ const ActionControlNav: React.FC<ActionControlNavProps> = ({ action, resetSelect
collapsible
style={{ backgroundColor: THEME.color.white, borderRadius: 0 }}
>
<ControlNavigationForm data={control.controlNavigation} />
<ControlNavigationForm
missionId={missionId}
actionControlId={action.id}
data={control.controlNavigation}
/>
</Panel>
</Stack.Item>
<Stack.Item style={{ width: '100%' }}>
Expand All @@ -256,7 +264,7 @@ const ActionControlNav: React.FC<ActionControlNavProps> = ({ action, resetSelect
collapsible
style={{ backgroundColor: THEME.color.white, borderRadius: 0 }}
>
<ControlGensDeMerForm data={control.controlGensDeMer} />
<ControlGensDeMerForm missionId={missionId} actionControlId={action.id} data={control.controlGensDeMer} />
</Panel>
</Stack.Item>
<Stack.Item style={{ width: '100%' }}>
Expand All @@ -269,7 +277,7 @@ const ActionControlNav: React.FC<ActionControlNavProps> = ({ action, resetSelect
collapsible
style={{ backgroundColor: THEME.color.white, borderRadius: 0 }}
>
<ControlSecurityForm data={control.controlNavigation} />
<ControlSecurityForm missionId={missionId} actionControlId={action.id} data={control.controlNavigation} />
</Panel>
</Stack.Item>
</Stack>
Expand Down
41 changes: 35 additions & 6 deletions frontend/src/pam/mission/controls/control-administrative-form.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import { Stack } from 'rsuite'
import { ControlAdministrative } from '../../mission-types'
import { THEME, Icon, Button, Accent, Size, Textarea, MultiRadio } from '@mtes-mct/monitor-ui'
import { THEME, Icon, Button, Accent, Size, Textarea, MultiRadio, OptionValue } from '@mtes-mct/monitor-ui'
import { CONTROL_MULTIRADIO_OPTIONS } from './utils'
import { useMutation } from '@apollo/client'
import { MUTATION_ADD_OR_UPDATE_CONTROL_ADMINISTRATIVE } from '../queries'

interface ControlAdministrativeFormProps {
missionId: String
actionControlId: String
data?: ControlAdministrative
}

const ControlAdministrativeForm: React.FC<ControlAdministrativeFormProps> = ({ data }) => {
const ControlAdministrativeForm: React.FC<ControlAdministrativeFormProps> = ({ missionId, actionControlId, data }) => {
const [mutate, { statusData, statusLoading, statusError }] = useMutation(
MUTATION_ADD_OR_UPDATE_CONTROL_ADMINISTRATIVE,
{
refetchQueries: ['GetMissionById']
}
)

const onChange = (field: string, value: any) => {
const updatedData = {
...data,
missionId: missionId,
actionControlId: actionControlId,
[field]: value
}
debugger
mutate({ variables: { control: updatedData } })

// TODO this shouldn't be like that - useState should not be used
// setStatus(updatedData)
}

return (
<Stack direction="column" alignItems="flex-start" spacing="1rem" style={{ width: '100%' }}>
<Stack.Item style={{ width: '100%' }}>
Expand All @@ -17,7 +42,7 @@ const ControlAdministrativeForm: React.FC<ControlAdministrativeFormProps> = ({ d
isInline
label="Permis de mise en exploitation (autorisation à pêcher) conforme"
name="compliantOperatingPermit"
onChange={function noRefCheck() {}}
onChange={(nextValue: OptionValue) => onChange('compliantOperatingPermit', nextValue)}
options={CONTROL_MULTIRADIO_OPTIONS}
/>
</Stack.Item>
Expand All @@ -28,7 +53,7 @@ const ControlAdministrativeForm: React.FC<ControlAdministrativeFormProps> = ({ d
isInline
label="Permis de navigation à jour"
name="upToDateNavigationPermit"
onChange={function noRefCheck() {}}
onChange={(nextValue: OptionValue) => onChange('upToDateNavigationPermit', nextValue)}
options={CONTROL_MULTIRADIO_OPTIONS}
/>
</Stack.Item>
Expand All @@ -39,12 +64,16 @@ const ControlAdministrativeForm: React.FC<ControlAdministrativeFormProps> = ({ d
isInline
label="Titres de sécurité conformes"
name="compliantSecurityDocuments"
onChange={function noRefCheck() {}}
onChange={(nextValue: OptionValue) => onChange('compliantSecurityDocuments', nextValue)}
options={CONTROL_MULTIRADIO_OPTIONS}
/>
</Stack.Item>
<Stack.Item style={{ width: '100%' }}>
<Textarea label="Observations (hors infraction) sur les pièces administratives" value={data?.observations} />
<Textarea
label="Observations (hors infraction) sur les pièces administratives"
value={data?.observations}
onChange={(nextValue: string) => onChange('observations', nextValue)}
/>
</Stack.Item>
<Stack.Item style={{ width: '100%' }}>
<Button accent={Accent.SECONDARY} size={Size.NORMAL} Icon={Icon.Plus} isFullWidth>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { THEME, Icon, Button, Accent, Size, Textarea, MultiRadio } from '@mtes-m
import { CONTROL_MULTIRADIO_OPTIONS } from './utils'

interface ControlGensDeMerFormProps {
missionId: String
actionControlId: String
data?: ControlGensDeMer
}

const ControlGensDeMerForm: React.FC<ControlGensDeMerFormProps> = ({ data }) => {
const ControlGensDeMerForm: React.FC<ControlGensDeMerFormProps> = ({ missionId, actionControlId, data }) => {
return (
<Stack direction="column" alignItems="flex-start" spacing="1rem" style={{ width: '100%' }}>
<Stack.Item style={{ width: '100%' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { ControlNavigation } from '../../mission-types'
import { THEME, Icon, Button, Accent, Size, Textarea } from '@mtes-mct/monitor-ui'

interface ControlNavigationFormProps {
missionId: String
actionControlId: String
data?: ControlNavigation
}

const ControlNavigationForm: React.FC<ControlNavigationFormProps> = ({ data }) => {
const ControlNavigationForm: React.FC<ControlNavigationFormProps> = ({ missionId, actionControlId, data }) => {
return (
<Stack direction="column" alignItems="flex-start" spacing="1rem" style={{ width: '100%' }}>
<Stack.Item style={{ width: '100%' }}>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/pam/mission/controls/control-security-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { ControlSecurity } from '../../mission-types'
import { THEME, Icon, Button, Accent, Size, Textarea } from '@mtes-mct/monitor-ui'

interface ControlSecurityFormProps {
missionId: String
actionControlId: String
data?: ControlSecurity
}

const ControlSecurityForm: React.FC<ControlSecurityFormProps> = ({ data }) => {
const ControlSecurityForm: React.FC<ControlSecurityFormProps> = ({ missionId, actionControlId, data }) => {
return (
<Stack direction="column" alignItems="flex-start" spacing="1rem" style={{ width: '100%' }}>
<Stack.Item style={{ width: '100%' }}>
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/pam/mission/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,32 @@ export const DELETE_ACTION_CONTROL = gql`
deleteControl(id: $id)
}
`

export const MUTATION_ADD_OR_UPDATE_CONTROL_GENS_DE_MER = gql`
mutation AddOrUpdateControlGensDeMer($control: ControlGensDeMerInput!) {
addOrUpdateControlGensDeMer(control: $control) {
id
}
}
`
export const MUTATION_ADD_OR_UPDATE_CONTROL_NAVIGATION = gql`
mutation AddOrUpdateControlNavigation($control: ControlNavigationInput!) {
addOrUpdateControlGensDeMer(control: $control) {
id
}
}
`
export const MUTATION_ADD_OR_UPDATE_CONTROL_SECURITY = gql`
mutation AddOrUpdateControlSecurity($control: ControlSecurityInput!) {
addOrUpdateControlSecurity(control: $control) {
id
}
}
`
export const MUTATION_ADD_OR_UPDATE_CONTROL_ADMINISTRATIVE = gql`
mutation AddOrUpdateControlAdministrative($control: ControlAdministrativeInput!) {
addOrUpdateControlAdministrative(control: $control) {
id
}
}
`

0 comments on commit 96bf240

Please sign in to comment.