Skip to content
Merged
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
1 change: 1 addition & 0 deletions frontend/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const config: CodegenConfig = {
preset: "client",
config: {
useTypeImports: true,
enumsAsTypes: true,
// By default, unknown scalars are generated as `any`. This is not ideal for catching potential bugs.
defaultScalarType: "unknown",
scalars: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/BrowserSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useTranslation } from "react-i18next";
import { useMutation } from "urql";

import { type FragmentType, graphql, useFragment } from "../gql";
import { DeviceType } from "../gql/graphql";
import type { DeviceType } from "../gql/graphql";

import DateTime from "./DateTime";
import EndSessionButton from "./Session/EndSessionButton";
Expand Down Expand Up @@ -97,7 +97,7 @@ const BrowserSession: React.FC<Props> = ({ session, isCurrent }) => {

const onSessionEnd = useEndBrowserSession(data.id, isCurrent);

const deviceType = data.userAgent?.deviceType ?? DeviceType.Unknown;
const deviceType = data.userAgent?.deviceType ?? "UNKNOWN";

let deviceName: string | null = null;
let clientName: string | null = null;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/CompatSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const CompatSession: React.FC<{
? simplifyUrl(data.ssoLogin.redirectUri)
: undefined;

const deviceType = data.userAgent?.deviceType ?? DeviceType.Unknown;
const deviceType = data.userAgent?.deviceType ?? "UNKNOWN";

const deviceName =
data.userAgent?.model ??
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/OAuth2Session.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { beforeAll, describe, expect, it } from "vitest";
import { never } from "wonka";

import { makeFragmentData } from "../gql";
import { Oauth2ApplicationType } from "../gql/graphql";
import type { Oauth2ApplicationType } from "../gql/graphql";
import { mockLocale } from "../test-utils/mockLocale";
import { DummyRouter } from "../test-utils/router";

Expand All @@ -34,7 +34,7 @@ describe("<OAuth2Session />", () => {
clientId: "test-client-id",
clientName: "Element",
clientUri: "https://element.io",
applicationType: Oauth2ApplicationType.Web,
applicationType: "WEB" as Oauth2ApplicationType,
},
};

Expand Down Expand Up @@ -80,7 +80,7 @@ describe("<OAuth2Session />", () => {
finishedAt,
client: {
...defaultSession.client,
applicationType: Oauth2ApplicationType.Native,
applicationType: "NATIVE",
},
},
FRAGMENT,
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/OAuth2Session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next";
import { useMutation } from "urql";

import { type FragmentType, graphql, useFragment } from "../gql";
import { DeviceType, Oauth2ApplicationType } from "../gql/graphql";
import type { DeviceType, Oauth2ApplicationType } from "../gql/graphql";
import { getDeviceIdFromScope } from "../utils/deviceIdFromScope";

import DateTime from "./DateTime";
Expand Down Expand Up @@ -58,13 +58,13 @@ export const END_SESSION_MUTATION = graphql(/* GraphQL */ `
const getDeviceTypeFromClientAppType = (
appType?: Oauth2ApplicationType | null,
): DeviceType => {
if (appType === Oauth2ApplicationType.Web) {
return DeviceType.Pc;
if (appType === "WEB") {
return "PC";
}
if (appType === Oauth2ApplicationType.Native) {
return DeviceType.Mobile;
if (appType === "NATIVE") {
return "MOBILE";
}
return DeviceType.Unknown;
return "UNKNOWN";
};

type Props = {
Expand All @@ -88,7 +88,7 @@ const OAuth2Session: React.FC<Props> = ({ session }) => {
: undefined;

const deviceType =
(data.userAgent?.deviceType === DeviceType.Unknown
(data.userAgent?.deviceType === "UNKNOWN"
? null
: data.userAgent?.deviceType) ??
getDeviceTypeFromClientAppType(data.client.applicationType);
Expand Down
15 changes: 5 additions & 10 deletions frontend/src/components/Session/DeviceTypeIcon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ const meta = {
component: DeviceTypeIcon,
tags: ["autodocs"],
args: {
deviceType: DeviceType.Unknown,
deviceType: "UNKNOWN",
},
argTypes: {
deviceType: {
control: "select",
options: [
DeviceType.Unknown,
DeviceType.Pc,
DeviceType.Mobile,
DeviceType.Tablet,
],
options: ["UNKNOWN", "PC", "MOBILE", "TABLET"],
},
},
} satisfies Meta<typeof DeviceTypeIcon>;
Expand All @@ -37,16 +32,16 @@ export const Unknown: Story = {};

export const Pc: Story = {
args: {
deviceType: DeviceType.Pc,
deviceType: "PC",
},
};
export const Mobile: Story = {
args: {
deviceType: DeviceType.Mobile,
deviceType: "MOBILE",
},
};
export const Tablet: Story = {
args: {
deviceType: DeviceType.Tablet,
deviceType: "TABLET",
},
};
18 changes: 9 additions & 9 deletions frontend/src/components/Session/DeviceTypeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import IconBrowser from "@vector-im/compound-design-tokens/assets/web/icons/web-
import type { FunctionComponent, SVGProps } from "react";
import { useTranslation } from "react-i18next";

import { DeviceType } from "../../gql/graphql";
import type { DeviceType } from "../../gql/graphql";

import styles from "./DeviceTypeIcon.module.css";

const deviceTypeToIcon: Record<
DeviceType,
FunctionComponent<SVGProps<SVGSVGElement> & { title?: string | undefined }>
> = {
[DeviceType.Unknown]: IconUnknown,
[DeviceType.Pc]: IconComputer,
[DeviceType.Mobile]: IconMobile,
[DeviceType.Tablet]: IconBrowser,
UNKNOWN: IconUnknown,
PC: IconComputer,
MOBILE: IconMobile,
TABLET: IconBrowser,
};

const DeviceTypeIcon: React.FC<{ deviceType: DeviceType }> = ({
Expand All @@ -33,10 +33,10 @@ const DeviceTypeIcon: React.FC<{ deviceType: DeviceType }> = ({
const Icon = deviceTypeToIcon[deviceType];

const deviceTypeToLabel: Record<DeviceType, string> = {
[DeviceType.Unknown]: t("frontend.device_type_icon_label.unknown"),
[DeviceType.Pc]: t("frontend.device_type_icon_label.pc"),
[DeviceType.Mobile]: t("frontend.device_type_icon_label.mobile"),
[DeviceType.Tablet]: t("frontend.device_type_icon_label.tablet"),
UNKNOWN: t("frontend.device_type_icon_label.unknown"),
PC: t("frontend.device_type_icon_label.pc"),
MOBILE: t("frontend.device_type_icon_label.mobile"),
TABLET: t("frontend.device_type_icon_label.tablet"),
};

const label = deviceTypeToLabel[deviceType];
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/components/SessionCard/SessionCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import IconSignOut from "@vector-im/compound-design-tokens/assets/web/icons/sign
import { Button } from "@vector-im/compound-web";
import { useTranslation } from "react-i18next";

import { DeviceType } from "../../gql/graphql";
import type { DeviceType } from "../../gql/graphql";

import * as Card from "./SessionCard";

Expand Down Expand Up @@ -51,10 +51,13 @@ const meta = {
disabled: false,
deviceName: "MacBook Pro 16",
clientName: "Firefox",
deviceType: DeviceType.Pc,
deviceType: "PC",
},
argTypes: {
deviceType: { control: "select", options: Object.values(DeviceType) },
deviceType: {
control: "select",
options: ["PC", "MOBILE", "TABLET", "UNKNOWN"],
},
disabled: { control: "boolean" },
deviceName: { control: "text" },
clientName: { control: "text" },
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/UserGreeting/UserGreeting.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { Provider } from "urql";
import { delay, fromValue, pipe } from "wonka";

import { makeFragmentData } from "../../gql";
import {
type SetDisplayNameMutation,
SetDisplayNameStatus,
} from "../../gql/graphql";
import type { SetDisplayNameMutation } from "../../gql/graphql";

import UserGreeting, { CONFIG_FRAGMENT, FRAGMENT } from "./UserGreeting";

Expand All @@ -31,7 +28,7 @@ const Template: React.FC<{
fromValue({
data: {
setDisplayName: {
status: SetDisplayNameStatus.Set,
status: "SET",
user: { id: userId, matrix: { displayName } },
},
},
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/UserGreeting/UserGreeting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const UserGreeting: React.FC<Props> = ({ user, siteConfig }) => {

const result = await setDisplayName({ displayName, userId: data.id });

if (result.data?.setDisplayName.status === SetDisplayNameStatus.Set) {
if (result.data?.setDisplayName.status === "SET") {
setOpen(false);
}
};
Expand Down Expand Up @@ -163,8 +163,7 @@ const UserGreeting: React.FC<Props> = ({ user, siteConfig }) => {
<Form.Field
name="displayname"
serverInvalid={
setDisplayNameResult.data?.setDisplayName.status ===
SetDisplayNameStatus.Invalid
setDisplayNameResult.data?.setDisplayName.status === "INVALID"
}
>
<Form.Label>
Expand Down
Loading
Loading