Skip to content

Commit 3a25ef7

Browse files
authored
Merge pull request #1272 from jadmsaadaot/out-of-date
Fix status out of date calculation
2 parents a793026 + 6afb622 commit 3a25ef7

File tree

5 files changed

+78
-10
lines changed

5 files changed

+78
-10
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""approved_date
2+
3+
Revision ID: 11c04609c1b4
4+
Revises: 74e3f8a6b3c2
5+
Create Date: 2023-11-16 14:50:22.513022
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '11c04609c1b4'
14+
down_revision = '74e3f8a6b3c2'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
with op.batch_alter_table('work_statuses', schema=None) as batch_op:
22+
batch_op.add_column(sa.Column('approved_date', sa.DateTime(timezone=True), nullable=True))
23+
24+
with op.batch_alter_table('work_statuses_history', schema=None) as batch_op:
25+
batch_op.add_column(sa.Column('approved_date', sa.DateTime(timezone=True), autoincrement=False, nullable=True))
26+
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade():
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
with op.batch_alter_table('work_statuses_history', schema=None) as batch_op:
33+
batch_op.drop_column('approved_date')
34+
35+
with op.batch_alter_table('work_statuses', schema=None) as batch_op:
36+
batch_op.drop_column('approved_date')
37+
38+
# ### end Alembic commands ###

epictrack-api/src/api/models/work_status.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class WorkStatus(BaseModelVersioned):
3535
work = relationship('Work', foreign_keys=[work_id], lazy='select')
3636
is_approved = Column(Boolean(), default=False, nullable=False)
3737
approved_by = Column(String(255), default=None, nullable=True)
38+
approved_date = Column(DateTime(timezone=True), nullable=True)
3839

3940
@classmethod
4041
def list_statuses_for_work_id(cls, work_id) -> List[WorkStatus]:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""Service to manage Work status."""
15+
from datetime import datetime
1516
from http import HTTPStatus
1617
from typing import Dict
1718

@@ -70,6 +71,7 @@ def approve_work_status(cls, work_status):
7071

7172
work_status.is_approved = True
7273
work_status.approved_by = TokenInfo.get_username()
74+
work_status.approved_date = datetime.utcnow()
7375

7476
work_status.save()
7577

epictrack-web/src/components/workPlan/status/StatusView/index.tsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import RecentStatus from "./RecentStatus";
66
import { Box, Grid } from "@mui/material";
77
import StatusHistory from "./StatusHistory";
88
import WarningBox from "../../../shared/warningBox";
9+
import { dateUtils } from "../../../../utils";
10+
import moment from "moment";
11+
import { When } from "react-if";
912

1013
const StatusView = () => {
1114
const { statuses } = React.useContext(WorkplanContext);
@@ -15,32 +18,55 @@ const StatusView = () => {
1518
setShowStatusForm(true);
1619
};
1720

21+
const STATUS_DATE_THRESHOLD = 7;
22+
23+
const isStatusOutOfDate = () => {
24+
const lastApprovedStatus = statuses.find((status) => status.is_approved);
25+
26+
if (!lastApprovedStatus) {
27+
return false;
28+
}
29+
30+
const daysAgo = moment().subtract(STATUS_DATE_THRESHOLD, "days");
31+
const NDaysAgo = dateUtils.diff(
32+
daysAgo.toLocaleString(),
33+
lastApprovedStatus?.approved_date,
34+
"days"
35+
);
36+
37+
return NDaysAgo > 0;
38+
};
39+
1840
return (
1941
<>
20-
{statuses.length === 0 && (
42+
<When condition={statuses.length === 0}>
2143
<NoDataEver
2244
title="You don't have any Statuses yet"
2345
subTitle="Create your first Status"
2446
addNewButtonText="Add Status"
2547
onAddNewClickHandler={() => onAddButtonClickHandler()}
2648
/>
27-
)}
28-
{statuses.length != 0 && !statuses[0].is_approved && (
49+
</When>
50+
<When condition={isStatusOutOfDate()}>
2951
<Box sx={{ paddingBottom: "16px" }}>
3052
<WarningBox
3153
title="The Work status is out of date"
3254
subTitle="Please provide an updated status"
3355
isTitleBold={true}
3456
/>
3557
</Box>
36-
)}
58+
</When>
3759
<Grid container spacing={2}>
38-
<Grid item xs={6}>
39-
{statuses.length > 0 && <RecentStatus />}
40-
</Grid>
41-
<Grid item xs={6}>
42-
{statuses.length > 1 && <StatusHistory />}
43-
</Grid>
60+
<When condition={statuses.length > 0}>
61+
<Grid item xs={6}>
62+
<RecentStatus />
63+
</Grid>
64+
</When>
65+
<When condition={statuses.length > 1}>
66+
<Grid item xs={6}>
67+
<StatusHistory />
68+
</Grid>
69+
</When>
4470
</Grid>
4571
</>
4672
);

epictrack-web/src/models/status.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export interface Status {
55
is_active: boolean;
66
is_approved: boolean;
77
approved_by?: string;
8+
approved_date: string;
89
}

0 commit comments

Comments
 (0)