Show all labs even if incompatible, with appropriate tooltip explaining requirements (#10369)
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
209b65243a
commit
e3930fb8b0
@@ -23,41 +23,18 @@ import { SettingLevel } from "../../../../../settings/SettingLevel";
|
||||
import SdkConfig from "../../../../../SdkConfig";
|
||||
import BetaCard from "../../../beta/BetaCard";
|
||||
import SettingsFlag from "../../../elements/SettingsFlag";
|
||||
import { defaultWatchManager, LabGroup, labGroupNames } from "../../../../../settings/Settings";
|
||||
import { LabGroup, labGroupNames } from "../../../../../settings/Settings";
|
||||
import { EnhancedMap } from "../../../../../utils/maps";
|
||||
import { arrayHasDiff } from "../../../../../utils/arrays";
|
||||
|
||||
interface State {
|
||||
labs: string[];
|
||||
betas: string[];
|
||||
}
|
||||
|
||||
export default class LabsUserSettingsTab extends React.Component<{}, State> {
|
||||
private readonly features = SettingsStore.getFeatureSettingNames();
|
||||
export default class LabsUserSettingsTab extends React.Component<{}> {
|
||||
private readonly labs: string[];
|
||||
private readonly betas: string[];
|
||||
|
||||
public constructor(props: {}) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
betas: [],
|
||||
labs: [],
|
||||
};
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
this.features.forEach((feature) => {
|
||||
defaultWatchManager.watchSetting(feature, null, this.onChange);
|
||||
});
|
||||
this.onChange();
|
||||
}
|
||||
|
||||
public componentWillUnmount(): void {
|
||||
defaultWatchManager.unwatchSetting(this.onChange);
|
||||
}
|
||||
|
||||
private onChange = (): void => {
|
||||
const features = SettingsStore.getFeatureSettingNames().filter((f) => SettingsStore.isEnabled(f));
|
||||
const [_labs, betas] = features.reduce(
|
||||
const features = SettingsStore.getFeatureSettingNames();
|
||||
const [labs, betas] = features.reduce(
|
||||
(arr, f) => {
|
||||
arr[SettingsStore.getBetaInfo(f) ? 1 : 0].push(f);
|
||||
return arr;
|
||||
@@ -65,18 +42,20 @@ export default class LabsUserSettingsTab extends React.Component<{}, State> {
|
||||
[[], []] as [string[], string[]],
|
||||
);
|
||||
|
||||
const labs = SdkConfig.get("show_labs_settings") ? _labs : [];
|
||||
if (arrayHasDiff(labs, this.state.labs) || arrayHasDiff(betas, this.state.betas)) {
|
||||
this.setState({ labs, betas });
|
||||
this.labs = labs;
|
||||
this.betas = betas;
|
||||
|
||||
if (!SdkConfig.get("show_labs_settings")) {
|
||||
this.labs = [];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
let betaSection: JSX.Element | undefined;
|
||||
if (this.state.betas.length) {
|
||||
if (this.betas.length) {
|
||||
betaSection = (
|
||||
<div data-testid="labs-beta-section" className="mx_SettingsTab_section">
|
||||
{this.state.betas.map((f) => (
|
||||
{this.betas.map((f) => (
|
||||
<BetaCard key={f} featureId={f} />
|
||||
))}
|
||||
</div>
|
||||
@@ -84,9 +63,9 @@ export default class LabsUserSettingsTab extends React.Component<{}, State> {
|
||||
}
|
||||
|
||||
let labsSections: JSX.Element | undefined;
|
||||
if (this.state.labs.length) {
|
||||
if (this.labs.length) {
|
||||
const groups = new EnhancedMap<LabGroup, JSX.Element[]>();
|
||||
this.state.labs.forEach((f) => {
|
||||
this.labs.forEach((f) => {
|
||||
groups
|
||||
.getOrCreate(SettingsStore.getLabGroup(f), [])
|
||||
.push(<SettingsFlag level={SettingLevel.DEVICE} name={f} key={f} />);
|
||||
|
||||
@@ -29,7 +29,6 @@ import { UserTab } from "../../../dialogs/UserTab";
|
||||
import { OpenToTabPayload } from "../../../../../dispatcher/payloads/OpenToTabPayload";
|
||||
import { Action } from "../../../../../dispatcher/actions";
|
||||
import SdkConfig from "../../../../../SdkConfig";
|
||||
import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
|
||||
import { showUserOnboardingPage } from "../../../user-onboarding/UserOnboardingPage";
|
||||
|
||||
interface IProps {
|
||||
@@ -37,7 +36,6 @@ interface IProps {
|
||||
}
|
||||
|
||||
interface IState {
|
||||
disablingReadReceiptsSupported: boolean;
|
||||
autocompleteDelay: string;
|
||||
readMarkerInViewThresholdMs: string;
|
||||
readMarkerOutOfViewThresholdMs: string;
|
||||
@@ -50,10 +48,7 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
|
||||
|
||||
private static KEYBINDINGS_SETTINGS = ["ctrlFForSearch"];
|
||||
|
||||
private static PRESENCE_SETTINGS = [
|
||||
"sendTypingNotifications",
|
||||
// sendReadReceipts - handled specially due to server needing support
|
||||
];
|
||||
private static PRESENCE_SETTINGS = ["sendReadReceipts", "sendTypingNotifications"];
|
||||
|
||||
private static COMPOSER_SETTINGS = [
|
||||
"MessageComposerInput.autoReplaceEmoji",
|
||||
@@ -101,7 +96,6 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
disablingReadReceiptsSupported: false,
|
||||
autocompleteDelay: SettingsStore.getValueAt(SettingLevel.DEVICE, "autocompleteDelay").toString(10),
|
||||
readMarkerInViewThresholdMs: SettingsStore.getValueAt(
|
||||
SettingLevel.DEVICE,
|
||||
@@ -114,16 +108,6 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
|
||||
};
|
||||
}
|
||||
|
||||
public async componentDidMount(): Promise<void> {
|
||||
const cli = MatrixClientPeg.get();
|
||||
|
||||
this.setState({
|
||||
disablingReadReceiptsSupported:
|
||||
(await cli.doesServerSupportUnstableFeature("org.matrix.msc2285.stable")) ||
|
||||
(await cli.isVersionSupported("v1.4")),
|
||||
});
|
||||
}
|
||||
|
||||
private onAutocompleteDelayChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
this.setState({ autocompleteDelay: e.target.value });
|
||||
SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value);
|
||||
@@ -140,10 +124,7 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
|
||||
};
|
||||
|
||||
private renderGroup(settingIds: string[], level = SettingLevel.ACCOUNT): React.ReactNodeArray {
|
||||
return settingIds.map((i) => {
|
||||
const disabled = !SettingsStore.isEnabled(i);
|
||||
return <SettingsFlag key={i} name={i} level={level} disabled={disabled} />;
|
||||
});
|
||||
return settingIds.map((i) => <SettingsFlag key={i} name={i} level={level} />);
|
||||
}
|
||||
|
||||
private onKeyboardShortcutsClicked = (): void => {
|
||||
@@ -205,14 +186,6 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
|
||||
<span className="mx_SettingsTab_subsectionText">
|
||||
{_t("Share your activity and status with others.")}
|
||||
</span>
|
||||
<SettingsFlag
|
||||
disabled={
|
||||
!this.state.disablingReadReceiptsSupported && SettingsStore.getValue("sendReadReceipts") // Make sure the feature can always be enabled
|
||||
}
|
||||
disabledDescription={_t("Your server doesn't support disabling sending read receipts.")}
|
||||
name="sendReadReceipts"
|
||||
level={SettingLevel.ACCOUNT}
|
||||
/>
|
||||
{this.renderGroup(PreferencesUserSettingsTab.PRESENCE_SETTINGS)}
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user