Skip to content
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

HPCC-29403 Allow disabling time zone adjustments in ECLWatch #17655

Open
wants to merge 1 commit into
base: candidate-9.2.x
Choose a base branch
from
Open
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
33 changes: 30 additions & 3 deletions esp/src/src-react/components/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

const defaultUIState = {
hasSelection: false,
isUTC: false,
};

interface FilesProps {
Expand Down Expand Up @@ -127,6 +128,25 @@
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasFocus]);

const toggleTimezone = () => {
setUIState((prevState) => ({ ...prevState, isUTC: !prevState.isUTC }));
};

React.useEffect(() => {
localStorage.setItem("isUTC", JSON.stringify(uiState.isUTC));
}, [uiState.isUTC]);

React.useEffect(() => {
const storedIsUTC = JSON.parse(localStorage.getItem("isUTC"));
if (storedIsUTC !== null) {
setUIState((prevState) => ({ ...prevState, isUTC: storedIsUTC }));
}
}, []);

const currentTime = React.useCallback(timestamp => {
const date = new Date(timestamp);
return date.toUTCString();
}, []);
// Grid ---
const gridStore = React.useMemo(() => {
return store ? store : CreateDFUQueryStore();
Expand Down Expand Up @@ -216,8 +236,8 @@
MaxSkew: {
label: nlsHPCC.MaxSkew, width: 60, formatter: (value, row) => value ? `${Utility.formatDecimal(value / 100)}%` : ""
},
Modified: { label: nlsHPCC.ModifiedUTCGMT },
Accessed: { label: nlsHPCC.LastAccessed },
Modified: { label: nlsHPCC.ModifiedUTCGMT, formatter: currentTime },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this before, but you'd probably have to change the label here depending on which TZ is selected, so it doesn't always say "UTC"

AtRestCost: {
label: nlsHPCC.FileCostAtRest,
formatter: (cost, row) => {
Expand All @@ -231,7 +251,7 @@
},
}
};
}, []);

Check warning on line 254 in esp/src/src-react/components/Files.tsx

View workflow job for this annotation

GitHub Actions / Check eclwatch and npm (20)

React Hook React.useMemo has a missing dependency: 'currentTime'. Either include it or remove the dependency array

Check warning on line 254 in esp/src/src-react/components/Files.tsx

View workflow job for this annotation

GitHub Actions / Check eclwatch and npm (18)

React Hook React.useMemo has a missing dependency: 'currentTime'. Either include it or remove the dependency array

Check warning on line 254 in esp/src/src-react/components/Files.tsx

View workflow job for this annotation

GitHub Actions / Check eclwatch and npm (16)

React Hook React.useMemo has a missing dependency: 'currentTime'. Either include it or remove the dependency array

const copyButtons = useCopyButtons(columns, selection, "files");

Expand Down Expand Up @@ -321,7 +341,14 @@
pushParams(filter);
}
},
], [currentUser, filter, hasFilter, refreshTable, selection, setShowDeleteConfirm, store, total, uiState.hasSelection, viewByScope]);
{ key: "divider_6", itemType: ContextualMenuItemType.Divider, onRender: () => <ShortVerticalDivider /> },
{
key: "toggleTimezone",
text: uiState.isUTC ? nlsHPCC.SwitchToLocalTime : nlsHPCC.SwitchToUTCTime,
iconProps: { iconName: uiState.isUTC ? "Globe" : "Clock" },
onClick: toggleTimezone,
},
], [currentUser, filter, hasFilter, refreshTable, selection, setShowDeleteConfirm, store, total, uiState.hasSelection, viewByScope, uiState.isUTC]);

// Filter ---
const filterFields: Fields = {};
Expand Down Expand Up @@ -382,4 +409,4 @@
></FluentPagedFooter>}
footerStyles={{}}
/>;
};
};
11 changes: 10 additions & 1 deletion esp/src/src/Utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,4 +1307,13 @@ export function wuidToTime(wuid: string): string {

export function wuidToDateTime(wuid: string): Date {
return new Date(`${wuidToDate(wuid)}T${wuidToTime(wuid)}Z`);
}
}
export function convertToLocalTime(dateString) {
const modifiedDate = new Date(dateString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These conversion functions may have to be slightly more complicated unfortunately. Using the Date.toLocaleString() and .toUTCString() functions as is would also change the formatting of the timestamps from something like 2023-07-21 01:14:44 to Fri, 21 Jul 2023 01:14:44 GMT. Which might be an improvement, actually... But just something to consider.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was what I was talking about in my previous review. Seems like these should just be formatted one way or the other, so that they're consistent.

image

return modifiedDate.toLocaleString();
}

export function convertToUTCTime(dateString) {
const modifiedDate = new Date(dateString);
return modifiedDate.toUTCString();
}
2 changes: 2 additions & 0 deletions esp/src/src/nls/hpcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@ export = {
SuspendedReason: "Suspended Reason",
Statistics: "Statistics",
SVGSource: "SVG Source",
SwitchToLocalTime:"Switch to Local Time",
SwitchToUTCTime:"Switch to UTC Time",
SyncSelection: "Sync To Selection",
Syntax: "Syntax",
SystemServers: "System Servers",
Expand Down
Loading