Skip to content

Commit

Permalink
add: notification when regex is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Odaimoko committed Aug 22, 2024
1 parent 8458264 commit 3c7435b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
15 changes: 10 additions & 5 deletions src/data-model/workflow-def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ export function isTaskSummaryValid(task: STask) {
export function trimTextBySettings(text: string) {
const taskSummaryTrimPattern = getSettings()?.task_summary_trim_regexp_pattern as string;
if (taskSummaryTrimPattern) { // undefined or empty string we do not use regex
const regex = new RegExp(taskSummaryTrimPattern, "g");
const regexReplacedText = text.replace(regex, "");
if (text != regexReplacedText && text.includes("UT_080")) {
devLog("Regex Trimmed", text, "->", regexReplacedText);
let regexReplacedText = text;
try {
const regex = new RegExp(taskSummaryTrimPattern, "g");
regexReplacedText = text.replace(regex, "");
if (text != regexReplacedText && text.includes("UT_080")) {
devLog("Regex Trimmed", text, "->", regexReplacedText);
}
} catch (e) { /* empty */
} finally {
text = regexReplacedText;
}
text = regexReplacedText;
}
return text;
}
Expand Down
32 changes: 27 additions & 5 deletions src/settings/RegexTrimEditView.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import React from "react";
import React, {useEffect, useState} from "react";
import {HStack} from "../ui/pure-react/view-template/h-stack";
import {centerChildren, diffGroupSpacing} from "../ui/pure-react/style-def";
import {getSettings, usePluginSettings} from "./settings";
import {ArrowMoveRight} from "../ui/pure-react/icon/ArrowBigUpDash";
import {InlineCodeView} from "../ui/common/inline-code-view";
import {devLog} from "../utils/env-util";
import {DisappearableErrText} from "../ui/pure-react/view-template/disappearable-err-text";

export function RegexTrimEditView() {
// TODO Previe use task_summary_trim_regexp_pattern_test_text
const [regPattern, setRegPattern] = usePluginSettings<string>("task_summary_trim_regexp_pattern")
const [testText, setTestText] = usePluginSettings<string>("task_summary_trim_regexp_pattern_test_text");
const replacedText = testText.replace(new RegExp(regPattern), "");
devLog(`$[RegexTrimEditView] oriTag: ${regPattern}, patternValid?`);
const [notiText, setNotiText] = useState("")
let regExp: RegExp | null = null;
try {
regExp = new RegExp(regPattern);
} catch (e) {
// regExp is invalid
}
useEffect(() => {
if (!regExp)
setNotiText("[Err] Invalid Regular expression.")
else setNotiText("")
}, [testText, regPattern]);
const replacedText = regExp ? testText.replace(regExp, "") : testText;
devLog(`$[RegexTrimEditView] oriTag: ${regPattern}, patternValid? ${!!regExp}`);
return <div>
<HStack style={{justifyContent: "space-between"}}>
<div>
<div className={"setting-item-name"}>Remove regex pattern from task summary</div>
<div className={"setting-item-description"}>
You need to edit some file and save for this to be effective. Empty means no effect.
Empty means no effect.
</div>
<div className={"setting-item-description"}>
<b>You need to edit any file and save for this to be effective.</b>
</div>
</div>
<div>
Expand All @@ -28,10 +44,15 @@ export function RegexTrimEditView() {
setRegPattern(event.target.value)
}}
/>

</div>
</HStack>

<p/>
<DisappearableErrText color={notiText.startsWith("[Err]") ? "var(--text-error)" : "green"}
text={notiText} setText={setNotiText}/>
<p/>
<label>Preview Your Task:</label>
<label>Preview Your Task </label>
<HStack style={{justifyContent: "space-between", ...centerChildren}} spacing={diffGroupSpacing}>
<div style={{minWidth: 200,}}>
<div style={{display: "inline-block"}}>
Expand All @@ -54,6 +75,7 @@ export function RegexTrimEditView() {
<InlineCodeView text={"]"}/>
</div>
</div>

</HStack>
</div>
}
1 change: 0 additions & 1 deletion src/ui/react-view/react-manage-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export function ReactManagePage({eventCenter}: {
// })

// endregion

return (
<div>
<HStack>
Expand Down

0 comments on commit 3c7435b

Please sign in to comment.