Skip to content

Commit

Permalink
wip: project status filter
Browse files Browse the repository at this point in the history
fix: disable clear button but use default order on software and project overview page
  • Loading branch information
dmijatovic committed Aug 11, 2023
1 parent b23eec9 commit d5c0fef
Show file tree
Hide file tree
Showing 20 changed files with 389 additions and 52 deletions.
84 changes: 77 additions & 7 deletions database/105-project-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ GROUP BY
output_for_project.project;
$$;

CREATE FUNCTION project_status() RETURNS TABLE (
project UUID,
status VARCHAR(20)
) LANGUAGE sql STABLE AS
$$
SELECT
project.id,
CASE
WHEN project.date_end < now() THEN 'finished'::VARCHAR
WHEN project.date_start > now() THEN 'pending'::VARCHAR
WHEN project.date_start < now() AND project.date_end > now() THEN 'in_progress'::VARCHAR
ELSE 'unknown'::VARCHAR
END AS status
FROM
project
$$;

CREATE FUNCTION project_quality(show_all BOOLEAN DEFAULT FALSE) RETURNS TABLE (
slug VARCHAR,
Expand Down Expand Up @@ -263,7 +279,7 @@ INNER JOIN
$$;

-- AGGREGATE participating organisations per project for project_overview RPC
-- use only TOP LEVEL organisations (paren IS NULL)
-- use only TOP LEVEL organisations (parent IS NULL)
CREATE FUNCTION project_participating_organisations() RETURNS TABLE (
project UUID,
organisations VARCHAR[]
Expand Down Expand Up @@ -303,7 +319,8 @@ CREATE FUNCTION project_overview() RETURNS TABLE (
research_domain_text TEXT,
participating_organisations VARCHAR[],
impact_cnt INTEGER,
output_cnt INTEGER
output_cnt INTEGER,
project_status VARCHAR(20)
) LANGUAGE sql STABLE AS
$$
SELECT
Expand All @@ -323,7 +340,8 @@ SELECT
research_domain_filter_for_project.research_domain_text,
project_participating_organisations.organisations AS participating_organisations,
COALESCE(count_project_impact.impact_cnt, 0) AS impact_cnt,
COALESCE(count_project_output.output_cnt, 0) AS output_cnt
COALESCE(count_project_output.output_cnt, 0) AS output_cnt,
project_status.status
FROM
project
LEFT JOIN
Expand All @@ -333,9 +351,11 @@ LEFT JOIN
LEFT JOIN
project_participating_organisations() ON project.id=project_participating_organisations.project
LEFT JOIN
count_project_impact() ON project.id = count_project_impact.project
count_project_impact() ON project.id=count_project_impact.project
LEFT JOIN
count_project_output() ON project.id = count_project_output.project
count_project_output() ON project.id=count_project_output.project
LEFT JOIN
project_status() ON project.id=project_status.project
;
$$;

Expand All @@ -358,7 +378,8 @@ CREATE FUNCTION project_search(search VARCHAR) RETURNS TABLE (
research_domain_text TEXT,
participating_organisations VARCHAR[],
impact_cnt INTEGER,
output_cnt INTEGER
output_cnt INTEGER,
project_status VARCHAR(20)
) LANGUAGE sql STABLE AS
$$
SELECT
Expand All @@ -378,7 +399,8 @@ SELECT
research_domain_filter_for_project.research_domain_text,
project_participating_organisations.organisations AS participating_organisations,
COALESCE(count_project_impact.impact_cnt, 0),
COALESCE(count_project_output.output_cnt, 0)
COALESCE(count_project_output.output_cnt, 0),
project_status.status
FROM
project
LEFT JOIN
Expand All @@ -391,6 +413,8 @@ LEFT JOIN
count_project_impact() ON project.id = count_project_impact.project
LEFT JOIN
count_project_output() ON project.id = count_project_output.project
LEFT JOIN
project_status() ON project.id=project_status.project
WHERE
project.title ILIKE CONCAT('%', search, '%')
OR
Expand Down Expand Up @@ -427,6 +451,7 @@ $$;
-- PROVIDES AVAILABLE KEYWORDS FOR APPLIED FILTERS
CREATE FUNCTION project_keywords_filter(
search_filter TEXT DEFAULT '',
status_filter VARCHAR DEFAULT '',
keyword_filter CITEXT[] DEFAULT '{}',
research_domain_filter VARCHAR[] DEFAULT '{}',
organisation_filter VARCHAR[] DEFAULT '{}'
Expand All @@ -446,6 +471,11 @@ WHERE
COALESCE(research_domain, '{}') @> research_domain_filter
AND
COALESCE(participating_organisations, '{}') @> organisation_filter
AND
CASE
WHEN status_filter <> '' THEN project_status = status_filter
ELSE true
END
GROUP BY
keyword
;
Expand All @@ -456,6 +486,7 @@ $$;
-- PROVIDES AVAILABLE DOMAINS FOR APPLIED FILTERS
CREATE FUNCTION project_domains_filter(
search_filter TEXT DEFAULT '',
status_filter VARCHAR DEFAULT '',
keyword_filter CITEXT[] DEFAULT '{}',
research_domain_filter VARCHAR[] DEFAULT '{}',
organisation_filter VARCHAR[] DEFAULT '{}'
Expand All @@ -475,6 +506,11 @@ WHERE
COALESCE(research_domain, '{}') @> research_domain_filter
AND
COALESCE(participating_organisations, '{}') @> organisation_filter
AND
CASE
WHEN status_filter <> '' THEN project_status = status_filter
ELSE true
END
GROUP BY
domain
;
Expand All @@ -484,6 +520,7 @@ $$;
-- PROVIDES AVAILABLE DOMAINS FOR APPLIED FILTERS
CREATE FUNCTION project_participating_organisations_filter(
search_filter TEXT DEFAULT '',
status_filter VARCHAR DEFAULT '',
keyword_filter CITEXT[] DEFAULT '{}',
research_domain_filter VARCHAR[] DEFAULT '{}',
organisation_filter VARCHAR[] DEFAULT '{}'
Expand All @@ -503,7 +540,40 @@ WHERE
COALESCE(research_domain, '{}') @> research_domain_filter
AND
COALESCE(participating_organisations, '{}') @> organisation_filter
AND
CASE
WHEN status_filter <> '' THEN project_status = status_filter
ELSE true
END
GROUP BY
organisation
;
$$;

-- REACTIVE PROJECT STATUS WITH COUNTS
-- PROVIDES AVAILABLE DOMAINS FOR APPLIED FILTERS
CREATE FUNCTION project_status_filter(
search_filter TEXT DEFAULT '',
keyword_filter CITEXT[] DEFAULT '{}',
research_domain_filter VARCHAR[] DEFAULT '{}',
organisation_filter VARCHAR[] DEFAULT '{}'
) RETURNS TABLE (
project_status VARCHAR,
project_status_cnt INTEGER
) LANGUAGE sql STABLE AS
$$
SELECT
project_status,
COUNT(id) AS project_status_cnt
FROM
project_search(search_filter)
WHERE
COALESCE(keywords, '{}') @> keyword_filter
AND
COALESCE(research_domain, '{}') @> research_domain_filter
AND
COALESCE(participating_organisations, '{}') @> organisation_filter
GROUP BY
project_status
;
$$;
16 changes: 12 additions & 4 deletions database/112-organisation-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ CREATE FUNCTION projects_by_organisation(organisation_id UUID) RETURNS TABLE (
research_domain VARCHAR[],
participating_organisations VARCHAR[],
impact_cnt INTEGER,
output_cnt INTEGER
output_cnt INTEGER,
project_status VARCHAR(20)
) LANGUAGE sql STABLE AS
$$
SELECT DISTINCT ON (project.id)
Expand All @@ -42,7 +43,8 @@ SELECT DISTINCT ON (project.id)
research_domain_filter_for_project.research_domain,
project_participating_organisations.organisations AS participating_organisations,
COALESCE(count_project_impact.impact_cnt, 0) AS impact_cnt,
COALESCE(count_project_output.output_cnt, 0) AS output_cnt
COALESCE(count_project_output.output_cnt, 0) AS output_cnt,
project_status.status
FROM
project
LEFT JOIN
Expand All @@ -57,6 +59,8 @@ LEFT JOIN
count_project_impact() ON project.id = count_project_impact.project
LEFT JOIN
count_project_output() ON project.id = count_project_output.project
LEFT JOIN
project_status() ON project.id=project_status.project
WHERE
project_for_organisation.organisation IN (
SELECT list_child_organisations.organisation_id FROM list_child_organisations(organisation_id)
Expand Down Expand Up @@ -86,7 +90,8 @@ CREATE FUNCTION projects_by_organisation_search(
research_domain VARCHAR[],
participating_organisations VARCHAR[],
impact_cnt INTEGER,
output_cnt INTEGER
output_cnt INTEGER,
project_status VARCHAR(20)
) LANGUAGE sql STABLE AS
$$
SELECT DISTINCT ON (project.id)
Expand All @@ -106,7 +111,8 @@ SELECT DISTINCT ON (project.id)
research_domain_filter_for_project.research_domain,
project_participating_organisations.organisations AS participating_organisations,
COALESCE(count_project_impact.impact_cnt, 0) AS impact_cnt,
COALESCE(count_project_output.output_cnt, 0) AS output_cnt
COALESCE(count_project_output.output_cnt, 0) AS output_cnt,
project_status.status
FROM
project
LEFT JOIN
Expand All @@ -121,6 +127,8 @@ LEFT JOIN
count_project_impact() ON project.id = count_project_impact.project
LEFT JOIN
count_project_output() ON project.id = count_project_output.project
LEFT JOIN
project_status() ON project.id=project_status.project
WHERE
project_for_organisation.organisation IN (
SELECT list_child_organisations.organisation_id FROM list_child_organisations(organisation_id)
Expand Down
8 changes: 5 additions & 3 deletions frontend/__tests__/ProjectsOverviewPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ const mockProps = {
keywords: null,
domains: null,
organisations: null,
project_status: null,
page: 1,
rows: 12,
count: 408,
layout: 'masonry' as LayoutType,
keywordsList: mockData.keywordsList,
domainsList: mockData.domainsList,
organisationsList: mockData.organisationsList,
projectStatusList: mockData.projectStatusList as any,
projects: mockData.projects as any
}

Expand All @@ -48,7 +50,7 @@ describe('pages/projects/index.tsx', () => {
expect(heading).toBeInTheDocument()
})

it('renders project filter panel with orderBy and 3 filters (combobox)', () => {
it('renders project filter panel with orderBy and 4 filters (combobox)', () => {
render(
<WithAppContext>
<ProjectOverviewPage {...mockProps} />
Expand All @@ -58,9 +60,9 @@ describe('pages/projects/index.tsx', () => {
const panel = screen.getByTestId('filters-panel')
// find order by testid
const order = within(panel).getByTestId('filters-order-by')
// should have 3 filters
// should have 4 filters
const filters = within(panel).getAllByRole('combobox')
expect(filters.length).toEqual(3)
expect(filters.length).toEqual(4)
// screen.debug(filters)
})

Expand Down
18 changes: 18 additions & 0 deletions frontend/__tests__/__mocks__/projectsOverview.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@
"keyword_cnt": 31
}
],
"projectStatusList":[
{
"project_status": "finished",
"project_status_cnt": 107
},
{
"project_status": "in_progress",
"project_status_cnt": 123
},
{
"project_status": "pending",
"project_status_cnt": 120
},
{
"project_status": "unknown",
"project_status_cnt": 54
}
],
"domainsList":[
{
"key": "LS1_1",
Expand Down
12 changes: 7 additions & 5 deletions frontend/components/charts/progress/PeriodProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ type PeriodProgressBar = {

export default function PeriodProgressBar({date_start,date_end,className, height='0.5rem'}:PeriodProgressBar) {

const progress = getProgressValue({
date_start,
date_end
})
// if one of date values is missing we do not show progressbar
if (date_start === null || date_end === null) return null

function getProgressValue({date_start, date_end}: PeriodProgressBar) {

if (date_start === null || date_end === null) return 0

const start_date = new Date(date_start)
Expand All @@ -42,6 +39,11 @@ export default function PeriodProgressBar({date_start,date_end,className, height
return Math.floor(progress)
}

const progress = getProgressValue({
date_start,
date_end
})

return (
<div
title={`${progress}%`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
// SPDX-License-Identifier: Apache-2.0

import {ProjectStatusKey} from '~/types/Project'
import {getImageUrl} from '~/utils/editImage'
import KeywordList from '~/components/cards/KeywordList'
import CardTitleSubtitle from '~/components/cards/CardTitleSubtitle'
Expand Down Expand Up @@ -33,6 +34,7 @@ type ProjectCardProps = {
impact_cnt: number | null
output_cnt: number | null
visibleKeywords?: number
project_status: ProjectStatusKey
}

export default function ProjectCardContent(item:ProjectCardProps){
Expand Down Expand Up @@ -72,6 +74,7 @@ export default function ProjectCardContent(item:ProjectCardProps){
<ProjectPeriod
date_start={item.date_start}
date_end={item.date_end}
project_status={item.project_status}
/>
</div>
{/* Metrics */}
Expand Down
19 changes: 17 additions & 2 deletions frontend/components/projects/overview/cards/ProjectPeriod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@

import PeriodProgressBar from '~/components/charts/progress/PeriodProgressBar'
import ProjectDuration from './ProjectDuration'
import {ProjectStatusKey} from '~/types/Project'

type ProjectPeriodProps = {
date_start: string | null
date_end: string | null
project_status: ProjectStatusKey
}

export default function ProjectPeriod({date_start,date_end}:ProjectPeriodProps) {
if (!date_start || !date_end) return null
export default function ProjectPeriod({date_start, date_end, project_status}: ProjectPeriodProps) {
// if status unknown we do not show project period
if (project_status==='unknown') return null

// when project is finished we only show dates
// if (project_status === 'finished') {
// return (
// <ProjectDuration
// date_start={date_start}
// date_end={date_end}
// />
// )
// }

// show both dates and progressbar
return (
<>
<ProjectDuration
Expand Down
Loading

0 comments on commit d5c0fef

Please sign in to comment.