change(ui): add more tz, change abs/rel timest

This commit is contained in:
sylenien 2022-12-13 16:29:56 +01:00
parent ea69792159
commit d96ae9e259
7 changed files with 53 additions and 34 deletions

View file

@ -100,10 +100,11 @@ function Timeline(props) {
}; };
} else { } else {
const time = getTime(e); const time = getTime(e);
const tz = settingsStore.sessionSettings.timezone.value
const timeStr = DateTime.fromMillis(props.startedAt + time).setZone(tz).toFormat(`hh:mm:ss a`)
timeLineTooltip = { timeLineTooltip = {
time: !settingsStore.isUniTs time: Duration.fromMillis(time).toFormat(`mm:ss`),
? Duration.fromMillis(time).toFormat(`mm:ss`) timeStr,
: DateTime.fromMillis(props.startedAt + time).toFormat(`hh:mm:ss a`),
offset: e.nativeEvent.offsetX, offset: e.nativeEvent.offsetX,
isVisible: true, isVisible: true,
}; };

View file

@ -8,30 +8,39 @@ interface Props {
time: number; time: number;
offset: number; offset: number;
isVisible: boolean; isVisible: boolean;
timeStr: string;
} }
function TimeTooltip({ function TimeTooltip({
time, time,
offset, offset,
isVisible, isVisible,
timeStr,
}: Props) { }: Props) {
return ( return (
<div <div
className={stl.timeTooltip} className={stl.timeTooltip}
style={{ style={{
top: -30, top: 0,
left: offset, left: offset,
display: isVisible ? 'block' : 'none', display: isVisible ? 'block' : 'none',
transform: 'translateX(-50%)', transform: 'translate(-50%, -110%)',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
textAlign: "center",
}} }}
> >
{!time ? 'Loading' : time} {!time ? 'Loading' : time}
{timeStr ? (
<>
<br />
<span className="text-gray-light">({timeStr})</span>
</>
) : null}
</div> </div>
); );
} }
export default connect((state) => { export default connect((state) => {
const { time = 0, offset = 0, isVisible } = state.getIn(['sessions', 'timeLineTooltip']); const { time = 0, offset = 0, isVisible, timeStr } = state.getIn(['sessions', 'timeLineTooltip']);
return { time, offset, isVisible }; return { time, offset, isVisible, timeStr };
})(TimeTooltip); })(TimeTooltip);

View file

@ -13,7 +13,6 @@ import { PlayerContext } from 'App/components/Session/playerContext';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import { useStore } from 'App/mstore'; import { useStore } from 'App/mstore';
import AutoplayToggle from 'Shared/AutoplayToggle'; import AutoplayToggle from 'Shared/AutoplayToggle';
import { Toggler } from 'UI';
function SubHeader(props) { function SubHeader(props) {
const { player, store } = React.useContext(PlayerContext) const { player, store } = React.useContext(PlayerContext)
@ -28,7 +27,6 @@ function SubHeader(props) {
eventList: eventsList, eventList: eventsList,
endTime, endTime,
} = store.get() } = store.get()
const { settingsStore } = useStore()
const mappedResourceList = resourceList const mappedResourceList = resourceList
.filter((r) => r.isRed() || r.isYellow()) .filter((r) => r.isRed() || r.isYellow())
@ -56,19 +54,9 @@ function SubHeader(props) {
showModal(<BugReportModal width={width} height={height} xrayProps={xrayProps} hideModal={hideModal} />, { right: true }); showModal(<BugReportModal width={width} height={height} xrayProps={xrayProps} hideModal={hideModal} />, { right: true });
}; };
const timeStr = settingsStore.isUniTs ? 'Local Time' : 'Relative Timestamp'
const onFormatCh = (e) => {
e.stopPropagation();
e.preventDefault();
settingsStore.toggleTimeFormat()
}
return ( return (
<div className="w-full px-4 py-2 flex items-center border-b"> <div className="w-full px-4 py-2 flex items-center border-b">
{!isAssist && (<div onClick={onFormatCh} className="cursor-pointer color-gray-medium text-sm p-1 flex items-center gap-2 mr-2 hover:bg-gray-light-shade rounded-md">
<Toggler plain name="sessionsLive" checked={settingsStore.isUniTs} />
<span>{timeStr}</span>
</div>)}
{location && ( {location && (
<div <div
className="flex items-center cursor-pointer color-gray-medium text-sm p-1 hover:bg-gray-light-shade rounded-md" className="flex items-center cursor-pointer color-gray-medium text-sm p-1 hover:bg-gray-light-shade rounded-md"

View file

@ -21,6 +21,7 @@ function FetchDetailsModal(props: Props) {
const isXHR = resource.type === TYPES.XHR const isXHR = resource.type === TYPES.XHR
const { const {
sessionStore: { devTools }, sessionStore: { devTools },
settingsStore: { sessionSettings: { timezone }},
} = useStore(); } = useStore();
useEffect(() => { useEffect(() => {
@ -49,7 +50,7 @@ function FetchDetailsModal(props: Props) {
return ( return (
<div className="bg-white p-5 h-screen overflow-y-auto" style={{ width: '500px' }}> <div className="bg-white p-5 h-screen overflow-y-auto" style={{ width: '500px' }}>
<h5 className="mb-2 text-2xl">Network Request</h5> <h5 className="mb-2 text-2xl">Network Request</h5>
<FetchBasicDetails resource={resource} timestamp={props.time ? DateTime.fromMillis(props.time).toFormat(`hh:mm:ss a`) : undefined} /> <FetchBasicDetails resource={resource} timestamp={props.time ? DateTime.fromMillis(props.time).setZone(timezone.value).toFormat(`hh:mm:ss a`) : undefined} />
{isXHR && !fetchPresented && <FetchPluginMessage />} {isXHR && !fetchPresented && <FetchPluginMessage />}
{isXHR && <FetchTabs resource={resource} />} {isXHR && <FetchTabs resource={resource} />}

View file

@ -70,7 +70,7 @@ const initialState = Map({
timelinePointer: null, timelinePointer: null,
sessionPath: {}, sessionPath: {},
lastPlayedSessionId: null, lastPlayedSessionId: null,
timeLineTooltip: { time: 0, offset: 0, isVisible: false }, timeLineTooltip: { time: 0, offset: 0, isVisible: false, timeStr: '' },
createNoteTooltip: { time: 0, isVisible: false, isEdit: false, note: null }, createNoteTooltip: { time: 0, isVisible: false, isEdit: false, note: null },
}); });
@ -454,4 +454,4 @@ export function updateLastPlayedSession(sessionId) {
type: LAST_PLAYED_SESSION_ID, type: LAST_PLAYED_SESSION_ID,
sessionId, sessionId,
}; };
} }

View file

@ -8,7 +8,6 @@ export default class SettingsStore {
sessionSettings: SessionSettings = new SessionSettings() sessionSettings: SessionSettings = new SessionSettings()
captureRateFetched: boolean = false; captureRateFetched: boolean = false;
limits: any = null; limits: any = null;
isUniTs = false;
constructor() { constructor() {
makeAutoObservable(this, { makeAutoObservable(this, {
@ -16,10 +15,6 @@ export default class SettingsStore {
}) })
} }
toggleTimeFormat = () => {
this.isUniTs = !this.isUniTs
}
saveCaptureRate(data: any) { saveCaptureRate(data: any) {
return sessionService.saveCaptureRate(data) return sessionService.saveCaptureRate(data)
.then(data => data.json()) .then(data => data.json())

View file

@ -13,27 +13,52 @@ const defaultDurationFilter = {
countType: 'sec' countType: 'sec'
} }
const negativeExceptions = {
4: ['-04:30'],
3: ['-03:30'],
}
const exceptions = {
3: ['+03:30'],
4: ['+04:30'],
5: ['+05:30', '+05:45'],
6: ['+06:30'],
9: ['+09:30']
}
export const generateGMTZones = (): Timezone[] => { export const generateGMTZones = (): Timezone[] => {
const timezones: Timezone[] = []; const timezones: Timezone[] = [];
const positiveNumbers = [...Array(12).keys()]; const positiveNumbers = [...Array(13).keys()];
const negativeNumbers = [...Array(12).keys()].reverse(); const negativeNumbers = [...Array(13).keys()].reverse();
negativeNumbers.pop(); // remove trailing zero since we have one in positive numbers array negativeNumbers.pop(); // remove trailing zero since we have one in positive numbers array
const combinedArray = [...negativeNumbers, ...positiveNumbers]; const combinedArray = [...negativeNumbers, ...positiveNumbers];
for (let i = 0; i < combinedArray.length; i++) { for (let i = 0; i < combinedArray.length; i++) {
let symbol = i < 11 ? '-' : '+'; let symbol = i < 12 ? '-' : '+';
let isUTC = i === 11; let isUTC = i === 12;
let value = String(combinedArray[i]).padStart(2, '0'); const item = combinedArray[i]
let value = String(item).padStart(2, '0');
let tz = `UTC ${symbol}${String(combinedArray[i]).padStart(2, '0')}:00`; let tz = `UTC ${symbol}${String(item).padStart(2, '0')}:00`;
let dropdownValue = `UTC${symbol}${value}`; let dropdownValue = `UTC${symbol}${value}`;
timezones.push({ label: tz, value: isUTC ? 'UTC' : dropdownValue }); timezones.push({ label: tz, value: isUTC ? 'UTC' : dropdownValue });
// @ts-ignore
const negativeMatch = negativeExceptions[item], positiveMatch = exceptions[item]
if (i < 11 && negativeMatch) {
negativeMatch.forEach((str: string) => {
timezones.push({ label: `UTC ${str}`, value: `UTC${str}`})
})
} else if (i > 11 && positiveMatch) {
positiveMatch.forEach((str: string) => {
timezones.push({ label: `UTC ${str}`, value: `UTC${str}`})
})
}
} }
timezones.splice(17, 0, { label: 'GMT +05:30', value: 'UTC+05:30' });
return timezones; return timezones;
}; };