Skip to content

Commit

Permalink
Disable the day of month selection for now
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Feb 3, 2025
1 parent d5dcb17 commit d972f41
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import { getRuntimeServiceListResourcesQueryKey } from "@rilldata/web-common/runtime-client";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import { useQueryClient } from "@tanstack/svelte-query";
import cronstrue from "cronstrue";
import { createAdminServiceDeleteReport } from "../../../client";
import ProjectAccessControls from "../../projects/ProjectAccessControls.svelte";
import {
Expand All @@ -22,7 +21,11 @@
import MetadataValue from "./MetadataValue.svelte";
import ReportOwnerBlock from "./ReportOwnerBlock.svelte";
import RunNowButton from "./RunNowButton.svelte";
import { exportFormatToPrettyString, formatNextRunOn } from "./utils";
import {
exportFormatToPrettyString,
formatNextRunOn,
formatRefreshSchedule,
} from "./utils";
export let organization: string;
export let project: string;
Expand All @@ -39,18 +42,11 @@
$: dashboardTitle =
$dashboard.data?.explore?.displayName || $dashboardName.data;
// Get human-readable frequency
$: humanReadableFrequency =
$reportQuery.data &&
cronstrue.toString(
$reportQuery.data.resource.report.spec.refreshSchedule.cron,
{
verbose: true,
},
);
$: reportSpec = $reportQuery.data?.resource?.report?.spec;
// Get human-readable frequency
$: humanReadableFrequency = formatRefreshSchedule(reportSpec);
$: emailNotifier = extractNotifier(reportSpec?.notifiers, "email");
$: slackNotifier = extractNotifier(reportSpec?.notifiers, "slack");
Expand Down
26 changes: 26 additions & 0 deletions web-admin/src/features/scheduled-reports/metadata/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { V1ReportSpec } from "@rilldata/web-common/runtime-client";
import cronstrue from "cronstrue";
import { DateTime } from "luxon";
import { V1ExportFormat } from "../../../client";

Expand Down Expand Up @@ -25,3 +27,27 @@ export function formatNextRunOn(nextRunOn: string, timeZone: string): string {
.setZone(timeZone)
.toLocaleString(DateTime.DATETIME_FULL);
}

const suffixMap = {
1: "st",
2: "nd",
3: "rd",
};
export function formatRefreshSchedule(reportSpec: V1ReportSpec) {
if (!reportSpec.refreshSchedule?.cron) return "";
let formattedRefreshSchedule = cronstrue.toString(
reportSpec.refreshSchedule.cron,
{
verbose: true,
},
);
formattedRefreshSchedule = formattedRefreshSchedule.replace(
/on day (\d*) of the month/,
(_, day: number) => {
const suffix = suffixMap[day % 10] ?? "th";
return `on the ${day}${suffix} of each month`;
},
);

return formattedRefreshSchedule;
}
1 change: 1 addition & 0 deletions web-common/src/components/forms/Select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
>
<Select.Trigger
{id}
{disabled}
{lockable}
{lockTooltip}
bind:el={selectElement}
Expand Down
4 changes: 3 additions & 1 deletion web-common/src/components/select/select-trigger.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import TooltipContent from "../tooltip/TooltipContent.svelte";
type $$Props = SelectPrimitive.TriggerProps & {
disabled?: boolean;
lockable?: boolean;
lockTooltip?: string;
// See: https://www.bits-ui.com/docs/components/select#selecttrigger
Expand All @@ -18,6 +19,7 @@
let className: $$Props["class"] = undefined;
export let el: HTMLButtonElement | undefined = undefined;
export let disabled = false;
export let lockable = false;
export let lockTooltip = "";
export { className as class };
Expand All @@ -27,7 +29,7 @@

<SelectPrimitive.Trigger
bind:el
disabled={locked}
disabled={locked || disabled}
class={cn(
"flex h-8 w-full items-center relative justify-between rounded-[2px] border border-gray-300 bg-transparent px-2 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:border-primary-400 disabled:cursor-not-allowed disabled:bg-gray-50 disabled:text-gray-400 [&>span]:line-clamp-1",
className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@
/>
{/if}
{#if $data["frequency"] === ReportFrequency.Monthly}
<Input
bind:value={$data["dayOfMonth"]}
errors={$errors["dayOfMonth"]}
<Select
value={"1"}
id="dayOfMonth"
label="Day"
inputType="number"
width="64px"
labelGap={2}
options={[{ value: "1", label: "First day" }]}
disabled
/>
{/if}
<TimePicker bind:value={$data["timeOfDay"]} id="timeOfDay" label="Time" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
const schema = yup(
object({
title: string().required("Required"),
// There isnt enough space so just say "Invalid"
dayOfMonth: number().min(1, "Invalid").max(31, "Invalid"),
emailRecipients: array().of(string().email("Invalid email")),
slackChannels: array().of(string()),
slackUsers: array().of(string().email("Invalid email")),
Expand Down

0 comments on commit d972f41

Please sign in to comment.