Skip to content

Commit

Permalink
fix: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Sep 25, 2024
1 parent a0d8437 commit b796243
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dhis2-verify-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Build
run: yarn d2-app-scripts build

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: app-build
path: |
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
with:
node-version: 14.x

- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: app-build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
usePeriodId,
periodTypesMapping,
yearlyFixedPeriodTypes,
isDateALessThanDateB,
isDateAGreaterThanDateB,
} from '../../shared/index.js'
import DisabledTooltip from './disabled-tooltip.js'
import PeriodMenu from './period-menu.js'
Expand All @@ -36,11 +36,13 @@ const getMaxYear = (dateLimit) => {
// periods run up to, but not including dateLimit, so if limit is 1 January, max year is previous year
// otherwise, max year is the year from the date limit
const dateLimitYear = getYear(dateLimit)

try {
const [year, month, day] = dateLimit.split('-')
if (Number(month) === 1 && Number(day) === 1) {
return Number(year) - 1
}
return dateLimitYear
} catch (e) {
console.error(e)
return dateLimitYear
Expand All @@ -50,7 +52,10 @@ const getMaxYear = (dateLimit) => {
export const PeriodSelectorBarItem = () => {
const { systemInfo = {} } = useConfig()
const { calendar = 'gregory' } = systemInfo
const { eraYear: currentFullYear } = getNowInCalendar(calendar)
const { eraYear: nowEraYear, year: nowYear } = getNowInCalendar(calendar)
const currentFullYear = ['ethiopian', 'ethiopic'].includes(calendar)
? nowEraYear
: nowYear

const [periodOpen, setPeriodOpen] = useState(false)
const [periodId, setPeriodId] = usePeriodId()
Expand Down Expand Up @@ -117,7 +122,7 @@ export const PeriodSelectorBarItem = () => {

// date comparison
if (
isDateALessThanDateB(endDate, dateLimit, {
isDateAGreaterThanDateB(endDate, dateLimit, {
inclusive: true,
calendar,
})
Expand Down
15 changes: 9 additions & 6 deletions src/context-selection/period-selector-bar-item/use-periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ export default function usePeriods({
// date comparison
if (
lastPeriodOfPrevYear &&
// `${year}-01-01` <= lastPeriodOfPrevYear.endDate
isDateALessThanDateB(`${year}`, lastPeriodOfPrevYear.endDate, {
inclusive: true,
calendar,
})
isDateALessThanDateB(
`${year}-01-01`,
lastPeriodOfPrevYear.endDate,
{
inclusive: true,
calendar,
}
)
) {
const [lastPeriodOfPrevYear] = generateFixedPeriods({
...generateFixedPeriodsPayload,
Expand All @@ -95,7 +98,7 @@ export default function usePeriods({
firstPeriodNextYear &&
// `${year + 1}-01-01` > firstPeriodNextYear.startDate
isDateAGreaterThanDateB(
`${year + 1}`,
`${year + 1}-01-01`,
firstPeriodNextYear.startDate,
{ inclusive: false, calendar }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function YearNavigator({
onYearChange,
calendar,
}) {
// console.log('maxYear', maxYear)
const startYear = startingYears[calendar] ?? startingYears.default
return (
<div className={classes.container}>
Expand Down
23 changes: 16 additions & 7 deletions src/data-workspace/data-details-sidebar/audit-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ export default function AuditLog({ item }) {
<DataTable>
<TableHead>
<DataTableRow>
<DataTableColumnHeader>Date</DataTableColumnHeader>
<DataTableColumnHeader>User</DataTableColumnHeader>
<DataTableColumnHeader>
Change
{i18n.t('Date')}
</DataTableColumnHeader>
<DataTableColumnHeader>
{i18n.t('User')}
</DataTableColumnHeader>
<DataTableColumnHeader>
{i18n.t('Change')}
</DataTableColumnHeader>
</DataTableRow>
</TableHead>
Expand All @@ -109,10 +113,7 @@ export default function AuditLog({ item }) {
{created
? `${created
.substring(0, 16)
.replace(
'T',
' '
)} (${timezone})`
.replace('T', ' ')}`
: null}
</DataTableCell>
<DataTableCell>{user}</DataTableCell>
Expand All @@ -138,6 +139,14 @@ export default function AuditLog({ item }) {
})}
</TableBody>
</DataTable>
{audits.length > 0 && (
<div className={styles.timeZoneNote}>
{i18n.t(
'audit dates are given in {{- timezone}} time',
{ timezone }
)}
</div>
)}
</div>
</ExpandableUnit>
)
Expand Down
7 changes: 7 additions & 0 deletions src/data-workspace/data-details-sidebar/audit-log.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@

.alignToEnd {
text-align: right;
}

.timeZoneNote {
margin-block-start: var(--spacers-dp4);
font-size: 12px;
line-height: 19px;
color: var(--colors-grey600);
}
9 changes: 6 additions & 3 deletions src/shared/date/get-now-in-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ const pad = (startValue, minLength, padString) => {
}
}

const stringifyDate = (temporalDate, long) => {
const shortDate = `${pad(temporalDate.eraYear, 4, '0')}-${pad(
const stringifyDate = (temporalDate, long, calendar) => {
const year = ['ethiopian', 'ethiopic'].includes(calendar)
? temporalDate.eraYear
: temporalDate.year
const shortDate = `${pad(year, 4, '0')}-${pad(
temporalDate.month,
2,
'0'
Expand All @@ -32,5 +35,5 @@ export const getNowInCalendarString = ({
long = false,
}) => {
const nowTemporal = getNowInCalendar(calendar, timezone)
return stringifyDate(nowTemporal, long)
return stringifyDate(nowTemporal, long, calendar)
}

0 comments on commit b796243

Please sign in to comment.