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

Mobile: Resolves #10883: Remove slider component module and replace integer settings with validated text inputs and ensure all validation error flows work correctly #11069

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e55db5a
Create and utilise new component for note history and trashed item tt…
mrjo118 Sep 16, 2024
454da7c
Revert "Create and utilise new component for note history and trashed…
mrjo118 Oct 2, 2024
3d35235
Merge remote-tracking branch 'origin/dev' into note-history-and-trash…
mrjo118 Oct 2, 2024
d001a1e
Allow slider component values to be incremented by tapping the value …
mrjo118 Oct 2, 2024
a0f95a9
Merge branch 'dev' into note-history-and-trash-ttl-text-input
personalizedrefrigerator Oct 5, 2024
dc84c0c
Remove slider component mode and replace integer settings with valida…
mrjo118 Nov 12, 2024
70dbbb3
Make switching to the plugins screen on desktop trigger the switching…
mrjo118 Nov 13, 2024
11b05af
Merge branch 'note-history-and-trash-ttl-text-input2' into note-histo…
mrjo118 Nov 13, 2024
d563598
Remove unused import
mrjo118 Nov 13, 2024
10cb151
Remove license changes with incorrect formatting
mrjo118 Nov 13, 2024
3d7e0c9
Add license change back in
mrjo118 Nov 13, 2024
4a116c3
Revert "Add license change back in"
mrjo118 Nov 13, 2024
e754232
Add license change back in
mrjo118 Nov 13, 2024
47c2fc4
Avoid validating enum values as integers, as they are already restricted
mrjo118 Nov 13, 2024
1aa395e
Fix validation issue
mrjo118 Nov 13, 2024
1e4b87e
Add automated tests
mrjo118 Nov 19, 2024
ad8a277
Merge remote-tracking branch 'origin/dev' into note-history-and-trash…
mrjo118 Nov 19, 2024
57304d2
Merge branch 'dev' into note-history-and-trash-ttl-text-input
mrjo118 Nov 19, 2024
1aa63f0
Resolved compile error due to merging in updates
mrjo118 Nov 19, 2024
960af00
Merge branch 'note-history-and-trash-ttl-text-input' of https://githu…
mrjo118 Nov 19, 2024
bf039c3
Merge branch 'dev' into note-history-and-trash-ttl-text-input
mrjo118 Nov 28, 2024
5428a45
Merge branch 'dev' into note-history-and-trash-ttl-text-input
mrjo118 Dec 9, 2024
2595f61
Change formatting of values back to always using integer type and add…
mrjo118 Dec 10, 2024
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 packages/app-cli/app/command-settingschema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function settingTypeToSchemaType(type: SettingItemType): string {
[SettingItemType.Array]: 'array',
[SettingItemType.Object]: 'object',
[SettingItemType.Button]: '',
[SettingItemType.BigInt]: 'integer',
};

const r = map[type];
Expand Down
2 changes: 1 addition & 1 deletion packages/app-cli/app/help-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function renderCommandHelp(cmd, width = null) {
if ('value' in md) {
if (md.type === Setting.TYPE_STRING) {
defaultString = md.value ? `"${md.value}"` : null;
} else if (md.type === Setting.TYPE_INT) {
} else if (md.type === Setting.TYPE_INT || md.type === Setting.TYPE_BIGINT) {
defaultString = (md.value ? md.value : 0).toString();
} else if (md.type === Setting.TYPE_BOOL) {
defaultString = md.value === true ? 'true' : 'false';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
1 change: 1 addition & 0 deletions packages/app-cli/tests/support/plugins/dialog/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
1 change: 1 addition & 0 deletions packages/app-cli/tests/support/plugins/events/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
1 change: 1 addition & 0 deletions packages/app-cli/tests/support/plugins/menu/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
1 change: 1 addition & 0 deletions packages/app-cli/tests/support/plugins/toc/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
1 change: 1 addition & 0 deletions packages/app-cli/tests/support/plugins/worker/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ const SettingComponent: React.FC<Props> = props => {
</div>
);
}
} else if (md.type === Setting.TYPE_INT) {
} else if (md.type === Setting.TYPE_INT || md.type === Setting.TYPE_BIGINT) {
const value = props.value as number;

const onNumChange: React.ChangeEventHandler<HTMLInputElement> = (event) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,33 @@ const SettingComponent: React.FunctionComponent<Props> = props => {
</View>
</View>
);
} else if (md.type === Setting.TYPE_BIGINT) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than adding a new type (Setting.TYPE_BIGINT), it could make sense to define a new subtype. See, for example, how the FontSearch text input type is implemented .

const value = props.value?.toString();
const label = `${md.label()} (${md.unitLabel(md.value)})`;

return (
<View key={props.settingId} style={{ flexDirection: 'column', borderBottomWidth: 1, borderBottomColor: theme.dividerColor }}>
<View key={props.settingId} style={containerStyle}>
<Text key="label" style={styleSheet.settingText}>
{label}
</Text>
<TextInput
keyboardType="numeric"
autoCorrect={false}
autoComplete="off"
selectionColor={theme.textSelectionColor}
keyboardAppearance={theme.keyboardAppearance}
autoCapitalize="none"
key="control"
style={styleSheet.settingControl}
value={value}
onChangeText={newValue => void props.updateSettingValue(props.settingId, newValue.replace(/[^0-9]/g, ''))}
secureTextEntry={!!md.secure}
/>
</View>
{descriptionComp}
</View>
);
} else if (md.type === Setting.TYPE_STRING) {
if (['sync.2.path', 'plugins.devPluginPaths'].includes(md.key) && (shim.fsDriver().isUsingAndroidSAF() || shim.mobilePlatform() === 'web')) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
7 changes: 4 additions & 3 deletions packages/lib/models/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class Setting extends BaseModel {
public static TYPE_ARRAY = SettingItemType.Array;
public static TYPE_OBJECT = SettingItemType.Object;
public static TYPE_BUTTON = SettingItemType.Button;
public static TYPE_BIGINT = SettingItemType.BigInt;

public static THEME_LIGHT = 1;
public static THEME_DARK = 2;
Expand Down Expand Up @@ -782,7 +783,7 @@ class Setting extends BaseModel {
public static valueToString(key: string, value: any) {
const md = this.settingMetadata(key);
value = this.formatValue(key, value);
if (md.type === SettingItemType.Int) return value.toFixed(0);
if (md.type === SettingItemType.Int || md.type === SettingItemType.BigInt) return value.toFixed(0);
if (md.type === SettingItemType.Bool) return value ? '1' : '0';
if (md.type === SettingItemType.Array) return value ? JSON.stringify(value) : '[]';
if (md.type === SettingItemType.Object) return value ? JSON.stringify(value) : '{}';
Expand All @@ -801,7 +802,7 @@ class Setting extends BaseModel {
public static formatValue(key: string | SettingItemType, value: any) {
const type = typeof key === 'string' ? this.settingMetadata(key).type : key;

if (type === SettingItemType.Int) return !value ? 0 : Math.floor(Number(value));
if (type === SettingItemType.Int || type === SettingItemType.BigInt) return !value ? 0 : Math.floor(Number(value));

if (type === SettingItemType.Bool) {
if (typeof value === 'string') {
Expand Down Expand Up @@ -1086,7 +1087,7 @@ class Setting extends BaseModel {
}

public static typeToString(typeId: SettingItemType) {
if (typeId === SettingItemType.Int) return 'int';
if (typeId === SettingItemType.Int || typeId === SettingItemType.BigInt) return 'int';
if (typeId === SettingItemType.String) return 'string';
if (typeId === SettingItemType.Bool) return 'bool';
if (typeId === SettingItemType.Array) return 'array';
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/models/settings/builtInMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ const builtInMetadata = (Setting: typeof SettingType) => {
'revisionService.ttlDays': {
section: 'revisionService',
value: 90,
type: SettingItemType.Int,
type: SettingItemType.BigInt,
public: true,
minimum: 1,
maximum: 365 * 2,
Expand Down Expand Up @@ -1626,7 +1626,7 @@ const builtInMetadata = (Setting: typeof SettingType) => {

'trash.ttlDays': {
value: 90,
type: SettingItemType.Int,
type: SettingItemType.BigInt,
public: true,
minimum: 1,
maximum: 300,
Expand Down
1 change: 1 addition & 0 deletions packages/lib/models/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
1 change: 1 addition & 0 deletions packages/lib/services/plugins/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

export enum SettingItemSubType {
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/ToggleSidebars/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export enum SettingItemType {
Array = 4,
Object = 5,
Button = 6,
BigInt = 7,
}

// Redefine a simplified interface to mask internal details
Expand Down
Loading