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

Clean up routing behaviour in ngram component #1727

Merged
merged 12 commits into from
Dec 23, 2024

Conversation

BeritJanssen
Copy link
Contributor

@BeritJanssen BeritJanssen commented Dec 12, 2024

Close #1268. As discussed IRL, I decided to focus on the problems involved in managing routing parameters connected to the ngram component, and this fixes the multiple fetching. My personal preference is to keep the concerns for parameter changes and requests separated, i.e., not to combine them both in one model. But extending StoreSync and using its methods works like a charm! 🤩

import { BooleanFilter, DateFilter, DateFilterData, MultipleChoiceFilter } from './field-filter';
import { of } from 'rxjs';
import { distinct } from 'rxjs/operators';
import { SimpleStore } from '../store/simple-store';
import { Store } from '../store/types';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change removes some unused imports, which I noticed when I was looking at other examples for testing routing behaviour.

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 only test in this spec was the one related to the ngram related models and types.

component.onParameterChange('size', 2);
expect(component.stopPolling$.next).not.toHaveBeenCalled();
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On initialization, all values in the template will be adjusted to the values reflected in the routing parameters, which will trigger the onParameterChange method, hence the extra if condition in there to see if the parameter has actually changed.

@BeritJanssen BeritJanssen marked this pull request as draft December 12, 2024 09:06
@BeritJanssen BeritJanssen marked this pull request as ready for review December 12, 2024 09:49
Copy link
Contributor

@lukavdplas lukavdplas left a comment

Choose a reason for hiding this comment

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

Looks good!

I wasn't sure about the way date fields are set to a default value here, but if that works, feel free to merge.

Comment on lines +42 to +43
keysInStore = ['ngramSettings'];

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this variable is never used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, by the StoreSync parent.

analysis: 'none',
maxDocuments: 50,
numberOfNgrams: 10,
dateField: 'date'
Copy link
Contributor

Choose a reason for hiding this comment

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

The way the date field is handled looks a bit shaky, since the corpus may not actually have a field with this name. I think this was already an issue, though. Have you checked that the visualisation still works with corpora like parliament-denmark-old?

Copy link
Contributor Author

@BeritJanssen BeritJanssen Dec 20, 2024

Choose a reason for hiding this comment

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

Yes, good point. The problem is that when the ngramParameters model is initialized, the corpus input hasn't been set yet, so we cannot set the date field. Initializing in onChanges ... if (changes.corpus) and passing the first date field in the corpus on initialization may be the best way to solve this (in practice, this only happens once, as we will have to navigate away from the ngram component in order to change the corpus). I will try that. This highlights a problem that I see with outfactoring state management to models in general: often, state management and data manipulation requires transferring knowledge about preconditions for certain states as well. So a lot of the logic tied to the data will still be tied up in the component. This could probably be solved if we did more heavy refactoring, and not use @Input anymore to transfer corpus and queryModel state, and instead keep tabs on them through observables. Then again, my intuition is that it would move the code into a less angularesque state, and would make it harder to step into as a new developer.

Copy link
Contributor Author

@BeritJanssen BeritJanssen Dec 23, 2024

Choose a reason for hiding this comment

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

Hmm, I tried and abandoned the idea to initialize ngramParameters in ngOnChanges. That seems to work in practice, but unit testing depending on change detection is a bit of a nuisance. I decided to remove the date field from the routing parameters for now: the number of corpora in which different date fields are available is so limited that I think it's not too important to include the date field in the route at this moment. We can add it once we decided & implemented a more stable solution for transferring knowledge about corpus & queryModel between components and/or models.

@BeritJanssen BeritJanssen merged commit 3f3d887 into develop Dec 23, 2024
1 check passed
@BeritJanssen BeritJanssen deleted the feature/n-gram-update branch December 23, 2024 14:04
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.

ngram request triggered three times
2 participants