Skip to content

Commit

Permalink
Merge pull request #9257 from CitizenLabDotCo/master
Browse files Browse the repository at this point in the history
 Release 2024-10-31
  • Loading branch information
EdwinKato authored Oct 31, 2024
2 parents 8b532ab + 9e887d0 commit 55358f9
Show file tree
Hide file tree
Showing 96 changed files with 135 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def update_fields!(page_temp_ids_to_ids_mapping, option_temp_ids_to_ids_mapping,
options_params = field_params.delete :options
if field_params[:id] && fields_by_id.key?(field_params[:id])
field = fields_by_id[field_params[:id]]
next unless update_field! field, field_params, errors, index
next unless update_field!(field, field_params, errors, index)
else
field = create_field! field_params, errors, page_temp_ids_to_ids_mapping, index
next unless field
Expand Down Expand Up @@ -164,6 +164,8 @@ def update_field!(field, field_params, errors, index)
field_params = idea_custom_field_service.remove_ignored_update_params field_params
if field.errors.errors.empty?
field.assign_attributes field_params
return true unless field.changed?

SideFxCustomFieldService.new.before_update field, current_user
if field.save
SideFxCustomFieldService.new.after_update field, current_user
Expand Down Expand Up @@ -248,6 +250,7 @@ def update_option_image!(option, image_id)
def update_option!(option, option_params, errors, field_index, option_index)
update_params = option_params.except('image_id')
option.assign_attributes update_params
return true unless option.changed?

SideFxCustomFieldOptionService.new.before_update option, current_user
if option.save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3160,6 +3160,31 @@
assert_status 200
end

example 'Updating fields only logs activities when they have changed' do
page = create(:custom_field_page, resource: custom_form)
field1 = create(:custom_field, resource: custom_form, title_multiloc: { 'en' => 'Field 1' })
field2 = create(:custom_field, resource: custom_form, title_multiloc: { 'en' => 'Field 2' })
request = {
custom_fields: [
{
id: page.id,
input_type: 'page',
page_layout: 'default'
},
{
id: field1.id,
title_multiloc: { 'en' => 'Field 1' }
},
{
id: field2.id,
title_multiloc: { 'en' => 'Field 2 changed' }
}
]
}

expect { do_request(request) }.to enqueue_job(LogActivityJob).exactly(1).times
end

context "Update custom field's map config relation" do
let!(:map_config1) { create(:map_config, mappable: nil) }
let!(:map_config2) { create(:map_config, mappable: nil) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module MultiTenancy
module Templates
module Serializers
class NavBarItem < Base
ref_attribute :static_page
ref_attributes %i[static_page project]
attributes %i[code ordering title_multiloc]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module EmailCampaigns
module Disableable
extend ActiveSupport::Concern

# NOTE: This concern is now applied to all campaigns
# but is left here so that future campaigns have the ability to not be disabled

# If one instance is enabled, we consider the campaign_type enabled. This
# returns all campaign_types that are not all disabled
def self.enabled_campaign_types(instances)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module EmailCampaigns
class Campaigns::CommentOnIdeaYouFollow < Campaign
include Consentable
include Disableable
include ActivityTriggerable
include RecipientConfigurable
include LifecycleStageRestrictable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module EmailCampaigns
class Campaigns::CommentOnInitiativeYouFollow < Campaign
include Consentable
include Disableable
include ActivityTriggerable
include RecipientConfigurable
include LifecycleStageRestrictable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module EmailCampaigns
class Campaigns::OfficialFeedbackOnIdeaYouFollow < Campaign
include Consentable
include Disableable
include ActivityTriggerable
include RecipientConfigurable
include Trackable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module EmailCampaigns
class Campaigns::OfficialFeedbackOnInitiativeYouFollow < Campaign
include Consentable
include Disableable
include ActivityTriggerable
include RecipientConfigurable
include Trackable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module EmailCampaigns
class Campaigns::ProjectPublished < Campaign
include Consentable
include Disableable
include ActivityTriggerable
include RecipientConfigurable
include Trackable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module EmailCampaigns
class Campaigns::StatusChangeOnIdeaYouFollow < Campaign
include Consentable
include Disableable
include ActivityTriggerable
include RecipientConfigurable
include Trackable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module EmailCampaigns
class Campaigns::StatusChangeOnInitiativeYouFollow < Campaign
include Consentable
include Disableable
include ActivityTriggerable
include RecipientConfigurable
include Trackable
Expand Down
16 changes: 5 additions & 11 deletions front/app/component-library/utils/styleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ type StylingConstsType = {
// Reusable text styling
export function quillEditedContent(
buttonColor = colors.teal,
linkColor = colors.teal,
textColor = colors.textPrimary,
mentionColor = colors.textPrimary,
fontSize: 's' | 'base' | 'm' | 'l' = 'base',
Expand All @@ -295,7 +294,7 @@ export function quillEditedContent(
return `
${defaultFontStyle}
a, li, p {
li, p {
${defaultFontStyle}
}
Expand All @@ -315,7 +314,7 @@ export function quillEditedContent(
a {
font-size: inherit;
font-weight: inherit;
text-decoration: inherit;
text-decoration: underline;
}
}
Expand All @@ -329,7 +328,7 @@ export function quillEditedContent(
a {
font-size: inherit;
font-weight: inherit;
text-decoration: inherit;
text-decoration: underline;
}
}
Expand All @@ -342,20 +341,15 @@ export function quillEditedContent(
}
a {
color: ${linkColor};
color: #0000EE; /* Standard fallback for all browsers */
color: -webkit-link; /* Overrides the fallback in WebKit browsers */
text-decoration: underline;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
word-break: break-word;
hyphens: auto;
transition: background 80ms ease-out;
&:hover {
color: ${darken(0.15, linkColor)};
background: ${transparentize(0.91, linkColor)};
text-decoration: underline;
}
}
ul, ol {
Expand Down
5 changes: 5 additions & 0 deletions front/app/components/T/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { createElement } from 'react';

import { trim } from 'lodash-es';
import { Multiloc } from 'typings';

import useAppConfigurationLocales from 'hooks/useAppConfigurationLocales';
Expand Down Expand Up @@ -54,6 +55,10 @@ const T = (props: Props) => {
fallback
);

if (trim(localizedText) === '') {
return null;
}

if (children) {
return children(localizedText);
}
Expand Down
5 changes: 0 additions & 5 deletions front/app/components/UI/QuillEditedContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { quillEditedContent } from '@citizenlab/cl2-component-library';
import styled, { useTheme } from 'styled-components';

const Container = styled.div<{
linkColor: Props['linkColor'];
textColor: Props['textColor'];
mentionColor: Props['mentionColor'];
fontSize: Props['fontSize'];
Expand All @@ -13,7 +12,6 @@ const Container = styled.div<{
${(props) =>
quillEditedContent(
props.theme.colors.tenantPrimary,
props.linkColor,
props.textColor,
props.mentionColor,
props.fontSize,
Expand All @@ -23,7 +21,6 @@ const Container = styled.div<{

interface Props {
disableTabbing?: boolean;
linkColor?: string;
textColor?: string;
mentionColor?: string;
fontSize?: 's' | 'base' | 'm' | 'l';
Expand All @@ -33,7 +30,6 @@ interface Props {
}

const QuillEditedContent = ({
linkColor,
textColor,
mentionColor,
fontSize,
Expand All @@ -59,7 +55,6 @@ const QuillEditedContent = ({

return (
<Container
linkColor={linkColor}
textColor={textColor}
mentionColor={mentionColor || theme.colors.tenantText}
fontSize={fontSize}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { transparentize } from 'polished';
import { DayPicker, PropsBase } from 'react-day-picker';
import styled from 'styled-components';

import useAppConfiguration from 'api/app_configuration/useAppConfiguration';

import useLocale from 'hooks/useLocale';

import { getLocale } from '../../_shared/locales';
Expand Down Expand Up @@ -144,6 +146,9 @@ const Calendar = ({
defaultMonth,
onUpdateRange,
}: Props) => {
const { data: appConfiguration } = useAppConfiguration();
const tenantTimezone =
appConfiguration?.data.attributes.settings.core.timezone;
const startMonth = getStartMonth({
startMonth: _startMonth,
selectedRange,
Expand Down Expand Up @@ -188,11 +193,7 @@ const Calendar = ({
clickedDate: day,
});

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (updatedRange) {
onUpdateRange(updatedRange);
}
onUpdateRange(updatedRange);
};

return (
Expand All @@ -213,6 +214,7 @@ const Calendar = ({
// range rather than being controlled by our state.
selected={[] as any}
onSelect={NOOP}
timeZone={tenantTimezone}
/>
</DayPickerStyles>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const getStartMonth = ({
}: GetStartMonthProps) => {
if (startMonth) return startMonth;

const times: number[] = [addYears(new Date(), -2).getTime()];
const times: number[] = [addYears(new Date(), -10).getTime()];

if (selectedRange.from) {
times.push(addYears(selectedRange.from, -2).getTime());
times.push(addYears(selectedRange.from, -10).getTime());
}

if (disabledRanges.length > 0) {
Expand Down Expand Up @@ -49,10 +49,10 @@ export const getEndMonth = ({
}: GetEndMonthProps) => {
if (endMonth) return endMonth;

const times: number[] = [addYears(new Date(), 2).getTime()];
const times: number[] = [addYears(new Date(), 10).getTime()];

if (selectedRange.to) {
times.push(addYears(selectedRange.to, 2).getTime());
times.push(addYears(selectedRange.to, 10).getTime());
}

if (disabledRanges.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getUpdatedRange = ({
selectedRange: { from, to },
disabledRanges,
clickedDate,
}: GetUpdatedRangeParams) => {
}: GetUpdatedRangeParams): Partial<DateRange> => {
const { valid, reason } = rangesValid({ from, to }, disabledRanges);

if (!valid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export interface Props {
startMonth?: Date;
endMonth?: Date;
defaultMonth?: Date;
onUpdateRange: (range: DateRange) => void;
onUpdateRange: (range: Partial<DateRange>) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useLocale from 'hooks/useLocale';
import { getLocale } from '../../_shared/locales';
import { CalendarProps } from '../typings';

import { getEndMonth, getStartMonth } from './utils/getStartEndMonth';
import { getEndMonth } from './utils/getStartEndMonth';

const DayPickerStyles = styled.div`
.rdp-root {
Expand All @@ -34,8 +34,7 @@ const Calendar = ({
onChange,
}: CalendarProps) => {
const locale = useLocale();

const startMonth = getStartMonth({ startMonth: _startMonth, selectedDate });
const startMonth = new Date(1900, 0);
const endMonth = getEndMonth({ endMonth: _endMonth, selectedDate });

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
import { addYears } from 'date-fns';

interface GetStartMonthProps {
startMonth?: Date;
selectedDate?: Date;
}

export const getStartMonth = ({
startMonth,
selectedDate,
}: GetStartMonthProps) => {
if (startMonth) return startMonth;
const twoYearsAgo = addYears(new Date(), -2);

if (selectedDate) {
return new Date(
Math.min(addYears(selectedDate, -2).getTime(), twoYearsAgo.getTime())
);
}

return twoYearsAgo;
};

interface GetEndMonthProps {
endMonth?: Date;
selectedDate?: Date;
}

export const getEndMonth = ({ endMonth, selectedDate }: GetEndMonthProps) => {
if (endMonth) return endMonth;
const twoYearsFromNow = addYears(new Date(), 2);
const tenYearsFromNow = addYears(new Date(), 10);

if (selectedDate) {
return new Date(
Math.max(addYears(selectedDate, 2).getTime(), twoYearsFromNow.getTime())
Math.max(addYears(selectedDate, 10).getTime(), tenYearsFromNow.getTime())
);
}

return twoYearsFromNow;
return tenYearsFromNow;
};
Loading

0 comments on commit 55358f9

Please sign in to comment.