Skip to content

Commit

Permalink
feat(ui): humanize cron expressions (#4233)
Browse files Browse the repository at this point in the history
* Added the **cRonstrue** dependency.
* Enabled English/French localization.
* Enabled the readable cron expression on Flow listing.
* Refactored the app locale config access.
  • Loading branch information
yuri1969 committed Jul 4, 2024
1 parent d66708f commit 26d2794
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 7 deletions.
10 changes: 10 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"node-modules-polyfill": "^0.1.4",
"nprogress": "^0.2.0",
"posthog-js": "^1.138.2",
"cronstrue": "^2.50.0",
"throttle-debounce": "^5.0.0",
"vite-plugin-eslint": "^1.8.1",
"vue": "^3.4.27",
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/flows/TriggerAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
placement="left"
:persistent="true"
:title="`${$t('trigger details')}: ${trigger ? trigger.id : ''}`"
width=""
width="35em"
transition=""
:hide-after="0"
>
Expand Down
7 changes: 6 additions & 1 deletion ui/src/components/flows/TriggerVars.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<template v-if="scope.row.key === 'description'">
<markdown :source="scope.row.value" />
</template>
<template v-else-if="scope.row.key === 'cron'">
<cron :cron-expression="scope.row.value" />
</template>
<template v-else>
<var-value :value="scope.row.value" :execution="execution" />
</template>
Expand All @@ -23,11 +26,13 @@
import Utils from "../../utils/utils";
import VarValue from "../executions/VarValue.vue";
import Markdown from "../layout/Markdown.vue";
import Cron from "../layout/Cron.vue";
export default {
components: {
VarValue,
Markdown
Markdown,
Cron
},
props: {
data: {
Expand Down
25 changes: 25 additions & 0 deletions ui/src/components/layout/Cron.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template>
<span data-component="FILENAME_PLACEHOLDER">
{{ humanReadableCron }}
</span>
</template>

<script>
import Utils from "../../utils/utils.js";
import cronstrue from "cronstrue";
import "cronstrue/locales/fr";
export default {
props: {
cronExpression: {
type: String,
default: undefined
}
},
computed: {
humanReadableCron() {
return cronstrue.toString(this.cronExpression, {locale: Utils.getLang()});
}
}
}
</script>
3 changes: 2 additions & 1 deletion ui/src/components/onboarding/OnboardingCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import imageDoc from "../../assets/onboarding/onboarding-docs-dark.svg"
import imageProduct from "../../assets/onboarding/onboarding-product-dark.svg"
import Markdown from "../layout/Markdown.vue";
import Utils from "../../utils/utils.js";
export default {
name: "OnboardingCard",
Expand Down Expand Up @@ -50,7 +51,7 @@
},
computed: {
lang() {
const lang = localStorage.getItem("lang") || "en";
const lang = Utils.getLang();
if (lang === "fr") {
return "_fr"
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/settings/BasicSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
this.defaultNamespace = localStorage.getItem("defaultNamespace") || "";
this.defaultLogLevel = localStorage.getItem("defaultLogLevel") || "INFO";
this.lang = localStorage.getItem("lang") || "en";
this.lang = Utils.getLang();
this.theme = localStorage.getItem("theme") || "light";
this.editorTheme = localStorage.getItem("editorTheme") || (darkTheme ? "dark" : "vs");
this.dateFormat = localStorage.getItem(DATE_FORMAT_STORAGE_KEY) || "llll";
Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
return Utils.humanDuration(value, options);
},
humanizeNumber: (value) => {
return parseInt(value).toLocaleString(localStorage.getItem("lang") || "en")
return parseInt(value).toLocaleString(Utils.getLang());
},
cap: value => value ? value.toString().capitalize() : "",
lower: value => value ? value.toString().toLowerCase() : "",
Expand Down
3 changes: 2 additions & 1 deletion ui/src/utils/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import TaskSubflowId from "../components/flows/tasks/TaskSubflowId.vue";
import TaskSubflowInputs from "../components/flows/tasks/TaskSubflowInputs.vue";
import LeftMenuLink from "../components/LeftMenuLink.vue";
import RouterMd from "../components/utils/RouterMd.vue";
import Utils from "./utils";

export default (app, routes, stores, translations) => {
// charts
Expand Down Expand Up @@ -102,7 +103,7 @@ export default (app, routes, stores, translations) => {


// l18n
let locale = localStorage.getItem("lang") || "en";
let locale = Utils.getLang();

let i18n = createI18n({
locale: locale,
Expand Down
6 changes: 5 additions & 1 deletion ui/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default class Utils {
static humanDuration(value, options) {
options = options || {maxDecimalPoints: 2};
options.spacer = "";
options.language = localStorage.getItem("lang") || "en";
options.language = Utils.getLang();
options.languages = humanizeDurationLanguages;
options.largest = 2;

Expand Down Expand Up @@ -187,6 +187,10 @@ export default class Utils {
return localStorage.getItem("theme") || "light";
}

static getLang() {
return localStorage.getItem("lang") || "en";
}

static splitFirst(str, separator){
return str.split(separator).slice(1).join(separator);
}
Expand Down

0 comments on commit 26d2794

Please sign in to comment.