Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Fix marketplace releases tab crash bug #26162

Merged
merged 8 commits into from
Jul 14, 2022
13 changes: 9 additions & 4 deletions apps/meteor/client/views/admin/apps/AppDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import React, { useState, useCallback, useRef, FC } from 'react';
import { ISettings } from '../../../../app/apps/client/@types/IOrchestrator';
import { Apps } from '../../../../app/apps/client/orchestrator';
import Page from '../../../components/Page';
import { useEndpointData } from '../../../hooks/useEndpointData';
import { AsyncStatePhase } from '../../../lib/asyncState';
import AppDetails from './AppDetails';
import AppDetailsHeader from './AppDetailsHeader';
import AppLogs from './AppLogs';
Expand Down Expand Up @@ -39,7 +41,10 @@ const AppDetailsPage: FC<{ id: string }> = function AppDetailsPage({ id }) {
const router = useRoute(currentRouteName);
const handleReturn = useMutableCallback((): void => router.push({}));

const { value: releases, phase: releasesPhase } = useEndpointData(`/apps/${id}/versions`) as any;

const { installed, settings, privacyPolicySummary, permissions, tosLink, privacyLink } = appData || {};
const isSecurityVisible = privacyPolicySummary || permissions || tosLink || privacyLink;

const saveAppSettings = useCallback(async () => {
const { current } = settingsRef;
Expand Down Expand Up @@ -89,12 +94,12 @@ const AppDetailsPage: FC<{ id: string }> = function AppDetailsPage({ id }) {
<Tabs.Item onClick={(): void => handleTabClick('details')} selected={!tab || tab === 'details'}>
{t('Details')}
</Tabs.Item>
{Boolean(installed) && (
{Boolean(installed) && isSecurityVisible && (
<Tabs.Item onClick={(): void => handleTabClick('security')} selected={tab === 'security'}>
{t('Security')}
</Tabs.Item>
)}
{Boolean(installed) && (
{Boolean(installed) && releasesPhase !== AsyncStatePhase.REJECTED && (
<Tabs.Item onClick={(): void => handleTabClick('releases')} selected={tab === 'releases'}>
{t('Releases')}
</Tabs.Item>
Expand All @@ -113,7 +118,7 @@ const AppDetailsPage: FC<{ id: string }> = function AppDetailsPage({ id }) {

{Boolean(!tab || tab === 'details') && <AppDetails app={appData} />}

{tab === 'security' && (
{tab === 'security' && isSecurityVisible && (
<AppSecurity
privacyPolicySummary={privacyPolicySummary}
appPermissions={permissions}
Expand All @@ -122,7 +127,7 @@ const AppDetailsPage: FC<{ id: string }> = function AppDetailsPage({ id }) {
/>
)}

{tab === 'releases' && <AppReleases id={id} />}
{tab === 'releases' && <AppReleases value={releases} phase={releasesPhase} />}

{Boolean(tab === 'settings' && settings && Object.values(settings).length) && (
<SettingsDisplay
Expand Down
11 changes: 6 additions & 5 deletions apps/meteor/client/views/admin/apps/AppReleases.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { App } from '@rocket.chat/core-typings';
import { Accordion } from '@rocket.chat/fuselage';
import React, { useEffect, useState } from 'react';

import { useEndpointData } from '../../../hooks/useEndpointData';
import { AsyncStatePhase } from '../../../lib/asyncState/AsyncStatePhase';
import AccordionLoading from './AccordionLoading';
import ReleaseItem from './ReleaseItem';
Expand All @@ -15,14 +15,16 @@ type release = {
};
};

const AppReleases = ({ id }: { id: string }): JSX.Element => {
const { value, phase, error } = useEndpointData(`/apps/${id}/versions`) as any;
type value = {
apps: App[];
success: boolean;
};

const AppReleases = ({ value, phase }: { value: value; phase: AsyncStatePhase }): JSX.Element => {
const [releases, setReleases] = useState([] as release[]);

const isLoading = phase === AsyncStatePhase.LOADING;
const isSuccess = phase === AsyncStatePhase.RESOLVED;
const didFail = phase === AsyncStatePhase.REJECTED || error;

useEffect(() => {
if (isSuccess && value?.apps) {
Expand All @@ -41,7 +43,6 @@ const AppReleases = ({ id }: { id: string }): JSX.Element => {
return (
<>
<Accordion width='100%' alignSelf='center'>
{didFail && error}
{isLoading && <AccordionLoading />}
{isSuccess && releases.length && releases.map((release) => <ReleaseItem release={release} key={release.version} />)}
</Accordion>
Expand Down
16 changes: 10 additions & 6 deletions apps/meteor/client/views/admin/apps/AppSecurity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ const AppSecurity: FC<AppSecurityProps> = ({ privacyPolicySummary, appPermission
{t('Policies')}
</Box>
<Box display='flex' flexDirection='column'>
<Box is='a' href={tosLink}>
Terms of use
</Box>
<Box is='a' href={privacyLink}>
Privacy policy
</Box>
{tosLink && (
<Box is='a' href={tosLink}>
Terms of use
rique223 marked this conversation as resolved.
Show resolved Hide resolved
</Box>
)}
{privacyLink && (
<Box is='a' href={privacyLink}>
Privacy policy
</Box>
)}
</Box>
</Box>
</Margins>
Expand Down