mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-12-05 11:38:00 +00:00
Refactor className and children to component properties instead och view model snapshots in shared components (#32711)
* Refactor className? to component property in EncryptionEventView * Refactor extraClassNames to default react className as component property for DecryptionFailureBodyView * Refactor className to component property for MessageTimestampView * Refactor className and children to component properties for ReactionsRowButton * Refactor className to component property for DisambiguatedProfile * Refactor className to a component property in DateSeparatorView * Fix for lint errors and EncryptionEventView unsupported icon color * EncryptionEventView fix for icon color css specificity/order
This commit is contained in:
@@ -78,13 +78,11 @@ export class EncryptionEventViewModel
|
||||
props: EncryptionEventViewModelProps,
|
||||
isEncrypted: boolean,
|
||||
): EncryptionEventViewSnapshotInterface {
|
||||
// Keep legacy class names for compatibility with existing timeline layout and styling.
|
||||
const newSnapshot: EncryptionEventViewSnapshotInterface = {
|
||||
state: EncryptionEventState.CHANGED,
|
||||
encryptedStateEvents: undefined,
|
||||
userName: undefined,
|
||||
timestamp: props.timestamp,
|
||||
className: "mx_EventTileBubble mx_cryptoEvent mx_cryptoEvent_icon",
|
||||
};
|
||||
|
||||
const content = props.mxEvent.getContent<RoomEncryptionEventContent>();
|
||||
@@ -113,8 +111,6 @@ export class EncryptionEventViewModel
|
||||
newSnapshot.state = EncryptionEventState.DISABLE_ATTEMPT;
|
||||
} else {
|
||||
newSnapshot.state = EncryptionEventState.UNSUPPORTED;
|
||||
// Unsupported branch matches legacy EncryptionEvent class usage (no icon class).
|
||||
newSnapshot.className = "mx_EventTileBubble mx_cryptoEvent";
|
||||
}
|
||||
|
||||
return newSnapshot;
|
||||
|
||||
@@ -22,10 +22,6 @@ export interface DecryptionFailureBodyViewModelProps {
|
||||
* The local device verification state.
|
||||
*/
|
||||
verificationState?: boolean;
|
||||
/**
|
||||
* Extra CSS classes to apply to the component
|
||||
*/
|
||||
extraClassNames?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,30 +58,21 @@ export class DecryptionFailureBodyViewModel
|
||||
/**
|
||||
* @param decryptionFailureCode - The decryption failure code for the event.
|
||||
* @param verificationState - The local device verification state.
|
||||
* @param extraClassNames - Extra CSS classes to apply to the component.
|
||||
*/
|
||||
private static readonly computeSnapshot = (
|
||||
decryptionFailureCode: DecryptionFailureCode | null,
|
||||
verificationState?: boolean,
|
||||
extraClassNames?: string[],
|
||||
): DecryptionFailureBodyViewSnapshotInterface => {
|
||||
// Keep mx_DecryptionFailureBody and mx_EventTile_content to support the compatibility with existing timeline and the all the layout
|
||||
const defaultClassNames = ["mx_DecryptionFailureBody", "mx_EventTile_content"];
|
||||
return {
|
||||
decryptionFailureReason: DecryptionFailureBodyViewModel.getDecryptionReasonFromCode(decryptionFailureCode),
|
||||
isLocalDeviceVerified: verificationState,
|
||||
extraClassNames: extraClassNames ? defaultClassNames.concat(extraClassNames) : defaultClassNames,
|
||||
};
|
||||
};
|
||||
|
||||
public constructor(props: DecryptionFailureBodyViewModelProps) {
|
||||
super(
|
||||
props,
|
||||
DecryptionFailureBodyViewModel.computeSnapshot(
|
||||
props.decryptionFailureCode,
|
||||
props.verificationState,
|
||||
props.extraClassNames,
|
||||
),
|
||||
DecryptionFailureBodyViewModel.computeSnapshot(props.decryptionFailureCode, props.verificationState),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,14 +91,12 @@ export class MessageTimestampViewModel
|
||||
receivedAt = formatFullDate(receivedDate, props.showTwelveHour);
|
||||
}
|
||||
|
||||
// Keep mx_MessageTimestamp for compatibility with the existing timeline and layout.
|
||||
return {
|
||||
ts: timestamp,
|
||||
tsSentAt: sentAt,
|
||||
tsReceivedAt: receivedAt,
|
||||
inhibitTooltip: props.inhibitTooltip,
|
||||
href: props.href,
|
||||
className: "mx_MessageTimestamp",
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { type MouseEvent, type MouseEventHandler, type ReactNode } from "react";
|
||||
import { type MouseEvent, type MouseEventHandler } from "react";
|
||||
import {
|
||||
BaseViewModel,
|
||||
type ReactionsRowViewSnapshot,
|
||||
@@ -41,10 +41,6 @@ export interface ReactionsRowViewModelProps {
|
||||
* Optional callback invoked on add-reaction button context-menu.
|
||||
*/
|
||||
onAddReactionContextMenu?: MouseEventHandler<HTMLButtonElement>;
|
||||
/**
|
||||
* Reaction row children (typically reaction buttons).
|
||||
*/
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
interface InternalProps extends ReactionsRowViewModelProps {
|
||||
@@ -59,18 +55,16 @@ export class ReactionsRowViewModel
|
||||
props: InternalProps,
|
||||
): Pick<
|
||||
ReactionsRowViewSnapshot,
|
||||
"isVisible" | "showAllButtonVisible" | "showAddReactionButton" | "addReactionButtonActive" | "children"
|
||||
"isVisible" | "showAllButtonVisible" | "showAddReactionButton" | "addReactionButtonActive"
|
||||
> => ({
|
||||
isVisible: props.isActionable && props.reactionGroupCount > 0,
|
||||
showAllButtonVisible: props.reactionGroupCount > MAX_ITEMS_WHEN_LIMITED + 1 && !props.showAll,
|
||||
showAddReactionButton: props.canReact,
|
||||
addReactionButtonActive: !!props.addReactionButtonActive,
|
||||
children: props.children,
|
||||
});
|
||||
|
||||
private static readonly computeSnapshot = (props: InternalProps): ReactionsRowViewSnapshot => ({
|
||||
ariaLabel: _t("common|reactions"),
|
||||
className: "mx_ReactionsRow",
|
||||
showAllButtonLabel: _t("action|show_all"),
|
||||
addReactionButtonLabel: _t("timeline|reactions|add_reaction_prompt"),
|
||||
addReactionButtonVisible: false,
|
||||
@@ -136,15 +130,6 @@ export class ReactionsRowViewModel
|
||||
this.snapshot.merge({ addReactionButtonActive });
|
||||
}
|
||||
|
||||
public setChildren(children?: ReactNode): void {
|
||||
this.props = {
|
||||
...this.props,
|
||||
children,
|
||||
};
|
||||
|
||||
this.snapshot.merge({ children });
|
||||
}
|
||||
|
||||
public setAddReactionHandlers({
|
||||
onAddReactionClick,
|
||||
onAddReactionContextMenu,
|
||||
|
||||
@@ -66,10 +66,6 @@ export interface DisambiguatedProfileViewModelProps {
|
||||
* Optional click handler for the profile.
|
||||
*/
|
||||
onClick?: DisambiguatedProfileViewActions["onClick"];
|
||||
/**
|
||||
* Optional CSS class name to apply to the profile.
|
||||
*/
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +79,7 @@ export class DisambiguatedProfileViewModel
|
||||
private static readonly computeSnapshot = (
|
||||
props: DisambiguatedProfileViewModelProps,
|
||||
): DisambiguatedProfileViewSnapshot => {
|
||||
const { member, fallbackName, colored, emphasizeDisplayName, withTooltip, className } = props;
|
||||
const { member, fallbackName, colored, emphasizeDisplayName, withTooltip } = props;
|
||||
|
||||
// Compute display name
|
||||
const displayName = member?.rawDisplayName || fallbackName;
|
||||
@@ -123,7 +119,6 @@ export class DisambiguatedProfileViewModel
|
||||
return {
|
||||
displayName,
|
||||
colorClass,
|
||||
className,
|
||||
displayIdentifier,
|
||||
title,
|
||||
emphasizeDisplayName,
|
||||
|
||||
@@ -68,7 +68,6 @@ export class DateSeparatorViewModel
|
||||
|
||||
super(props, {
|
||||
label: DateSeparatorViewModel.computeLabel(props, relativeDatesEnabled),
|
||||
className: "mx_TimelineSeparator",
|
||||
});
|
||||
|
||||
this.relativeDatesEnabled = relativeDatesEnabled;
|
||||
@@ -101,7 +100,6 @@ export class DateSeparatorViewModel
|
||||
const label = DateSeparatorViewModel.computeLabel(this.props, this.relativeDatesEnabled);
|
||||
return {
|
||||
label,
|
||||
className: "mx_TimelineSeparator",
|
||||
jumpToEnabled: this.jumpToDateEnabled && !this.props.forExport,
|
||||
jumpFromDate: formatDateForInput(new Date(this.props.ts)),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user