Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into 215787_drop_cash_a…
Browse files Browse the repository at this point in the history
…ssist
  • Loading branch information
marekbiczysko committed Nov 13, 2024
2 parents d97229d + 57ca1fe commit 7122b03
Show file tree
Hide file tree
Showing 50 changed files with 1,541 additions and 124 deletions.
4 changes: 2 additions & 2 deletions development_tools/local_selenium_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export PYTHONPATH=$MAIN_DIR/src:$PYTHONPATH
export OUTPUT_DATA_ROOT=$MAIN_DIR/tests/selenium/output_data
export DATA_VOLUME=$OUTPUT_DATA_ROOT/data
pushd $MAIN_DIR/src/frontend
yarn
yarn build-for-backend
yarn
yarn build-for-backend
popd
2 changes: 1 addition & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/frontend/src/containers/pages/dashboard/NewDashboardPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useBaseUrl } from '@hooks/useBaseUrl';
import { FC } from 'react';

export const NewDashboardPage: FC = () => {
const { businessArea } = useBaseUrl();
const dashboardUrl = `${window.location.origin}/api/rest/dashboard/${businessArea}/`;
return (
<div style={{ height: '100vh', width: '100%' }}>
<iframe
src={dashboardUrl}
style={{
width: '100%',
height: '100vh',
border: 'none',
}}
title="Dashboard"
/>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useRoutes } from 'react-router-dom';
import { ActivityLogPage } from '../pages/core/MainActivityLogPage';
import { DashboardPage } from '../pages/dashboard/DashboardPage';
import { ReportingDetailsPage } from '../pages/reporting/ReportingDetailsPage';
import { ReportingPage } from '../pages/reporting/ReportingPage';
import { GrievanceRoutes } from './GrievanceRoutes';
import { ProgramRoutes } from './ProgramRoutes';
import { ManagerialConsolePage } from '@containers/pages/managerialConsole/ManagerialConsolePage';
import { ReactElement } from 'react';
import { NewDashboardPage } from '@containers/pages/dashboard/NewDashboardPage';

export const AllProgramsRoutesSwitch = (): ReactElement => {
const allProgramsRoutes = [
{
path: 'country-dashboard',
element: <DashboardPage />,
element: <NewDashboardPage />,
},
{
path: 'reporting/:id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ActivityLogPage } from '../pages/core/MainActivityLogPage';
import { UsersPage } from '../pages/core/UsersPage';
import { ReportingDetailsPage } from '../pages/reporting/ReportingDetailsPage';
import { ReportingPage } from '../pages/reporting/ReportingPage';
import { DashboardPage } from '../pages/dashboard/DashboardPage';
import { GrievanceRoutes } from './GrievanceRoutes';
import { PaymentModuleRoutes } from './PaymentModuleRoutes';
import { PaymentVerificationRoutes } from './PaymentVerificationRoutes';
Expand All @@ -13,12 +12,13 @@ import { RegistrationRoutes } from './RegistrationRoutes';
import { TargetingRoutes } from './TargetingRoutes';
import { AccountabilityRoutes } from './AccountabilityRoutes';
import { ReactElement } from 'react';
import { NewDashboardPage } from '@containers/pages/dashboard/NewDashboardPage';

export const SelectedProgramRoutesSwitch = (): ReactElement => {
const routes = useRoutes([
{
path: 'country-dashboard',
element: <DashboardPage />,
element: <NewDashboardPage />,
},
{
path: 'reporting/:id',
Expand Down
12 changes: 9 additions & 3 deletions src/frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { defineConfig, splitVendorChunkPlugin } from 'vite';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';

// https://vitejs.dev/config/
export default defineConfig({
assetsInclude: ['**/*.png'],
base: '',
plugins: [tsconfigPaths(), react(), splitVendorChunkPlugin()],
base: '/',
publicDir: 'public',
plugins: [tsconfigPaths(), react()],
resolve: {
mainFields: [],
},
Expand All @@ -22,6 +23,11 @@ export default defineConfig({
manifest: true,
rollupOptions: {
input: '/src/main.tsx',
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
},
},
},
},
server: {
Expand Down
1 change: 1 addition & 0 deletions src/hct_mis_api/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
path("lookups/program-statuses/", endpoints.lookups.ProgramStatuses().as_view(), name="program-statuses-list"),
path("business_areas/", endpoints.core.BusinessAreaListView.as_view(), name="business-area-list"),
path("programs/", ProgramGlobalListView.as_view(), name="program-global-list"),
path("dashboard/", include("hct_mis_api.apps.dashboard.urls")),
path(
"<slug:business_area>/",
include(
Expand Down
4 changes: 4 additions & 0 deletions src/hct_mis_api/apps/core/tasks_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@
"task": "hct_mis_api.apps.periodic_data_update.celery_tasks.remove_old_pdu_template_files_task",
"schedule": crontab(hour="*/24"),
},
"update_dashboard_figures_task": {
"task": "hct_mis_api.apps.dashboard.celery_tasks.update_dashboard_figures",
"schedule": crontab(hour="*/24"),
},
}
Empty file.
1 change: 1 addition & 0 deletions src/hct_mis_api/apps/dashboard/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Register your models here.
5 changes: 5 additions & 0 deletions src/hct_mis_api/apps/dashboard/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class DashboardConfig(AppConfig):
name = "hct_mis_api.apps.dashboard"
50 changes: 50 additions & 0 deletions src/hct_mis_api/apps/dashboard/celery_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging
from typing import Any

from hct_mis_api.apps.core.celery import app
from hct_mis_api.apps.core.models import BusinessArea
from hct_mis_api.apps.dashboard.services import DashboardDataCache
from hct_mis_api.apps.utils.logs import log_start_and_end
from hct_mis_api.apps.utils.sentry import sentry_tags, set_sentry_business_area_tag

logger = logging.getLogger(__name__)

CACHE_TIMEOUT = 60 * 60 * 24 # 24 hours


@app.task(bind=True, default_retry_delay=60, max_retries=3)
@log_start_and_end
@sentry_tags
def update_dashboard_figures(self: Any) -> None:
"""
Celery task that runs every 24 hours to refresh dashboard data for all business areas
with households.
"""
business_areas_with_households = BusinessArea.objects.using("read_only").filter(active=True)

for business_area in business_areas_with_households:
try:
set_sentry_business_area_tag(business_area.slug)
DashboardDataCache.refresh_data(business_area.slug)

except Exception as e:
logger.error(f"Failed to refresh dashboard data for {business_area.slug}: {e}")
raise self.retry(exc=e)


@app.task(bind=True, default_retry_delay=60, max_retries=3)
@log_start_and_end
@sentry_tags
def generate_dash_report_task(self: Any, business_area_slug: str) -> None:
"""
Celery task to refresh dashboard data for a specific business area.
"""
try:
business_area = BusinessArea.objects.get(slug=business_area_slug)
set_sentry_business_area_tag(business_area.slug)
DashboardDataCache.refresh_data(business_area.slug)

except BusinessArea.DoesNotExist:
logger.error(f"Business area with slug {business_area_slug} not found.")
except Exception as e:
raise self.retry(exc=e, countdown=60)
Empty file.
20 changes: 20 additions & 0 deletions src/hct_mis_api/apps/dashboard/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from rest_framework import serializers


class DashboardHouseholdSerializer(serializers.Serializer):
business_area_name = serializers.CharField()
total_delivered_quantity_usd = serializers.DecimalField(max_digits=12, decimal_places=2)
total_delivered_quantity = serializers.DecimalField(max_digits=12, decimal_places=2)
payments = serializers.IntegerField()
individuals = serializers.IntegerField()
households = serializers.IntegerField()
children_counts = serializers.IntegerField()
month = serializers.CharField()
year = serializers.IntegerField()
program = serializers.CharField()
sector = serializers.CharField()
status = serializers.CharField()
admin1 = serializers.CharField()
fsp = serializers.CharField()
delivery_types = serializers.CharField()
pwd_counts = serializers.IntegerField()
Loading

0 comments on commit 7122b03

Please sign in to comment.