Skip to content

Commit 79cc385

Browse files
authored
Add special history component for epd and work lead (#1499)
* Add special history component for epd and work lead * use and move specialfield lock component * add create work team lead special field * create special fields at create stage * resolve conflicts
1 parent 744b57e commit 79cc385

File tree

9 files changed

+881
-700
lines changed

9 files changed

+881
-700
lines changed

epictrack-api/src/api/services/work.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from api.models.indigenous_work import IndigenousWork
3535
from api.models.pagination_options import PaginationOptions
3636
from api.models.phase_code import PhaseVisibilityEnum
37+
from api.models.special_field import EntityEnum
3738
from api.models.work_status import WorkStatus
3839
from api.models.work_type import WorkType
3940
from api.schemas.request import ActionConfigurationBodyParameterSchema, OutcomeConfigurationBodyParameterSchema
@@ -49,6 +50,7 @@
4950
from api.services.outcome_configuration import OutcomeConfigurationService
5051
from api.services.outcome_template import OutcomeTemplateService
5152
from api.services.phaseservice import PhaseService
53+
from api.services.special_field import SpecialFieldService
5254
from api.services.work_phase import WorkPhaseService
5355

5456

@@ -186,6 +188,7 @@ def create_work(cls, payload, commit: bool = True):
186188
if cls.check_existence(payload["title"]):
187189
raise ResourceExistsError("Work with same title already exists")
188190
work = Work(**payload)
191+
cls.create_special_fields(work)
189192
work.work_state = WorkStateEnum.IN_PROGRESS
190193
phases = PhaseService.find_phase_codes_by_ea_act_and_work_type(
191194
work.ea_act_id, work.work_type_id
@@ -244,6 +247,28 @@ def create_work(cls, payload, commit: bool = True):
244247
db.session.commit()
245248
return work
246249

250+
@classmethod
251+
def create_special_fields(cls, work: Work):
252+
"""Create work special fields"""
253+
work.flush()
254+
work_epd_special_field_data = {
255+
"entity": EntityEnum.WORK,
256+
"entity_id": work.id,
257+
"field_name": "responsible_epd_id",
258+
"field_value": work.responsible_epd_id,
259+
"active_from": work.created_at
260+
}
261+
work_team_lead_special_field_data = {
262+
"entity": EntityEnum.WORK,
263+
"entity_id": work.id,
264+
"field_name": "work_lead_id",
265+
"field_value": work.work_lead_id,
266+
"active_from": work.created_at
267+
}
268+
269+
SpecialFieldService.create_special_field_entry(work_epd_special_field_data)
270+
SpecialFieldService.create_special_field_entry(work_team_lead_special_field_data)
271+
247272
@classmethod
248273
def find_staff(cls, work_id: int, is_active) -> [Staff]:
249274
"""Active staff assigned on a work"""

epictrack-web/src/components/project/ProjectForm.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import ControlledTextField from "../shared/controlledInputComponents/ControlledT
2020
import { SpecialFieldGrid } from "../shared/specialField";
2121
import {
2222
SpecialFieldEntityEnum,
23-
SpecialFields,
23+
SPECIAL_FIELDS,
2424
} from "../../constants/application-constant";
2525
import { Else, If, Then, When } from "react-if";
2626
import Icons from "../icons";
@@ -227,7 +227,7 @@ export default function ProjectForm({ ...props }) {
227227
>
228228
<ETFormLabel required>Name</ETFormLabel>
229229
<When condition={disabled}>
230-
<If condition={specialField === SpecialFields.PROJECT.NAME}>
230+
<If condition={specialField === SPECIAL_FIELDS.PROJECT.NAME}>
231231
<Then>
232232
<IconButton onClick={() => setSpecialField("")}>
233233
<LockOpenIcon fill={Palette.primary.accent.main} />
@@ -236,7 +236,7 @@ export default function ProjectForm({ ...props }) {
236236
<Else>
237237
<IconButton
238238
onClick={() =>
239-
setSpecialField(SpecialFields.PROJECT.NAME)
239+
setSpecialField(SPECIAL_FIELDS.PROJECT.NAME)
240240
}
241241
>
242242
<LockClosedIcon fill={Palette.primary.accent.main} />
@@ -265,7 +265,9 @@ export default function ProjectForm({ ...props }) {
265265
<ETFormLabel required>Proponent</ETFormLabel>
266266
<When condition={disabled}>
267267
<If
268-
condition={specialField === SpecialFields.PROJECT.PROPONENT}
268+
condition={
269+
specialField === SPECIAL_FIELDS.PROJECT.PROPONENT
270+
}
269271
>
270272
<Then>
271273
<IconButton onClick={() => setSpecialField("")}>
@@ -275,7 +277,7 @@ export default function ProjectForm({ ...props }) {
275277
<Else>
276278
<IconButton
277279
onClick={() =>
278-
setSpecialField(SpecialFields.PROJECT.PROPONENT)
280+
setSpecialField(SPECIAL_FIELDS.PROJECT.PROPONENT)
279281
}
280282
>
281283
<LockClosedIcon fill={Palette.primary.accent.main} />
@@ -303,33 +305,33 @@ export default function ProjectForm({ ...props }) {
303305
entity_id={(ctx.item as Project)?.id}
304306
fieldName={specialField}
305307
fieldLabel={
306-
specialField === SpecialFields.PROJECT.PROPONENT
308+
specialField === SPECIAL_FIELDS.PROJECT.PROPONENT
307309
? "Proponent Name"
308310
: "Name"
309311
}
310312
fieldType={
311-
specialField === SpecialFields.PROJECT.PROPONENT
313+
specialField === SPECIAL_FIELDS.PROJECT.PROPONENT
312314
? "select"
313315
: "text"
314316
}
315317
title={
316-
specialField === SpecialFields.PROJECT.PROPONENT
318+
specialField === SPECIAL_FIELDS.PROJECT.PROPONENT
317319
? "Proponet History"
318320
: (ctx.item as Project)?.name
319321
}
320322
description={
321323
<>
322324
<When
323325
condition={
324-
specialField === SpecialFields.PROJECT.PROPONENT
326+
specialField === SPECIAL_FIELDS.PROJECT.PROPONENT
325327
}
326328
>
327329
Update the Proponent of this Project.{" "}
328330
<a href="#">Click this link</a> for detailed
329331
instructions.
330332
</When>
331333
<When
332-
condition={specialField === SpecialFields.PROJECT.NAME}
334+
condition={specialField === SPECIAL_FIELDS.PROJECT.NAME}
333335
>
334336
Update the legal name of the Project and the dates each
335337
name was in legal use. <a href="#">Click this link</a>{" "}
@@ -338,7 +340,7 @@ export default function ProjectForm({ ...props }) {
338340
</>
339341
}
340342
options={
341-
specialField === SpecialFields.PROJECT.PROPONENT
343+
specialField === SPECIAL_FIELDS.PROJECT.PROPONENT
342344
? proponents?.map((p) => ({
343345
label: p.name,
344346
value: p.id.toString(),

0 commit comments

Comments
 (0)