Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: fix for template dormancy hour/day toggle#19884

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rowansmithau merged 8 commits intomainfromfix-dormancy-unit-switching
Sep 28, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
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
17 changes: 14 additions & 3 deletionssite/src/components/DurationField/DurationField.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,16 +64,27 @@ export const ChangeUnit: Story = {
},
};

export constCantConvertToDays: Story = {
export constConvertSmallHoursToDays: Story = {
args: {
valueMs: hoursToMs(2),
valueMs: hoursToMs(2), // 2 hours should convert to 1 day when switching units (rounded up)
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

// Initially should show 2 hours
const input = canvas.getByLabelText("Duration");
await expect(input).toHaveValue("2");

// Switch to days by clicking the dropdown
const unitDropdown = canvas.getByLabelText("Time unit");
await userEvent.click(unitDropdown);

// Find and click the Days option - this should now work (no longer disabled)
const daysOption = within(document.body).getByText("Days");
await expect(daysOption).toHaveAttribute("aria-disabled", "true");
await userEvent.click(daysOption);

// After switching to days, should show 1 day (2 hours rounded up to nearest day)
await expect(input).toHaveValue("1");
},
};

Expand Down
38 changes: 20 additions & 18 deletionssite/src/components/DurationField/DurationField.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,19 +45,12 @@ const reducer = (state: State, action: Action): State => {
state.unit,
);

if (
action.unit === "days" &&
!canConvertDurationToDays(currentDurationMs)
) {
return state;
}

return {
unit: action.unit,
durationFieldValue:
action.unit === "hours"
? durationInHours(currentDurationMs).toString()
: durationInDays(currentDurationMs).toString(),
:Math.ceil(durationInDays(currentDurationMs)).toString(),
};
}
default: {
Expand DownExpand Up@@ -124,17 +117,30 @@ export const DurationField: FC<DurationFieldProps> = (props) => {
type: "CHANGE_TIME_UNIT",
unit,
});

// Calculate the new duration in ms after changing the unit
// Important: When changing from hours to days, we need to round up to nearest day
// but keep the millisecond value consistent for the parent component
let newDurationMs: number;
if (unit === "hours") {
// When switching to hours, use the current milliseconds to get exact hours
newDurationMs = currentDurationMs;
} else {
// When switching to days, round up to the nearest day
const daysValue = Math.ceil(durationInDays(currentDurationMs));
newDurationMs = daysToDuration(daysValue);
}

// Notify parent component if the value has changed
if (newDurationMs !== parentValueMs) {
onChange(newDurationMs);
}
}}
inputProps={{ "aria-label": "Time unit" }}
IconComponent={ChevronDownIcon}
>
<MenuItem value="hours">Hours</MenuItem>
<MenuItem
value="days"
disabled={!canConvertDurationToDays(currentDurationMs)}
>
Days
</MenuItem>
<MenuItem value="days">Days</MenuItem>
</Select>
</div>

Expand DownExpand Up@@ -181,7 +187,3 @@ function hoursToDuration(hours: number): number {
function daysToDuration(days: number): number {
return days * 24 * hoursToDuration(1);
}

function canConvertDurationToDays(duration: number): boolean {
return Number.isInteger(durationInDays(duration));
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp