Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit 071ccbd

Browse files
authored
feat: optional user defined ms clarity setup (#285)
1 parent c1830f8 commit 071ccbd

File tree

5 files changed

+73
-40
lines changed

5 files changed

+73
-40
lines changed

src/@types/parseable/api/about.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ export type AboutData = {
1414
grpcPort: number;
1515
oidcActive: boolean;
1616
cache: string;
17+
analytics: {
18+
clarityTag: string;
19+
}
1720
};

src/components/Navbar/infoModal.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const InfoModal: FC<InfoModalProps> = (props) => {
1616
const { opened, close } = props;
1717

1818
const { getAboutData, getAboutIsError, getAboutIsLoading } = useAbout();
19-
const [, setAppStore] = useAppStore((_store) => null);
19+
const [analytics, setAppStore] = useAppStore((store) => store.instanceConfig?.analytics);
2020
const llmStatus = useMemo(() => {
2121
let status = 'LLM API Key not set';
2222
if (getAboutData?.data?.llmActive) {
@@ -114,7 +114,9 @@ const InfoModal: FC<InfoModalProps> = (props) => {
114114
<Box className={aboutTextInnerBox}>
115115
<Text className={aboutTextKey}>Store</Text>
116116
<Stack style={{ flexDirection: 'row', alignItems: 'center' }} gap={4}>
117-
<Text className={aboutTextValue} style={{width: '100%'}}>{getAboutData?.data?.store?.type}</Text>
117+
<Text className={aboutTextValue} style={{ width: '100%' }}>
118+
{getAboutData?.data?.store?.type}
119+
</Text>
118120
<Tooltip label={getAboutData?.data?.store?.path}>
119121
<IconInfoCircle style={{ cursor: 'pointer' }} size="1.2rem" color="gray" stroke={1.5} />
120122
</Tooltip>
@@ -128,6 +130,10 @@ const InfoModal: FC<InfoModalProps> = (props) => {
128130
<Text className={aboutTextKey}>LLM Status</Text>
129131
<Text className={aboutTextValue}>{llmStatus}</Text>
130132
</Box>
133+
<Box className={aboutTextInnerBox}>
134+
<Text className={aboutTextKey}>Usage Analytics</Text>
135+
<Text className={aboutTextValue}>{analytics?.clarityTag ? 'Tracking (MS Clarity)' : 'Not Tracking'}</Text>
136+
</Box>
131137
</Box>
132138
</>
133139
) : null}

src/layouts/MainLayout/index.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@ import { PrimaryHeader } from '@/components/Header';
22
import Navbar from '@/components/Navbar';
33
import { NAVBAR_WIDTH, PRIMARY_HEADER_HEIGHT } from '@/constants/theme';
44
import { Box } from '@mantine/core';
5-
import { useCallback, useEffect, type FC } from 'react';
5+
import { useCallback, useEffect, useState, type FC } from 'react';
66
import { Outlet } from 'react-router-dom';
77
import { heights } from '@/components/Mantine/sizing';
88
import { useAppStore, appStoreReducers } from './providers/AppProvider';
9+
import _ from 'lodash';
910

1011
const { toggleMaximize } = appStoreReducers;
1112

1213
const MainLayout: FC = () => {
1314
const [maximized, setAppStore] = useAppStore((store) => store.maximized);
15+
const [analytics] = useAppStore((store) => store.instanceConfig?.analytics);
16+
const [trackingScriptsAdded, setTrackingScriptsAdded] = useState<boolean>(false);
1417
const primaryHeaderHeight = !maximized ? PRIMARY_HEADER_HEIGHT : 0;
1518
const navbarWidth = !maximized ? NAVBAR_WIDTH : 0;
1619

17-
const handleEscKeyPress = useCallback((event: KeyboardEvent) => {
18-
if (event.key === 'Escape') {
19-
maximized && setAppStore(toggleMaximize);
20-
}
21-
}, [maximized]);
20+
const handleEscKeyPress = useCallback(
21+
(event: KeyboardEvent) => {
22+
if (event.key === 'Escape') {
23+
maximized && setAppStore(toggleMaximize);
24+
}
25+
},
26+
[maximized],
27+
);
2228

2329
useEffect(() => {
2430
window.addEventListener('keydown', handleEscKeyPress);
@@ -27,6 +33,19 @@ const MainLayout: FC = () => {
2733
};
2834
}, [maximized]);
2935

36+
useEffect(() => {
37+
if (analytics && _.isString(analytics.clarityTag) && !_.isEmpty(analytics.clarityTag) && !trackingScriptsAdded) {
38+
const script = document.createElement('script');
39+
script.type = 'text/javascript';
40+
script.innerHTML = `(function(c,l,a,r,i,t,y){ c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); })(window, document, "clarity", "script", "${analytics.clarityTag}");`;
41+
document.body.appendChild(script);
42+
setTrackingScriptsAdded(true);
43+
return () => {
44+
document.body.removeChild(script);
45+
};
46+
}
47+
}, [analytics]);
48+
3049
return (
3150
<Box style={{ width: '100vw', minWidth: 1000 }}>
3251
<PrimaryHeader />

src/layouts/MainLayout/providers/AppProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type AppStore = {
2929
streamSpecificUserAccess: string[] | null;
3030
instanceConfig: AboutData | null;
3131
isStandAloneMode: boolean | null;
32-
savedFilters: SavedFilterType[] | null; // null to verify whether filters have been fetched or not
32+
savedFilters: SavedFilterType[] | null; // null to verify whether filters have been fetched or not
3333
activeSavedFilters: SavedFilterType[]; // stream specific
3434
};
3535

src/pages/Login/styles/Login.module.css

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,71 @@
44
width: 30vw;
55
background: radial-gradient(circle at 78.7% 87.8%, #FFFFFF 70%, #E1EAEE 60%);
66
padding: 20px;
7-
}
8-
9-
@media (max-width: 768px) {
7+
}
8+
9+
@media (max-width: 768px) {
1010
.sideContainer {
11-
display: none;
11+
display: none;
1212
}
13-
}
14-
15-
.container {
13+
}
14+
15+
.container {
1616
position: relative;
1717
flex: 1;
1818
display: flex;
1919
align-items: center;
2020
justify-content: center;
2121
background-repeat: no-repeat;
2222
background-position: top center;
23-
}
24-
25-
.formContainer {
23+
}
24+
25+
.formContainer {
2626
position: relative;
2727
padding: 24px;
2828
border-radius: 4px;
2929
box-shadow: 0 0 24px 0 rgba(0, 0, 0, 0.2);
3030
border: 1px solid #D4D4D4;
31-
width: 20rem;
31+
width: 22rem;
3232
display: flex;
3333
flex-direction: column;
3434
align-items: center;
35-
}
36-
37-
.formInput {
35+
}
36+
37+
.formInput {
3838
width: 100%;
39-
}
40-
41-
.titleStyle {
39+
}
40+
41+
.titleStyle {
4242
color: #10143E;
4343
font-weight: 700;
4444
font-size: 24px;
45-
}
46-
47-
.descriptionStyle {
45+
}
46+
47+
.descriptionStyle {
4848
text-align: center;
4949
font-size: 14px;
5050
color: #828282;
51-
}
52-
53-
.errorStyle {
51+
}
52+
53+
.errorStyle {
5454
color: #FC466B;
55-
}
56-
57-
.loginBtnStyle {
55+
}
56+
57+
.loginBtnStyle {
5858
width: 100%;
5959
background-color: #545BEB;
60+
6061
&:hover {
6162
background-color: #FC466B;
6263
}
63-
}
64+
}
6465

65-
.loginBtnStyle:disabled,
66-
.loginBtnStyle:disabled:hover
67-
{
66+
.loginBtnStyle:disabled,
67+
.loginBtnStyle:disabled:hover {
6868
background-color: var(--mantine-color-gray-4);
69-
}
69+
}
70+
71+
.consentDescription {
72+
font-size: 0.66rem;
73+
color: var(--mantine-color-gray-6);
74+
}

0 commit comments

Comments
 (0)