refactor(schedule form): helper for multiline parsing
This commit is contained in:
parent
2d10da72f6
commit
a671b17b4f
2 changed files with 13 additions and 28 deletions
|
|
@ -14,7 +14,7 @@ import { PathsSection } from "./paths-section";
|
|||
import { RetentionSection } from "./retention-section";
|
||||
import { SummarySection } from "./summary-section";
|
||||
import { internalFormSchema, type BackupScheduleFormValues, type InternalFormValues } from "./types";
|
||||
import { backupScheduleToFormValues } from "./utils";
|
||||
import { backupScheduleToFormValues, parseMultilineEntries } from "./utils";
|
||||
|
||||
export type { BackupScheduleFormValues };
|
||||
|
||||
|
|
@ -46,34 +46,11 @@ export const CreateScheduleForm = ({ initialValues, formId, onSubmit, volume }:
|
|||
cronExpression,
|
||||
...rest
|
||||
} = data;
|
||||
const excludePatterns = excludePatternsText
|
||||
? excludePatternsText
|
||||
.split("\n")
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
|
||||
const excludeIfPresent = excludeIfPresentText
|
||||
? excludeIfPresentText
|
||||
.split("\n")
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
|
||||
const textPatterns = includePatternsText
|
||||
? includePatternsText
|
||||
.split("\n")
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
const excludePatterns = parseMultilineEntries(excludePatternsText);
|
||||
const excludeIfPresent = parseMultilineEntries(excludeIfPresentText);
|
||||
const textPatterns = parseMultilineEntries(includePatternsText);
|
||||
const includePatterns = [...(fileBrowserPatterns || []), ...textPatterns];
|
||||
|
||||
const customResticParams = customResticParamsText
|
||||
? customResticParamsText
|
||||
.split("\n")
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
const customResticParams = parseMultilineEntries(customResticParamsText);
|
||||
|
||||
onSubmit({
|
||||
...rest,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,14 @@ import type { BackupSchedule } from "~/client/lib/types";
|
|||
import { cronToFormValues } from "../../lib/cron-utils";
|
||||
import type { InternalFormValues } from "./types";
|
||||
|
||||
export const parseMultilineEntries = (value?: string) =>
|
||||
value
|
||||
? value
|
||||
.split("\n")
|
||||
.map((entry) => entry.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
|
||||
export const backupScheduleToFormValues = (schedule?: BackupSchedule): InternalFormValues | undefined => {
|
||||
if (!schedule) {
|
||||
return undefined;
|
||||
|
|
|
|||
Loading…
Reference in a new issue