mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
[+] implement LocaleDate consumer
Signed-off-by: Arthur Knoepflin <arthur@knoepflin.eu>
This commit is contained in:
parent
dad485b39d
commit
68b0ef59c1
@ -56,7 +56,7 @@ export class UserStore extends BaseStore<UserStoreModel> {
|
|||||||
allowTelemetry: true,
|
allowTelemetry: true,
|
||||||
allowUntrustedCAs: false,
|
allowUntrustedCAs: false,
|
||||||
colorTheme: UserStore.defaultTheme,
|
colorTheme: UserStore.defaultTheme,
|
||||||
localeTimezone: moment.tz.guess(true),
|
localeTimezone: moment.tz.guess(true) || "UTC",
|
||||||
downloadMirror: "default",
|
downloadMirror: "default",
|
||||||
downloadKubectlBinaries: true, // Download kubectl binaries matching cluster version
|
downloadKubectlBinaries: true, // Download kubectl binaries matching cluster version
|
||||||
openAtLogin: false,
|
openAtLogin: false,
|
||||||
@ -133,6 +133,11 @@ export class UserStore extends BaseStore<UserStoreModel> {
|
|||||||
this.lastSeenAppVersion = getAppVersion();
|
this.lastSeenAppVersion = getAppVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
setLocaleTimezone(tz: string) {
|
||||||
|
this.preferences.localeTimezone = tz;
|
||||||
|
}
|
||||||
|
|
||||||
protected refreshNewContexts = async () => {
|
protected refreshNewContexts = async () => {
|
||||||
try {
|
try {
|
||||||
const kubeConfig = await readFile(this.kubeConfigPath, "utf8");
|
const kubeConfig = await readFile(this.kubeConfigPath, "utf8");
|
||||||
|
|||||||
@ -41,12 +41,10 @@ export class Preferences extends React.Component {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get timezoneOptions(): SelectOption<string>[] {
|
timezoneOptions: SelectOption<string>[] = moment.tz.names().map(zone => ({
|
||||||
return moment.tz.names().map(zone => ({
|
|
||||||
label: zone,
|
label: zone,
|
||||||
value: zone,
|
value: zone,
|
||||||
}));
|
}));
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
@ -169,7 +167,7 @@ export class Preferences extends React.Component {
|
|||||||
<Select
|
<Select
|
||||||
options={this.timezoneOptions}
|
options={this.timezoneOptions}
|
||||||
value={preferences.localeTimezone}
|
value={preferences.localeTimezone}
|
||||||
onChange={({ value }: SelectOption) => preferences.localeTimezone = value}
|
onChange={({ value }: SelectOption) => userStore.setLocaleTimezone(value)}
|
||||||
themeName="lens"
|
themeName="lens"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { DrawerItem, DrawerItemLabels } from "../drawer";
|
|||||||
import { lookupApiLink } from "../../api/kube-api";
|
import { lookupApiLink } from "../../api/kube-api";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
||||||
|
import { LocaleDate } from "../locale-date";
|
||||||
import { getDetailsUrl } from "./kube-object-details";
|
import { getDetailsUrl } from "./kube-object-details";
|
||||||
|
|
||||||
export interface KubeObjectMetaProps {
|
export interface KubeObjectMetaProps {
|
||||||
@ -35,7 +36,7 @@ export class KubeObjectMeta extends React.Component<KubeObjectMetaProps> {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DrawerItem name="Created" hidden={this.isHidden("creationTimestamp")}>
|
<DrawerItem name="Created" hidden={this.isHidden("creationTimestamp")}>
|
||||||
{getAge(true, false)} ago ({creationTimestamp})
|
{getAge(true, false)} ago ({<LocaleDate date={creationTimestamp} />})
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
<DrawerItem name="Name" hidden={this.isHidden("name")}>
|
<DrawerItem name="Name" hidden={this.isHidden("name")}>
|
||||||
{getName()} <KubeObjectStatusIcon key="icon" object={object} />
|
{getName()} <KubeObjectStatusIcon key="icon" object={object} />
|
||||||
|
|||||||
1
src/renderer/components/locale-date/index.ts
Normal file
1
src/renderer/components/locale-date/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from "./locale-date";
|
||||||
18
src/renderer/components/locale-date/locale-date.tsx
Normal file
18
src/renderer/components/locale-date/locale-date.tsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { observer } from "mobx-react";
|
||||||
|
import moment from "moment-timezone";
|
||||||
|
import { userStore } from "../../../common/user-store";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
date: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@observer
|
||||||
|
export class LocaleDate extends React.Component<Props> {
|
||||||
|
render() {
|
||||||
|
const { preferences } = userStore;
|
||||||
|
const { date } = this.props;
|
||||||
|
|
||||||
|
return <>{moment.tz(date, preferences.localeTimezone).format()}</>;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user