Add configuration to disable relative date markers in timeline (#7405)

* add disabler elative dates setting

Signed-off-by: Kerry Archibald <kerrya@element.io>

* test existing DateSeparator

Signed-off-by: Kerry Archibald <kerrya@element.io>

* use full date format when TimelineDisableRelativeDates is truthy

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add comment

Signed-off-by: Kerry Archibald <kerrya@element.io>

* flip timelineDisableRelativeDates -> timelineEnableRelativeDates to fit convention

Signed-off-by: Kerry Archibald <kerrya@element.io>

* mock date constructor in test

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2021-12-21 10:08:22 +01:00 committed by GitHub
parent b90a0c443d
commit 61e3c38b19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 142 additions and 4 deletions

View file

@ -20,6 +20,8 @@ import React from 'react';
import { _t } from '../../../languageHandler';
import { formatFullDateNoTime } from '../../../DateUtils';
import { replaceableComponent } from "../../../utils/replaceableComponent";
import SettingsStore from '../../../settings/SettingsStore';
import { UIFeature } from '../../../settings/UIFeature';
function getDaysArray(): string[] {
return [
@ -42,9 +44,10 @@ interface IProps {
export default class DateSeparator extends React.Component<IProps> {
private getLabel() {
const date = new Date(this.props.ts);
const disableRelativeTimestamps = !SettingsStore.getValue(UIFeature.TimelineEnableRelativeDates);
// During the time the archive is being viewed, a specific day might not make sense, so we return the full date
if (this.props.forExport) return formatFullDateNoTime(date);
if (this.props.forExport || disableRelativeTimestamps) return formatFullDateNoTime(date);
const today = new Date();
const yesterday = new Date();
@ -63,11 +66,12 @@ export default class DateSeparator extends React.Component<IProps> {
}
render() {
const label = this.getLabel();
// ARIA treats <hr/>s as separators, here we abuse them slightly so manually treat this entire thing as one
// tab-index=-1 to allow it to be focusable but do not add tab stop for it, primarily for screen readers
return <h2 className="mx_DateSeparator" role="separator" tabIndex={-1} aria-label={this.getLabel()}>
return <h2 className="mx_DateSeparator" role="separator" tabIndex={-1} aria-label={label}>
<hr role="none" />
<div aria-hidden="true">{ this.getLabel() }</div>
<div aria-hidden="true">{ label }</div>
<hr role="none" />
</h2>;
}

View file

@ -965,4 +965,8 @@ export const SETTINGS: {[setting: string]: ISetting} = {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
[UIFeature.TimelineEnableRelativeDates]: {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
};

View file

@ -32,6 +32,7 @@ export enum UIFeature {
Communities = "UIFeature.communities",
AdvancedSettings = "UIFeature.advancedSettings",
RoomHistorySettings = "UIFeature.roomHistorySettings",
TimelineEnableRelativeDates = "UIFeature.timelineEnableRelativeDates"
}
export enum UIComponent {