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

Strict TS config - Week 1 #606

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export interface LabelEvent {
filter: LabelFilter;
}

export interface OwnDatatableColumn {
prop: string;
mode: string;
}

@Component({
selector: 'laji-own-datatable',
templateUrl: './own-datatable.component.html',
Expand All @@ -93,7 +98,7 @@ export interface LabelEvent {
]
})
export class OwnDatatableComponent implements OnInit, AfterViewChecked, OnDestroy {
@Input() year: string;
@Input() year = '';
@Input() loadError = '';
@Input() showDownloadAll = true;
@Input() showPrintLabels = true;
Expand All @@ -115,8 +120,8 @@ export class OwnDatatableComponent implements OnInit, AfterViewChecked, OnDestro

totalMessage = '';
publicity = Document.PublicityRestrictionsEnum;
useColumns = [];
allColumns = [
useColumns: OwnDatatableColumn[] = [];
allColumns: OwnDatatableColumn[] = [
{prop: 'templateName', mode: 'small'},
{prop: 'templateDescription', mode: 'small'},
{prop: 'dateEdited', mode: 'small'},
Expand All @@ -132,31 +137,31 @@ export class OwnDatatableComponent implements OnInit, AfterViewChecked, OnDestro
{prop: 'publicityRestrictions', mode: 'large'}
];
allRows: RowDocument[] = [];
visibleRows: RowDocument[];
filterBy: string;
visibleRows: RowDocument[] = [];
filterBy = '';
selectionType: SelectionType;
selectedLabel: string;
selectedLabel = '';
labelLoading = false;

displayMode: string;
displayMode = 'medium';
defaultSort: any;

usersId: string;
usersIdSub: Subscription;
usersId = '';
usersIdSub!: Subscription;

subscriptionDeleteOwnDocument: Subscription;
subscriptionDeleteOwnDocument!: Subscription;

downloadedDocumentId: string;
downloadedDocumentId = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of setting a default value, you could make the variable optional downloadedDocumentId?: string or set the type as downloadedDocumentId: string | undefined

fileType = 'csv';

_columns = ['dateEdited', 'dateObserved', 'locality', 'taxon', 'gatheringsCount', 'unitCount', 'observer', 'form', 'id', 'publicityRestrictions'];
_goToStartAfterViewCheck = false;
private lastSort: any;

@ViewChild(DatatableComponent) table: DatatableComponent;
@ViewChild('chooseFileTypeModal', { static: true }) public modal: ModalComponent;
@ViewChild('saveAsTemplate', { static: true }) public templateModal: ModalComponent;
@ViewChild('deleteModal', { static: true }) public deleteModal: ModalComponent;
@ViewChild(DatatableComponent) table!: DatatableComponent;
@ViewChild('chooseFileTypeModal', { static: true }) public modal!: ModalComponent;
@ViewChild('saveAsTemplate', { static: true }) public templateModal!: ModalComponent;
@ViewChild('deleteModal', { static: true }) public deleteModal!: ModalComponent;

labelFilter$: Observable<LabelFilter>;
forms$: Observable<{[id: string]: Form.List}>;
Expand Down Expand Up @@ -210,8 +215,10 @@ export class OwnDatatableComponent implements OnInit, AfterViewChecked, OnDestro

this.updateDisplayMode();
this.usersIdSub = this.userService.user$.pipe(
map(user => user.id)
).subscribe(id => this.usersId = id);
map(user => user?.id)
).subscribe(id => {
if (id) { this.usersId = id; }
});

this.subscriptionDeleteOwnDocument = this.deleteOwnDocument.childEventListner().subscribe(id => {
if (id !== null) {
Expand Down Expand Up @@ -373,7 +380,7 @@ export class OwnDatatableComponent implements OnInit, AfterViewChecked, OnDestro
}

private initColumns() {
const useCols = [];
const useCols: OwnDatatableColumn[] = [];
this._columns.map(col => {
const column = this.allColumns.find((value) => value.prop === col);
if (column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from
export class PillListComponent {

@Input() separator = ',';
@Input() isLabel;
@Input() isLabel = false;
@Input() isTaxonAutocomplete = false;
@Input() selectedTaxonNames: Array<string>;
@Input() selectedTaxonNames: Array<string> = [];
@Output() updateList = new EventEmitter();

_list;
_list: Array<string> = [];

@Input()
set list(data) {
set list(data: Array<string> | string) {
if (typeof data === 'string') {
this._list = data.split(this.separator);
} else if (Array.isArray(data)) {
const items = [];
const items: Array<string> = [];
data.map(item => items.push(...item.split(this.separator)));
this._list = items;
}
}

remove(item) {
remove(item: string) {
this.updateList.emit(this._list.filter(value => value !== item));
}

findIndexValue(item) {
findIndexValue(item: string) {
if (this.selectedTaxonNames.length > 0) {
const index = this.selectedTaxonNames.findIndex(i => i['id'] === item);
return index > -1 ? this.selectedTaxonNames[index]['value'] : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ import { News } from '../../../shared/model/News';
})
export class TechnicalNewsDumbComponent {
@Input() set news(news: News[] | null) {
this.technicalNews = news?.filter(newsItem => {
const days = 1;
const isNew = Date.now() - parseInt(newsItem.posted, 10) < (days * 86400000); // number of milliseconds in a day
const isTechnical = newsItem.tag === 'technical';
return isTechnical && isNew;
});
if (news) {
this.technicalNews = news?.filter(newsItem => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be changed to this.techicalNews = (news || []).filter(..., then the if clause can be removed and the type can be array (technicalNews: News[] = [];)

const days = 1;

let isNew = false;
if (newsItem.posted) {
isNew = Date.now() - parseInt(newsItem.posted, 10) < (days * 86400000); // number of milliseconds in a day
}

const isTechnical = newsItem.tag === 'technical';
return isTechnical && isNew;
});
} else {
this.technicalNews = null;
}
}
@Input() absoluteLink: string;

technicalNews: News[];
@Input() absoluteLink = '';

technicalNews: News[] | null = null;
}