From 03c3feef1680e6e9bd3ebd1a8f60bbee3447a739 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Mon, 8 Apr 2024 04:35:57 -0700 Subject: [PATCH] Mobile: Resolves #10245: Allow marking items as "ignored" in sync status (#10261) --- .eslintignore | 4 + .gitignore | 4 + .../screens/{status.js => status.tsx} | 93 +++++++++------ packages/app-mobile/root.tsx | 2 +- packages/lib/models/BaseItem.ts | 24 +++- .../settings/settingValidations.test.ts | 35 ++++++ packages/lib/services/ReportService.test.ts | 108 ++++++++++++++++++ packages/lib/services/ReportService.ts | 48 ++++++-- .../lib/services/database/migrations/47.ts | 7 ++ .../lib/services/database/migrations/index.ts | 2 + packages/lib/services/database/types.ts | 2 + packages/tools/cspell/dictionary4.txt | 5 +- 12 files changed, 290 insertions(+), 44 deletions(-) rename packages/app-mobile/components/screens/{status.js => status.tsx} (56%) create mode 100644 packages/lib/models/settings/settingValidations.test.ts create mode 100644 packages/lib/services/ReportService.test.ts create mode 100644 packages/lib/services/database/migrations/47.ts diff --git a/.eslintignore b/.eslintignore index 63957fa0b..e3c12f8cb 100644 --- a/.eslintignore +++ b/.eslintignore @@ -597,6 +597,7 @@ packages/app-mobile/components/screens/Notes.js packages/app-mobile/components/screens/UpgradeSyncTargetScreen.js packages/app-mobile/components/screens/encryption-config.js packages/app-mobile/components/screens/search.js +packages/app-mobile/components/screens/status.js packages/app-mobile/components/side-menu-content.js packages/app-mobile/components/voiceTyping/VoiceTypingDialog.js packages/app-mobile/gulpfile.js @@ -858,6 +859,7 @@ packages/lib/models/Tag.test.js packages/lib/models/Tag.js packages/lib/models/dateTimeFormats.test.js packages/lib/models/settings/FileHandler.js +packages/lib/models/settings/settingValidations.test.js packages/lib/models/settings/settingValidations.js packages/lib/models/utils/getCollator.js packages/lib/models/utils/getConflictFolderId.js @@ -897,6 +899,7 @@ packages/lib/services/KvStore.js packages/lib/services/MigrationService.js packages/lib/services/NavService.js packages/lib/services/PostMessageService.js +packages/lib/services/ReportService.test.js packages/lib/services/ReportService.js packages/lib/services/ResourceEditWatcher/index.js packages/lib/services/ResourceEditWatcher/reducer.js @@ -924,6 +927,7 @@ packages/lib/services/database/migrations/43.js packages/lib/services/database/migrations/44.js packages/lib/services/database/migrations/45.js packages/lib/services/database/migrations/46.js +packages/lib/services/database/migrations/47.js packages/lib/services/database/migrations/index.js packages/lib/services/database/sqlStringToLines.js packages/lib/services/database/types.js diff --git a/.gitignore b/.gitignore index 2ac858dd1..2386f2d8e 100644 --- a/.gitignore +++ b/.gitignore @@ -577,6 +577,7 @@ packages/app-mobile/components/screens/Notes.js packages/app-mobile/components/screens/UpgradeSyncTargetScreen.js packages/app-mobile/components/screens/encryption-config.js packages/app-mobile/components/screens/search.js +packages/app-mobile/components/screens/status.js packages/app-mobile/components/side-menu-content.js packages/app-mobile/components/voiceTyping/VoiceTypingDialog.js packages/app-mobile/gulpfile.js @@ -838,6 +839,7 @@ packages/lib/models/Tag.test.js packages/lib/models/Tag.js packages/lib/models/dateTimeFormats.test.js packages/lib/models/settings/FileHandler.js +packages/lib/models/settings/settingValidations.test.js packages/lib/models/settings/settingValidations.js packages/lib/models/utils/getCollator.js packages/lib/models/utils/getConflictFolderId.js @@ -877,6 +879,7 @@ packages/lib/services/KvStore.js packages/lib/services/MigrationService.js packages/lib/services/NavService.js packages/lib/services/PostMessageService.js +packages/lib/services/ReportService.test.js packages/lib/services/ReportService.js packages/lib/services/ResourceEditWatcher/index.js packages/lib/services/ResourceEditWatcher/reducer.js @@ -904,6 +907,7 @@ packages/lib/services/database/migrations/43.js packages/lib/services/database/migrations/44.js packages/lib/services/database/migrations/45.js packages/lib/services/database/migrations/46.js +packages/lib/services/database/migrations/47.js packages/lib/services/database/migrations/index.js packages/lib/services/database/sqlStringToLines.js packages/lib/services/database/types.js diff --git a/packages/app-mobile/components/screens/status.js b/packages/app-mobile/components/screens/status.tsx similarity index 56% rename from packages/app-mobile/components/screens/status.js rename to packages/app-mobile/components/screens/status.tsx index 5bc7d849e..6231bc20b 100644 --- a/packages/app-mobile/components/screens/status.js +++ b/packages/app-mobile/components/screens/status.tsx @@ -1,50 +1,64 @@ -const React = require('react'); +import * as React from 'react'; -const { View, Text, Button, FlatList } = require('react-native'); -const Setting = require('@joplin/lib/models/Setting').default; -const { connect } = require('react-redux'); -const { ScreenHeader } = require('../ScreenHeader'); -const ReportService = require('@joplin/lib/services/ReportService').default; -const { _ } = require('@joplin/lib/locale'); -const { BaseScreenComponent } = require('../base-screen'); -const { themeStyle } = require('../global-style'); +import { View, Text, Button, FlatList, TextStyle, StyleSheet } from 'react-native'; +import Setting from '@joplin/lib/models/Setting'; +import { connect } from 'react-redux'; +import { ScreenHeader } from '../ScreenHeader'; +import ReportService, { ReportSection } from '@joplin/lib/services/ReportService'; +import { _ } from '@joplin/lib/locale'; +import { BaseScreenComponent } from '../base-screen'; +import { themeStyle } from '../global-style'; +import { AppState } from '../../utils/types'; +import checkDisabledSyncItemsNotification from '@joplin/lib/services/synchronizer/utils/checkDisabledSyncItemsNotification'; +import { Dispatch } from 'redux'; -class StatusScreenComponent extends BaseScreenComponent { - static navigationOptions() { - return { header: null }; - } +interface Props { + themeId: number; + dispatch: Dispatch; +} - constructor() { - super(); +interface State { + report: ReportSection[]; +} + +class StatusScreenComponent extends BaseScreenComponent { + public constructor(props: Props) { + super(props); this.state = { report: [], }; } - UNSAFE_componentWillMount() { - this.resfreshScreen(); + public override componentDidMount() { + void this.refreshScreen(); } - async resfreshScreen() { + private async refreshScreen() { const service = new ReportService(); const report = await service.status(Setting.value('sync.target')); this.setState({ report: report }); } - styles() { + private styles() { const theme = themeStyle(this.props.themeId); - return { + return StyleSheet.create({ body: { flex: 1, margin: theme.margin, }, - }; + actionButton: { + flex: 0, + marginLeft: 2, + marginRight: 2, + }, + }); } - render() { + public override render() { const theme = themeStyle(this.props.themeId); + const styles = this.styles(); - const renderBody = report => { + const renderBody = (report: ReportSection[]) => { const baseStyle = { paddingLeft: 6, paddingRight: 6, @@ -60,7 +74,7 @@ class StatusScreenComponent extends BaseScreenComponent { for (let i = 0; i < report.length; i++) { const section = report[i]; - let style = { ...baseStyle }; + let style: TextStyle = { ...baseStyle }; style.fontWeight = 'bold'; if (i > 0) style.paddingTop = 20; lines.push({ key: `section_${i}`, isSection: true, text: section.title }); @@ -76,11 +90,19 @@ class StatusScreenComponent extends BaseScreenComponent { let text = ''; let retryHandler = null; + let ignoreHandler = null; if (typeof item === 'object') { if (item.canRetry) { retryHandler = async () => { await item.retryHandler(); - this.resfreshScreen(); + await this.refreshScreen(); + }; + } + if (item.canIgnore) { + ignoreHandler = async () => { + await item.ignoreHandler(); + await this.refreshScreen(); + await checkDisabledSyncItemsNotification((action) => this.props.dispatch(action)); }; } text = item.text; @@ -88,7 +110,7 @@ class StatusScreenComponent extends BaseScreenComponent { text = item; } - lines.push({ key: `item_${i}_${n}`, text: text, retryHandler: retryHandler }); + lines.push({ key: `item_${i}_${n}`, text: text, retryHandler, ignoreHandler }); } lines.push({ key: `divider2_${i}`, isDivider: true }); @@ -98,7 +120,7 @@ class StatusScreenComponent extends BaseScreenComponent { { - const style = { ...baseStyle }; + const style: TextStyle = { ...baseStyle }; if (item.isSection === true) { style.fontWeight = 'bold'; @@ -114,17 +136,24 @@ class StatusScreenComponent extends BaseScreenComponent { ) : null; const retryButton = item.retryHandler ? ( - +