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

Added tagged passage and story count display to Passage and Story Tags Dialogs #1498

Closed
wants to merge 1 commit into from

Conversation

sihambyte
Copy link
Contributor

Description

  • Added a function to count tag frequencies across passages.
  • Added a function to count tag frequencies across stories.
  • Added unit tests for passage and story tag frequency functions.
  • Updated UI to display tag frequencies with correct pluralization in dialogs.
  • Added a unit test to verify tag frequencies display.
  • Implemented tests for story and passage tags dialogs to confirm tag-editor accurately renders with appropriate tag frequencies.

Issues Fixed

#1391

Credit

[x] We would like to be credited in the application as Siham Argaw and Ngoc Nguyen.

Presubmission Checklist

[X] We have read this project's CONTRIBUTING file and this PR follows the criteria laid out there.
[X] This contribution was created by us and we have the right to submit it under the GPL v3 license. (This is not a rights assignment.)
[X] We have read and agree to abide by this project's Code of Conduct.

* display passageTag and storyTag frequencies
Co-authored-by: sihambyte <[email protected]>
@sihambyte sihambyte requested a review from klembot as a code owner February 22, 2024 06:27
Copy link
Owner

@klembot klembot left a comment

Choose a reason for hiding this comment

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

Overall, approach looks good--noticed some things that should get addressed, however.

@@ -9,5 +9,6 @@ export const TagEditor: React.FC<TagEditorProps> = props => (
<button onClick={() => props.onChangeName('mock-new-name')}>
onChangeName
</button>
<span>{`${props.count} ${props.count > 1 ? 'passages' : 'passage'}`}</span>
Copy link
Owner

Choose a reason for hiding this comment

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

Since this is a mock, let's just do

<span data-testid="count">{props.count}</span>

@@ -52,6 +53,7 @@ export const TagEditor: React.FC<TagEditorProps> = props => {
>
{t('common.color')}
</TextSelect>
<span className="tag-count">{`${count} ${count > 1 ? 'passages' : 'passage'}`}</span>
Copy link
Owner

Choose a reason for hiding this comment

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

This text needs to be localized instead of hardcoding English. Take a look at StoryListRoute to see an example of how it handles plurals in the title. Putting just an English translation of the text in this PR is fine; I notify translators before a release so they can update the text.

I'd suggest using the key components.tagEditor.passageCount for this.

Tests will need to be updated too--we don't need to test that the localization works correctly, just that the right keys are displayed.

@@ -24,7 +25,7 @@ export const PassageTagsDialog: React.FC<PassageTagsDialogProps> = props => {

const story = storyWithId(stories, storyId);
const tags = storyPassageTags(story);

const tagCountsInStory = passageTagFrequencies(story);
Copy link
Owner

Choose a reason for hiding this comment

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

This should be memoized for performance reasons.

@@ -17,6 +17,7 @@ export const StoryTagsDialog: React.FC<StoryTagsDialogProps> = props => {
const {t} = useTranslation();

const tags = storyTags(stories);
const tagCountsInStories = storyTagFrequencies(stories);
Copy link
Owner

Choose a reason for hiding this comment

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

This also should be memoized.

Comment on lines +162 to +177
export function passageTagFrequencies(story: Story) {
const tagPassageCounts: { [key: string]: number } = {};

story.passages.forEach(passage => {
if (passage.tags) {
passage.tags.forEach(tag=>{
if (!tagPassageCounts[tag]) {
tagPassageCounts[tag] = 1;
} else {
tagPassageCounts[tag] += 1;
}
})};
});
return tagPassageCounts;
}

Copy link
Owner

Choose a reason for hiding this comment

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

More idiomatically (and to parallel the name with storyPassageTags above it):

export function storyPassageTagFrequencies(story: Story) {
	const counts: Record<string, number> = {};

	for (const passage of story.passages) {
		for (const tag of passage.tags) {
			counts[tag] = (counts[tag] ?? 0) + 1;
		}
	}

	return counts;
}

I'm not sure why you do a check on passage.tags not being defined--it should always be, but did you find that wasn't the case in practice?

@@ -196,6 +212,20 @@ export function storyTags(stories: Story[]) {
).sort();
}

export function storyTagFrequencies(stories: Story[]) {
Copy link
Owner

Choose a reason for hiding this comment

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

Same suggestion as with passageTagFrequencies.

@klembot
Copy link
Owner

klembot commented Apr 12, 2024

It's been a while since this PR has seen any activity, so I'm going to close. Feel free to re-open, but bear in mind the suggestions I made on this.

@klembot klembot closed this Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants