Skip to content

Remove momentJS #333

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
booleanExposingStateControl,
} from "comps/controls/codeStateControl";

import { getMomentLocale } from "i18n/momentLocale";
import { getDayJSLocale } from "i18n/dayjsLocale";
import {
autoCompleteDate,
itemsDataTooltip,
Expand Down Expand Up @@ -151,7 +151,7 @@ let AutoCompleteCompBase = (function () {
const [validateState, setvalidateState] = useState({});

// 是否中文环境
const [chineseEnv, setChineseEnv] = useState(getMomentLocale() === "zh-cn");
const [chineseEnv, setChineseEnv] = useState(getDayJSLocale() === "zh-cn");

useEffect(() => {
setsearchtext(props.value.value);
Expand Down Expand Up @@ -346,11 +346,11 @@ let AutoCompleteCompBase = (function () {
tooltip: itemsDataTooltip,
placeholder: "[]",
})}
{getMomentLocale() === "zh-cn" &&
{getDayJSLocale() === "zh-cn" &&
children.searchFirstPY.propertyView({
label: trans("autoComplete.searchFirstPY"),
})}
{getMomentLocale() === "zh-cn" &&
{getDayJSLocale() === "zh-cn" &&
children.searchCompletePY.propertyView({
label: trans("autoComplete.searchCompletePY"),
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ const multiSelectComps: CompConfig[] = [
const dateComp: CompConfig = {
type: "date",
};
// TODO: RAHEEL

function dateTimeToTimestamp(compName: string) {
return "moment(" + compName + ".value || 0).valueOf()";
return "dayjs(" + compName + ".value || 0).valueOf()";
}
function dateTimeComp(toTimestamp?: boolean): CompConfig {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function hookToStateComp(useHookFn: () => JSONObject) {
}

/**
* Provide a comp of static data, such as exposure of lodash, moment library
* Provide a comp of static data, such as exposure of lodash, day.js library
*/
export function simpleValueComp(value: any) {
return simpleValueGetterComp(() => value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Hooks for managing dependencies
* lodash and moment are supported by default
* lodash and dayJS are supported by default
*/
export const DependecyHook = null;
2 changes: 1 addition & 1 deletion client/packages/lowcoder/src/comps/hooks/drawerComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ let TmpDrawerComp = (function () {
<Drawer
resizable={resizable}
onResizeStop={onResizeStop}
style={props.visible.value ? { overflow: "auto", pointerEvents: "auto" } : {}}
rootStyle={props.visible.value ? { overflow: "auto", pointerEvents: "auto" } : {}}
contentWrapperStyle={{ maxHeight: "100%", maxWidth: "100%" }}
bodyStyle={{ padding: 0, backgroundColor: props.style.background }}
closable={false}
Expand Down
2 changes: 1 addition & 1 deletion client/packages/lowcoder/src/comps/hooks/hookComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const HookMap: HookCompMapRawType = {
currentTime: CurrentTimeHookComp,
lodashJsLib: LodashJsLib,
dayJsLib: DayJsLib,
momentJsLib: DayJsLib,
momentJsLib: DayJsLib, // old components use this hook
utils: UtilsComp,
message: MessageComp,
localStorage: LocalStorageComp,
Expand Down
1 change: 0 additions & 1 deletion client/packages/lowcoder/src/comps/hooks/hookListComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const defaultHookListValue = [
// { compType: "windowSize", name: "windowSize" },
{ compType: "urlParams", name: "url" },
{ compType: "dayJsLib", name: "dayjs" },
// { compType: "momentJsLib", name: "dayjs" },
{ compType: "lodashJsLib", name: "_" },
{ compType: "utils", name: "utils" },
{ compType: "message", name: "message" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { language } from "i18n";

export function getMomentLocale() {
export function getDayJSLocale() {
switch (language) {
case "zh":
return "zh-cn";
Expand Down
4 changes: 2 additions & 2 deletions client/packages/lowcoder/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ export const en = {
preloadCSSApply: "Apply to the homepage of the workspace",
preloadLibsTitle: "JavaScript library",
preloadLibsHelp:
"Set up preloaded JavaScript libraries for all applications in the current workspace, and the system has built-in lodash, moment, uuid, numbro for direct use. JavaScript libraries are loaded before the app is initialized, so there is a certain impact on app performance.",
"Set up preloaded JavaScript libraries for all applications in the current workspace, and the system has built-in lodash, day.js, uuid, numbro for direct use. JavaScript libraries are loaded before the app is initialized, so there is a certain impact on app performance.",
preloadLibsEmpty: "No JavaScript libraries were added",
preloadLibsAddBtn: "Add a library",
saveSuccess: "Saved successfully",
Expand Down Expand Up @@ -1962,7 +1962,7 @@ export const en = {
},
preLoad: {
jsLibraryHelpText:
"Add JavaScript libraries to your current application via URL addresses. lodash, moment, uuid, numbro are built into the system for immediate use. JavaScript libraries are loaded before the application is initialized, which can have an impact on application performance.",
"Add JavaScript libraries to your current application via URL addresses. lodash, day.js, uuid, numbro are built into the system for immediate use. JavaScript libraries are loaded before the application is initialized, which can have an impact on application performance.",
exportedAs: "Exported as",
urlTooltip:
"URL address of the JavaScript library, [unpkg.com](https://unpkg.com/) or [jsdelivr.net](https://www.jsdelivr.com/) is recommended",
Expand Down
4 changes: 2 additions & 2 deletions client/packages/lowcoder/src/i18n/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ advanced: {
preloadCSSApply: "应用到工作空间的首页",
preloadLibsTitle: "JavaScript 库",
preloadLibsHelp:
"为当前工作空间中的所有应用程序设置预加载的 JavaScript 库,系统内置了 lodash、moment、uuid、numbro 可供直接使用.JavaScript 库在应用程序初始化之前加载,因此对应用程序性能有一定影响.",
"为当前工作空间中的所有应用程序设置预加载的 JavaScript 库,系统内置了 lodash、day.js、uuid、numbro 可供直接使用.JavaScript 库在应用程序初始化之前加载,因此对应用程序性能有一定影响.",
preloadLibsEmpty: "尚未添加 JavaScript 库",
preloadLibsAddBtn: "添加库",
saveSuccess: "保存成功",
Expand Down Expand Up @@ -1935,7 +1935,7 @@ userAuth: {
copyPassword: "复制密码",
},
preLoad: {
jsLibraryHelpText: "通过URL链接向当前应用程序添加JavaScript库.lodash、moment、uuid、numbro内置于系统中,可立即使用.JavaScript库在应用程序初始化之前加载,这可能会影响应用程序的性能.",
jsLibraryHelpText: "通过URL链接向当前应用程序添加JavaScript库.lodash、day.js、uuid、numbro内置于系统中,可立即使用.JavaScript库在应用程序初始化之前加载,这可能会影响应用程序的性能.",
exportedAs: "导出为",
urlTooltip: "JavaScript库的URL链接,建议使用[unpkg.com](https://unpkg.com/)或[jsdelivr.net](https://www.jsdelivr.com/).",
recommended: "推荐",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export default function BottomMetaDrawer(props: BottomMetaDrawerProps) {
boxShadow: "none",
borderRadius: "0",
}}
style={{
rootStyle={{
position: "absolute",
height: "100%",
bottom: 0,
Expand Down
4 changes: 2 additions & 2 deletions client/packages/lowcoder/src/util/commonUtils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import log, { LogLevelDesc } from "loglevel";
import dayjs from "dayjs";
import { getMomentLocale } from "i18n/momentLocale";
import { getDayJSLocale } from "i18n/dayjsLocale";
import _ from "lodash";

// https://github.com/vitejs/vite/discussions/7492#discussioncomment-2449310
import "dayjs/locale/en-gb";
import "dayjs/locale/zh-cn";

export function initApp() {
dayjs.locale(getMomentLocale());
dayjs.locale(getDayJSLocale());
const logLevel = getEnvLogLevel();
log.setLevel(logLevel);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/build-apps/use-third-party-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Lowcoder provides some JavaScript built-in libraries for use.
| Library | Docs | Version |
| --------- | -------------------------------------------------------------------- | -------------------------- |
| lodash | [https://lodash.com/docs/](https://lodash.com/docs/) | 4.17.21 |
| moment | [https://momentjs.com/docs/](https://momentjs.com/docs/) | 2.29.3 |
| day.js | [https://day.js.org/docs](https://day.js.org/docs/) | 2.29.3 |
| uuid | [https://github.com/uuidjs/uuid](https://github.com/uuidjs/uuid) | 8.3.2(Support v1/v3/v4/v5) |
| numbro | [https://numbrojs.com/format.html](https://numbrojs.com/format.html) | 2.3.6 |
| papaparse | [https://www.papaparse.com/docs](https://www.papaparse.com/docs) | 5.3.2 |
Expand Down
4 changes: 2 additions & 2 deletions docs/build-apps/write-javascript/javascript-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ function isMultiple(num1, num2) {
return num1 % num2 === 0;
}

// Call the moment library to return the current date
// Call the day.js library to return the current date
function getCurrentDate() {
return moment().format("YYYY-MM-DD");
return dayjs().format("YYYY-MM-DD");
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/build-apps/write-javascript/transformers.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ In the following example, `transformer1` uses the data of star rating in `rating

### Transform timestamp

Use the `moment().format()` method to transform timestamp formats. The following example converts the timestamp value of `start_time` returned by `query1` to `YYYY-MM-DD` format.
Use the `dayjs().format()` method to transform timestamp formats. The following example converts the timestamp value of `start_time` returned by `query1` to `YYYY-MM-DD` format.

```javascript
return query1.data.map(it => {
return {
...it,
start_time: moment(it.start_time).format('YYYY-MM-DD')
start_time: dayjs(it.start_time).format('YYYY-MM-DD')
};
})
```
Expand Down
2 changes: 1 addition & 1 deletion docs/build-apps/write-javascript/write-javascript-in.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Lowercase a string.
Change date format.

```javascript
{{moment(table1.selectedRow.date_column).format('YYYY-MM-DD')}}
{{dayjs(table1.selectedRow.date_column).format('YYYY-MM-DD')}}
```

Return name from query results.
Expand Down