Skip to content

Commit

Permalink
Feat/telegram metrics (#372)
Browse files Browse the repository at this point in the history
* update url

* update switch platform component position (#370)

* integrate telegram analyzer

* fix banner

---------

Co-authored-by: Cyrille <1618640+cyri113@users.noreply.github.com>
  • Loading branch information
mehdi-torabiv and cyri113 authored Jan 7, 2025
1 parent 3fb3536 commit de1bcf8
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TcGdriveIntegration from './TcGdriveIntegration';
import TcGithubIntegration from './TcGithubIntegration';
import TcMediaWiki from './TcMediaWiki';
import TcNotionIntegration from './TcNotionIntegration';
import TcTelegram from './tcTelegram/TcTelegram';
import TcTelegram from './TcTelegram/TcTelegram';
import TcButton from '../../shared/TcButton';
import TcCard from '../../shared/TcCard';
import TcText from '../../shared/TcText';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { CircularProgress } from '@mui/material';

import useAppStore from '@/store/useStore';

import { truncateCenter } from '@/helpers/helper';
import { StorageService } from '@/services/StorageService';
import { IntegrationPlatform } from '@/utils/enums';
import { IDiscordModifiedCommunity, IPlatformProps } from '@/utils/interfaces';
Expand Down
3 changes: 1 addition & 2 deletions src/components/layouts/SwitchPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const SwitchPlatform = () => {
const fetchedPlatforms =
community?.platforms.filter(
({ name, disconnectedAt }) =>
(name.includes('discord') || name.includes('discourse')) &&
!disconnectedAt
['discord', 'discourse', 'telegram'].some((platform) => name.includes(platform)) && !disconnectedAt
) || [];

setPlatforms(fetchedPlatforms);
Expand Down
14 changes: 10 additions & 4 deletions src/components/layouts/shared/TcPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ function TcPrompt() {
message:
'Data extraction is in progress for Discourse. This process may take more than 6 hours to complete.',
}
: {
backgroundColor: 'bg-orange',
message: `Data processing is in progress for ${selectedPlatformData.name}. Please check back later.`,
}
: selectedPlatformData.name === 'telegram'
? {
backgroundColor: 'bg-orange',
message:
'Data extraction is in progress for Telegram. This process may take more than 6 hours to complete.',
}
: {
backgroundColor: 'bg-orange',
message: `Data processing is in progress for ${selectedPlatformData.name}. Please check back later.`,
}
: {
backgroundColor: 'bg-orange',
message: (
Expand Down
5 changes: 3 additions & 2 deletions src/components/pages/pageIndex/ActiveMemberComposition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const ActiveMemberComposition = () => {
const endDate: moment.Moment = moment().subtract(1, 'day');
const startDate: moment.Moment = moment(endDate).subtract(7, 'days');


const platformId = community?.platforms.find(
(platform) => platform.id === selectedPlatform
)?.id;
Expand Down Expand Up @@ -109,7 +110,7 @@ const ActiveMemberComposition = () => {
}, [activeMembers]);

return (
<div className='rounded-lg bg-white py-8 px-5 shadow-box'>
<div className='rounded-lg bg-white px-5 py-8 shadow-box'>
<div className='px-3'>
<div className='flex flex-col space-y-3 md:flex-row md:items-center md:justify-between md:space-y-0'>
<h3 className='pb-3 text-xl font-bold md:text-2xl'>
Expand All @@ -129,7 +130,7 @@ const ActiveMemberComposition = () => {
onClick={() => {
router.push('/statistics');
}}
className='py-2 px-[5rem]'
className='px-[5rem] py-2'
/>
</div>
</div>
Expand Down
16 changes: 13 additions & 3 deletions src/components/pages/pageIndex/HeatmapChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ const HeatmapChart = () => {
excludeCategories.length > 0 ? excludeCategories : undefined
);

updateHeatmapData(data);
} else if (platform && platform.name === 'telegram') {
const data = await fetchHeatmapData(
platform.id,
platform.name,
dateRange[0],
dateRange[1],
selectedZone
);

updateHeatmapData(data);
}
} catch (error) {
Expand Down Expand Up @@ -306,7 +316,7 @@ const HeatmapChart = () => {
Hourly messages summed over the selected time period.
</p>
</div>
<div className='flex w-full flex-col-reverse space-y-3 px-2.5 md:w-auto md:flex-row md:space-y-0 md:space-x-3'>
<div className='flex w-full flex-col-reverse space-y-3 px-2.5 md:w-auto md:flex-row md:space-x-3 md:space-y-0'>
<RangeSelect
options={communityActiveDates}
icon={<FiCalendar size={18} />}
Expand Down Expand Up @@ -336,15 +346,15 @@ const HeatmapChart = () => {
handleFetchHeatmapByChannels={handleFetchHeatmapByChannels}
/>
</div>
) : (
) : platform?.name === 'discourse' ? (
<div className='flex flex-wrap'>
<FilterByCategory
handleFetchHeatmapByCategories={
handleFetchHeatmapByCategories
}
/>
</div>
)}
) : null}
</div>
</div>
<div className='relative'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ActiveMemberBreakdown from './memberBreakdowns/activeMembers/ActiveMember
import StatisticalData from './StatisticalData';

export interface ActiveMembersComposition {
platformType: 'discord' | 'discourse';
platformType: 'discord' | 'discourse' | 'telegram';
activePeriod: number;
isPremiumGuild: boolean;
handleDateRange: (range: number) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import DisengagedMembersCompositionBreakdown from './memberBreakdowns/disengaged
import StatisticalData from './StatisticalData';

export interface DisengagedMembersComposition {
platformType: 'discord' | 'discourse';
platformType: 'discord' | 'discourse' | 'telegram';
activePeriod: number;
isPremiumGuild: boolean;
handleDateRange: (range: number) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/statistics/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import OnboardingMembersBreakdown from './memberBreakdowns/onboardingMembers/Onb
import StatisticalData from './StatisticalData';

export interface OnboardingProps {
platformType: 'discord' | 'discourse';
platformType: 'discord' | 'discourse' | 'telegram';
activePeriod: number;
isPremiumGuild: boolean;
handleDateRange: (range: number) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ const CustomTable: React.FC<CustomTableProps> = ({
</div>
) : column.id === 'joinedAt' ||
column.id === 'joined_at' ? (
formatDate(row.joinedAt ?? row.joined_at)
row.joinedAt ? formatDate(row.joinedAt) : '-'
) : (
row[column.id]
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const options: IActivityCompositionOptions[] = [
];

interface IAcriveMemberBreakdownProps {
platformType: 'discord' | 'discourse';
platformType: 'discord' | 'discourse' | 'telegram';
}

export default function ActiveMemberBreakdown({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const options: IActivityCompositionOptions[] = [
];

interface IDisengagedMembersCompositionBreakdown {
platformType: 'discord' | 'discourse';
platformType: 'discord' | 'discourse' | 'telegram';
}

export default function DisengagedMembersCompositionBreakdown({
Expand Down Expand Up @@ -262,7 +262,7 @@ export default function DisengagedMembersCompositionBreakdown({
)}
</div>
{fetchedData && fetchedData?.totalResults > 3 ? (
<div className='mt-2 mb-12 flex justify-center'>
<div className='mb-12 mt-2 flex justify-center'>
<TcButton
text={isExpanded ? 'Show less' : 'Show member breakdown'}
variant='outlined'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const options: IActivityCompositionOptions[] = [
];

interface IOnboardingMembersBreakdown {
platformType: 'discord' | 'discourse';
platformType: 'discord' | 'discourse' | 'telegram';
}

export default function OnboardingMembersBreakdown({
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ export function flattenChannels(

export function capitalizeFirstLetter(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
}
16 changes: 10 additions & 6 deletions src/pages/statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ const Statistics = () => {
'2': 'disengagedMembers',
};

const [activePlatform, setActivePlatform] = useState<'discord' | 'discourse'>(
'discord'
);
const [activePlatform, setActivePlatform] = useState<
'discord' | 'discourse' | 'telegram'
>('discord');
const [loading, setLoading] = useState<boolean>(true);
const [activeMemberDate, setActiveMemberDate] = useState(1);
const [onBoardingMemberDate, setOnBoardingMemberDate] = useState(1);
Expand All @@ -72,9 +72,13 @@ const Statistics = () => {
const platform = community?.platforms.find(
(platform) => platform.id === selectedPlatform
);
setActivePlatform(
platform?.name.includes('discord') ? 'discord' : 'discourse'
);
if (platform?.name === 'discord') {
setActivePlatform('discord');
} else if (platform?.name === 'discourse') {
setActivePlatform('discourse');
} else if (platform?.name === 'telegram') {
setActivePlatform('telegram');
}
}, [selectedPlatform]);

useEffect(() => {
Expand Down
18 changes: 12 additions & 6 deletions src/store/slices/breakdownsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const createBreakdownsSlice: StateCreator<IBreakdown> = (set, get) => ({
roles: [],
getActiveMemberCompositionTable: async (
platformId: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
activityComposition: string[],
roles?: IRolesPayload,
username?: string,
Expand Down Expand Up @@ -56,7 +56,9 @@ const createBreakdownsSlice: StateCreator<IBreakdown> = (set, get) => ({
const baseUrl =
platformType === 'discourse'
? `/discourse/member-activity/${platformId}/active-members-composition-table`
: `/member-activity/${platformId}/active-members-composition-table`;
: platformType === 'telegram'
? `/telegram/member-activity/${platformId}/active-members-composition-table`
: `/member-activity/${platformId}/active-members-composition-table`;

const url = `${baseUrl}?${params.toString()}`;

Expand All @@ -69,7 +71,7 @@ const createBreakdownsSlice: StateCreator<IBreakdown> = (set, get) => ({
},
getOnboardingMemberCompositionTable: async (
platformId: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
activityComposition: string[],
roles?: IRolesPayload,
username?: string,
Expand Down Expand Up @@ -113,7 +115,9 @@ const createBreakdownsSlice: StateCreator<IBreakdown> = (set, get) => ({
const baseUrl =
platformType === 'discourse'
? `/discourse/member-activity/${platformId}/active-members-onboarding-table`
: `/member-activity/${platformId}/active-members-onboarding-table`;
: platformType === 'telegram'
? `/telegram/member-activity/${platformId}/active-members-onboarding-table`
: `/member-activity/${platformId}/active-members-onboarding-table`;

const url = `${baseUrl}?${params.toString()}`;

Expand All @@ -126,7 +130,7 @@ const createBreakdownsSlice: StateCreator<IBreakdown> = (set, get) => ({
},
getDisengagedMembersCompositionTable: async (
platformId: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
activityComposition: string[],
roles?: IRolesPayload,
username?: string,
Expand Down Expand Up @@ -170,7 +174,9 @@ const createBreakdownsSlice: StateCreator<IBreakdown> = (set, get) => ({
const baseUrl =
platformType === 'discourse'
? `/discourse/member-activity/${platformId}/disengaged-members-composition-table`
: `/member-activity/${platformId}/disengaged-members-composition-table`;
: platformType === 'telegram'
? `/telegram/member-activity/${platformId}/disengaged-members-composition-table`
: `/member-activity/${platformId}/disengaged-members-composition-table`;

const url = `${baseUrl}?${params.toString()}`;

Expand Down
12 changes: 8 additions & 4 deletions src/store/slices/chartSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const chartSlice: StateCreator<ICharts> = (set, get) => ({
onboardingMembersLoading: false,
fetchHeatmapData: async (
platformId: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
startDate: string,
endDate: string,
timeZone: string,
Expand All @@ -32,7 +32,9 @@ const chartSlice: StateCreator<ICharts> = (set, get) => ({
const endpoint =
platformType === 'discourse'
? `/discourse/heatmaps/${platformId}/heatmap-chart`
: `/heatmaps/${platformId}/heatmap-chart`;
: platformType === 'telegram'
? `/telegram/heatmaps/${platformId}/heatmap-chart`
: `/heatmaps/${platformId}/heatmap-chart`;

set(() => ({ isLoading: true }));

Expand Down Expand Up @@ -71,12 +73,14 @@ const chartSlice: StateCreator<ICharts> = (set, get) => ({
platformId: string,
startDate: string,
endDate: string,
platformType: 'discord' | 'discourse'
platformType: 'discord' | 'discourse' | 'telegram'
) => {
const endpoint =
platformType === 'discourse'
? `/discourse/heatmaps/${platformId}/line-graph`
: `/heatmaps/${platformId}/line-graph`;
: platformType === 'telegram'
? `/telegram/heatmaps/${platformId}/line-graph`
: `/heatmaps/${platformId}/line-graph`;

try {
set(() => ({ interactionsLoading: true }));
Expand Down
7 changes: 5 additions & 2 deletions src/store/slices/memberInteractionSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const createHeatmapSlice: StateCreator<IMemberInteraction> = (set, get) => ({
memberInteractionRecords: [],
getMemberInteraction: async (
platformId: string,
platformType: 'discord' | 'discourse'
platformType: 'discord' | 'discourse' | 'telegram'
) => {
try {
const endpoint =
platformType === 'discourse'
? `/discourse/member-activity/${platformId}/members-interactions-network-graph`
: `/member-activity/${platformId}/members-interactions-network-graph`;
: platformType === 'telegram'
? `/telegram/member-activity/${platformId}/members-interactions-network-graph`
: `/member-activity/${platformId}/members-interactions-network-graph`;

set(() => ({ isLoading: true }));
const { data } = await axiosInstance.post(endpoint);
set({ memberInteractionRecords: [...data], isLoading: false });
Expand Down
6 changes: 3 additions & 3 deletions src/store/types/IBreakdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default interface IBreakdown {
roles: any[];
getActiveMemberCompositionTable: (
platformId: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
activityComposition: string[],
roles?: IRolesPayload,
username?: string,
Expand All @@ -18,7 +18,7 @@ export default interface IBreakdown {
) => any;
getOnboardingMemberCompositionTable: (
platformId: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
activityComposition: string[],
roles?: IRolesPayload,
username?: string,
Expand All @@ -28,7 +28,7 @@ export default interface IBreakdown {
) => any;
getDisengagedMembersCompositionTable: (
platformId: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
activityComposition: string[],
roles?: IRolesPayload,
username?: string,
Expand Down
4 changes: 2 additions & 2 deletions src/store/types/ICharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default interface ICharts {
selectedChannelsList: any[];
fetchHeatmapData: (
platformId: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
startDate: string,
endDate: string,
timeZone: string,
Expand All @@ -27,7 +27,7 @@ export default interface ICharts {
platformId: string,
startDate: string,
endDate: string,
platformType: 'discord' | 'discourse',
platformType: 'discord' | 'discourse' | 'telegram',
timeZone: string
) => any;
fetchActiveMembers: (
Expand Down
2 changes: 1 addition & 1 deletion src/store/types/IMemberInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export default interface IMemberInteraction {
memberInteractionRecords: any[];
getMemberInteraction: (
platformId: string,
platformType: 'discord' | 'discourse'
platformType: 'discord' | 'discourse' | 'telegram'
) => any;
}

0 comments on commit de1bcf8

Please sign in to comment.