Skip to content

Commit

Permalink
Merge pull request #8923 from CitizenLabDotCo/master
Browse files Browse the repository at this point in the history
Release 2024-08-19
  • Loading branch information
EdwinKato authored Sep 19, 2024
2 parents c3895c2 + f539b55 commit b80af23
Show file tree
Hide file tree
Showing 37 changed files with 271 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ReportBuilder
class Queries::Projects < ReportBuilder::Queries::Base
def run_query(start_at: nil, end_at: nil, **_other_props)
def run_query(start_at: nil, end_at: nil, publication_statuses: [], **_other_props)
# publication_statuses = %w[published archived] # TODO: remove this debug line
start_date, end_date = TimeBoundariesParser.new(start_at, end_at).parse

overlapping_project_ids = Phase
Expand All @@ -10,7 +11,7 @@ def run_query(start_at: nil, end_at: nil, **_other_props)
overlapping_projects = Project
.joins(:admin_publication)
.where(id: overlapping_project_ids)
.where(admin_publication: { publication_status: 'published' })
.where(admin_publication: { publication_status: publication_statuses })

periods = Phase
.select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
describe '#run_query' do
before_all do
# 2020
past_project = create(:project)
@past_project = create(:project)
create(
:phase,
project: past_project,
project: @past_project,
start_at: Date.new(2020, 2, 1),
end_at: Date.new(2020, 3, 1),
with_permissions: true
Expand All @@ -29,11 +29,16 @@
@project3 = create(:project)
create(:phase, project: @project3, start_at: Date.new(2022, 2, 1), end_at: nil)

# Project not published (should be filtered out)
# Draft project
project4 = create(:project)
project4.admin_publication.update!(publication_status: 'draft')
create(:phase, project: project4, start_at: Date.new(2022, 2, 1), end_at: nil)

# Archived project
@project5 = create(:project)
@project5.admin_publication.update!(publication_status: 'archived')
create(:phase, project: @project5, start_at: Date.new(2022, 2, 1), end_at: nil)

# Empty project
create(:project)

Expand All @@ -45,7 +50,12 @@
end

it 'returns overlapping projects' do
result = query.run_query(start_at: Date.new(2021, 1, 1), end_at: Date.new(2021, 4, 1))
result = query.run_query(
start_at: Date.new(2021, 1, 1),
end_at: Date.new(2021, 4, 1),
publication_statuses: %w[published]
)

expect(result[:projects].count).to eq(2)

expect(
Expand All @@ -54,7 +64,12 @@
end

it 'returns overlapping projects when last phase has no end date' do
result = query.run_query(start_at: Date.new(2022, 1, 1), end_at: Date.new(2022, 4, 1))
result = query.run_query(
start_at: Date.new(2022, 1, 1),
end_at: Date.new(2022, 4, 1),
publication_statuses: %w[published]
)

expect(result[:projects].count).to eq(2)

expect(
Expand All @@ -63,12 +78,22 @@
end

it 'returns project images' do
result = query.run_query(start_at: Date.new(2021, 1, 1), end_at: Date.new(2021, 4, 1))
result = query.run_query(
start_at: Date.new(2021, 1, 1),
end_at: Date.new(2021, 4, 1),
publication_statuses: %w[published]
)

expect(result[:project_images].count).to eq(1)
end

it 'returns correct project periods' do
result = query.run_query(start_at: Date.new(2021, 1, 1), end_at: Date.new(2021, 4, 1))
result = query.run_query(
start_at: Date.new(2021, 1, 1),
end_at: Date.new(2021, 4, 1),
publication_statuses: %w[published]
)

expect(result[:periods].count).to eq(2)
expect(result[:periods][@project1.id]).to eq({
'start_at' => Date.new(2021, 2, 1),
Expand All @@ -79,5 +104,41 @@
'end_at' => nil
})
end

context 'when specific publication statuses are requested' do
it 'returns only published projects when only published is requested' do
result = query.run_query(
start_at: nil,
end_at: nil,
publication_statuses: %w[published]
)

expect(result[:projects].count).to eq(4)
expect(result[:projects].pluck(:id)).to match_array [@project1.id, @project2.id, @project3.id, @past_project.id]
end

it 'returns only archived projects when only archived is requested' do
result = query.run_query(
start_at: nil,
end_at: nil,
publication_statuses: %w[archived]
)

expect(result[:projects].count).to eq(1)
expect(result[:projects].first[:id]).to eq(@project5.id)
end

it 'returns expected projects when two publication_statuses are requested' do
result = query.run_query(
start_at: nil,
end_at: nil,
publication_statuses: %w[published archived]
)

expect(result[:projects].count).to eq(5)
expect(result[:projects].pluck(:id))
.to match_array [@project1.id, @project2.id, @project3.id, @project5.id, @past_project.id]
end
end
end
end
2 changes: 1 addition & 1 deletion back/engines/free/email_campaigns/config/locales/nb-NO.yml
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@
content_type:
comments: 'Kommentarer'
content_moderation: 'Moderering av innhold'
events: 'arrangementer'
events: 'Arrangementer'
general: 'Generell'
inputs: 'Innganger'
internal_comments: 'Interne kommentarer'
Expand Down
4 changes: 3 additions & 1 deletion front/app/api/graph_data_units/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ export const useParticipationLive = (
);
};

export const useProjects = (props: ProjectsProps = {}) => {
export const useProjects = (
props: ProjectsProps = { publication_statuses: 'published' }
) => {
return useGraphDataUnits<ProjectsResponse>({
resolved_name: 'ProjectsWidget',
props,
Expand Down
6 changes: 5 additions & 1 deletion front/app/api/graph_data_units/requestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ interface ParticipationParams extends BaseParams {
props: ParticipationProps;
}

export interface ProjectsProps extends DateProps {}
export type ProjectReportsPublicationStatus = 'published' | 'archived';

export interface ProjectsProps extends DateProps {
publication_statuses: ProjectReportsPublicationStatus;
}

interface ProjectsParams extends BaseParams {
resolved_name: 'ProjectsWidget';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Element } from '@craftjs/core';
import { FormatMessage } from 'typings';

import { useProjects } from 'api/graph_data_units';
import { ProjectReportsPublicationStatus } from 'api/graph_data_units/requestTypes';
import useUserCustomFields from 'api/user_custom_fields/useUserCustomFields';

import useAppConfigurationLocales from 'hooks/useAppConfigurationLocales';
Expand Down Expand Up @@ -42,9 +43,14 @@ import { getCommunity, getComparedDateRange, getProjects } from './utils';
interface Props {
startDate: string;
endDate: string;
publicationStatus?: ProjectReportsPublicationStatus;
}

const PlatformTemplateContent = ({ startDate, endDate }: Props) => {
const PlatformTemplateContent = ({
startDate,
endDate,
publicationStatus = 'published',
}: Props) => {
const dateRange = {
startAt: startDate,
endAt: endDate,
Expand All @@ -70,6 +76,7 @@ const PlatformTemplateContent = ({ startDate, endDate }: Props) => {
const { data: projects } = useProjects({
start_at: startDate,
end_at: endDate,
publication_statuses: publicationStatus,
});

if (!appConfigurationLocales || !userFields || !stats || !projects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import { Props } from '../typings';

import ProjectRow from './ProjectRow';

const ProjectsCard = ({ startAt, endAt }: Props) => {
const { data: response } = useProjects({ start_at: startAt, end_at: endAt });
const ProjectsCard = ({
startAt,
endAt,
publicationStatus = 'published',
}: Props) => {
const { data: response } = useProjects({
start_at: startAt,
end_at: endAt,
publication_statuses: publicationStatus,
});
if (!response) return null;

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
import React from 'react';

import { Box } from '@citizenlab/cl2-component-library';
import { Box, Select, Text } from '@citizenlab/cl2-component-library';
import { useNode } from '@craftjs/core';
import { IOption } from 'typings';

import { useIntl } from 'utils/cl-intl';

import {
TitleInput,
DateRangeInput,
} from '../ChartWidgets/_shared/ChartWidgetSettings';

import messages from './messages';
import { Props } from './typings';

const Settings = () => {
const { formatMessage } = useIntl();

const {
actions: { setProp },
publicationStatus,
} = useNode((node) => ({
publicationStatus: node.data.props.publicationStatus || 'published',
}));

const handleStatusChange = (option: IOption) => {
setProp((props: Props) => {
props.publicationStatus = option.value;
});
};

const options = [
{ value: 'published', label: formatMessage(messages.published) },
{ value: 'archived', label: formatMessage(messages.archived) },
];

return (
<Box>
<TitleInput />
<Box mb="20px">
<Text variant="bodyM" color="textSecondary" mb="5px">
{formatMessage(messages.publicationStatus)}
</Text>
<Select
options={options}
onChange={handleStatusChange}
value={publicationStatus}
/>
</Box>
<DateRangeInput />
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ ProjectsWidget.craft = {
title: {},
startAt: undefined,
endAt: undefined,
publicationStatus: undefined,
},
related: {
settings: Settings,
},
};

export const projectsTitle = messages.publishedProjects;
export const projectsTitle = messages.projects;

export default ProjectsWidget;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineMessages } from 'react-intl';

export default defineMessages({
publishedProjects: {
id: 'app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publishedProjects',
defaultMessage: 'Published projects',
projects: {
id: 'app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.projects',
defaultMessage: 'Projects',
},
finished: {
id: 'app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.finished',
Expand All @@ -21,4 +21,16 @@ export default defineMessages({
id: 'app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.planned',
defaultMessage: 'Planned',
},
archived: {
id: 'app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.archived',
defaultMessage: 'Archived',
},
published: {
id: 'app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.published',
defaultMessage: 'Published',
},
publicationStatus: {
id: 'app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publicationStatus',
defaultMessage: 'Publication status',
},
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Multiloc } from 'typings';

import { ProjectReportsPublicationStatus } from 'api/graph_data_units/requestTypes';

export interface Props {
title?: Multiloc;
startAt?: string;
endAt?: string | null;
publicationStatus?: ProjectReportsPublicationStatus;
}
5 changes: 4 additions & 1 deletion front/app/translations/admin/ach-UG.json
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,13 @@
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ChartWidgets.UsersWidget.users": "crwdns2212582:0{numberOfUsers}crwdnd2212582:0{percentageOfUsers}crwdne2212582:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ImageMultiloc.Settings.stretch": "crwdns2201674:0crwdne2201674:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.active": "crwdns2467856:0crwdne2467856:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.archived": "crwdns3094681:0crwdne3094681:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.finished": "crwdns2467858:0crwdne2467858:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.openEnded": "crwdns2504046:0crwdne2504046:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.planned": "crwdns2467860:0crwdne2467860:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publishedProjects": "crwdns2467862:0crwdne2467862:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.projects": "crwdns3094683:0crwdne3094683:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publicationStatus": "crwdns3094685:0crwdne3094685:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.published": "crwdns3094687:0crwdne3094687:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets._shared.missingData": "crwdns1963248:0crwdne1963248:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.noAppropriatePhases": "crwdns1603844:0crwdne1603844:0",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.noPhaseSelected": "crwdns1603846:0crwdne1603846:0",
Expand Down
5 changes: 4 additions & 1 deletion front/app/translations/admin/ar-SA.json
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,13 @@
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ChartWidgets.UsersWidget.users": "المستخدمون: {numberOfUsers} ({percentageOfUsers}%)",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ImageMultiloc.Settings.stretch": "تمتد",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.active": "نشيط",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.archived": "مؤرشفة",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.finished": "انتهى",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.openEnded": "مفتوحة",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.planned": "المخطط لها",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publishedProjects": "المشاريع المنشورة",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.projects": "المشاريع",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publicationStatus": "حالة النشر",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.published": "نُشرت",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets._shared.missingData": "البيانات الخاصة بهذه القطعة مفقودة. أعد تكوينه أو احذفه لتتمكن من حفظ التقرير.",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.noAppropriatePhases": "لم يتم العثور على مراحل مناسبة في هذا المشروع",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.noPhaseSelected": "لم يتم تحديد أي مرحلة. الرجاء تحديد المرحلة أولا.",
Expand Down
5 changes: 4 additions & 1 deletion front/app/translations/admin/cy-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,13 @@
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ChartWidgets.UsersWidget.users": "Users: {numberOfUsers} ({percentageOfUsers}%)",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ImageMultiloc.Settings.stretch": "Ymestyn",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.active": "Actif",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.archived": "Wedi'i archifo",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.finished": "Wedi gorffen",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.openEnded": "Penagored",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.planned": "Wedi'i gynllunio",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publishedProjects": "Prosiectau cyhoeddedig",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.projects": "Prosiectau",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publicationStatus": "Statws cyhoeddi",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.published": "Cyhoeddwyd",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets._shared.missingData": "Mae'r data ar gyfer y teclyn hwn ar goll. Ail-ffurfweddwch neu dilëwch ef i allu cadw'r adroddiad.",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.noAppropriatePhases": "Ni chanfuwyd unrhyw gamau priodol yn y prosiect hwn",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.noPhaseSelected": "Dim cam wedi'i ddewis. Dewiswch gam yn gyntaf.",
Expand Down
5 changes: 4 additions & 1 deletion front/app/translations/admin/da-DK.json
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,13 @@
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ChartWidgets.UsersWidget.users": "Brugere: {numberOfUsers} ({percentageOfUsers}%)",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ImageMultiloc.Settings.stretch": "Stræk",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.active": "Aktiv",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.archived": "Arkiveret",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.finished": "Afsluttet",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.openEnded": "Åbne spørgsmål",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.planned": "Planlagt",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publishedProjects": "Offentliggjorte projekter",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.projects": "Projekter",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.publicationStatus": "Status for offentliggørelse",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.ProjectsWidget.published": "Offentliggjort",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets._shared.missingData": "Dataene for denne widget mangler. Rekonfigurer eller slet den for at kunne gemme rapporten.",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.noAppropriatePhases": "Ingen passende faser fundet i dette projekt",
"app.containers.Admin.reporting.components.ReportBuilder.Widgets.noPhaseSelected": "Ingen fase valgt. Vælg venligst en fase først.",
Expand Down
Loading

0 comments on commit b80af23

Please sign in to comment.