Skip to content

Commit

Permalink
Create and utilise new component for note history and trashed item tt…
Browse files Browse the repository at this point in the history
…l, which allows entering the value accurately on the mobile app
  • Loading branch information
mrjo118 committed Sep 16, 2024
1 parent 8d3ac63 commit e55db5a
Show file tree
Hide file tree
Showing 36 changed files with 66 additions and 7 deletions.
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) {
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

0 comments on commit e55db5a

Please sign in to comment.