Skip to content

Commit

Permalink
review and QA 2
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed May 17, 2024
1 parent 430e960 commit 6d13c8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const inputsByType: Record<ISettingBase['type'], ElementType<any>> = {
type MemoizedSettingProps = {
_id?: string;
type: ISettingBase['type'];
packageValue: ISettingBase['packageValue'];
hint?: ReactNode;
callout?: ReactNode;
value?: SettingValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function TimespanSettingInput({
onChangeValue,
hasResetButton,
onResetButtonClick,
packageValue,
}: TimespanSettingInputProps): ReactElement {
const t = useTranslation();

Expand All @@ -90,7 +91,7 @@ function TimespanSettingInput({
const handleChange: FormEventHandler<HTMLInputElement> = (event) => {
const newValue = sanitizeInputValue(Number(event.currentTarget.value));

onChangeValue?.(newValue);
onChangeValue?.(timeUnitToMs(timeUnit, newValue));

setInternalValue(newValue);
};
Expand All @@ -117,13 +118,20 @@ function TimespanSettingInput({
return Object.entries(TIMEUNIT).map<readonly [TIMEUNIT, string]>(([label, value]) => [value, t.has(label) ? t(label) : label]); // todo translate
}, [t]);

const handleResetButtonClick = () => {
onResetButtonClick?.();
const newTimeUnit = getHighestTimeUnit(Number(packageValue));
setTimeUnit(newTimeUnit);
setInternalValue(msToTimeUnit(newTimeUnit, Number(packageValue)));
};

return (
<Field>
<FieldRow>
<FieldLabel htmlFor={_id} title={_id} required={required}>
{label}
</FieldLabel>
{hasResetButton && <ResetSettingButton data-qa-reset-setting-id={_id} onClick={onResetButtonClick} />}
{hasResetButton && <ResetSettingButton data-qa-reset-setting-id={_id} onClick={handleResetButtonClick} />}
</FieldRow>
<FieldRow>
<InputBox
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/client/views/admin/settings/inputs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type SettingInputProps<V = string, R = V> = {
_id: string;
label: ReactNode;
value?: V;
packageValue: V;
placeholder?: string;
readonly?: boolean;
autocomplete?: boolean;
Expand Down

0 comments on commit 6d13c8f

Please sign in to comment.