Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add article count copy editor field #547

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/EpicTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object SeparateArticleCountType extends Enum[SeparateArticleCountType] with Circ

case class SeparateArticleCount(
`type`: SeparateArticleCountType,
copy: Option[String]
)

case class EpicVariant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React from 'react';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Checkbox from '@material-ui/core/Checkbox';
import { SeparateArticleCount } from '../../models/epic';
import { TextField } from '@material-ui/core';
import { useForm } from 'react-hook-form';

interface FormData {
copy: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you clear the contents of this field does the tool submit an empty string (rather than null) to the database? I'm wondering what then happens in the epic

Copy link
Contributor Author

@andrewHEguardian andrewHEguardian Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, yes it does. But the epic logic checks that it contains "%%ARTICLE_COUNT%%" anyway, though arguably we shouldn't rely on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Perhaps it's worth being defensive and transforming '' to undefined in this component?

}

interface VariantEditorSeparateArticleCountEditorProps {
separateArticleCount?: SeparateArticleCount;
Expand All @@ -18,6 +24,20 @@ const VariantEditorSeparateArticleCountEditor: React.FC<VariantEditorSeparateArt
updateSeparateArticleCount(Boolean(separateArticleCount) ? undefined : { type: 'above' });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way this worked before means that the copy will be lost if "Above" is set to false, which I guess is fine?

};

const defaultValues: FormData = {
copy: separateArticleCount?.copy ?? '',
};

const { register, handleSubmit, errors } = useForm<FormData>({ mode: 'onChange', defaultValues });

const onSubmit = ({ copy }: FormData): void => {
updateSeparateArticleCount(
separateArticleCount
? { ...separateArticleCount, copy: copy === '' ? undefined : copy }
: undefined,
);
};

return (
<div>
<FormControlLabel
Expand All @@ -31,6 +51,18 @@ const VariantEditorSeparateArticleCountEditor: React.FC<VariantEditorSeparateArt
}
label="Above"
/>
<TextField
inputRef={register()}
error={errors.copy !== undefined}
helperText={errors.copy?.message}
onBlur={handleSubmit(onSubmit)}
name="copy"
label="Article count copy"
margin="normal"
variant="outlined"
disabled={isDisabled || !Boolean(separateArticleCount)}
fullWidth
/>
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions public/src/models/epic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ControlProportionSettings } from '../components/channelManagement/helpe

export interface SeparateArticleCount {
type: 'above';
copy?: string;
}

export interface EpicVariant extends Variant {
Expand Down