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
9 changes: 5 additions & 4 deletions apps/meteor/client/views/admin/apps/AppDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const AppDetailsPage: FC<{ id: string }> = function AppDetailsPage({ id }) {
const router = useRoute(currentRouteName);
const handleReturn = useMutableCallback((): void => router.push({}));

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

const saveAppSettings = useCallback(async () => {
const { current } = settingsRef;
Expand Down Expand Up @@ -89,12 +90,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) && marketplace !== false && (
<Tabs.Item onClick={(): void => handleTabClick('releases')} selected={tab === 'releases'}>
{t('Releases')}
</Tabs.Item>
Expand All @@ -113,7 +114,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 Down
44 changes: 10 additions & 34 deletions apps/meteor/client/views/admin/apps/AppReleases.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,25 @@
import { Accordion } from '@rocket.chat/fuselage';
import React, { useEffect, useState } from 'react';
import React from 'react';

import { useEndpointData } from '../../../hooks/useEndpointData';
import { AsyncStatePhase } from '../../../lib/asyncState/AsyncStatePhase';
import AccordionLoading from './AccordionLoading';
import ReleaseItem from './ReleaseItem';

type release = {
version: string;
createdDate: string;
detailedChangelog: {
raw: string;
rendered: string;
};
};

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

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) {
const { apps } = value;

setReleases(
apps.map((app: any) => ({
version: app.version,
createdDate: app.createdDate,
detailedChangelog: app.detailedChangelog,
})),
);
}
}, [isSuccess, value]);
const result = useEndpointData(`/apps/${id}/versions`);

return (
<>
<Accordion width='100%' alignSelf='center'>
{didFail && error}
{isLoading && <AccordionLoading />}
{isSuccess && releases.length && releases.map((release) => <ReleaseItem release={release} key={release.version} />)}
{result.phase === AsyncStatePhase.LOADING && <AccordionLoading />}
{result.phase === AsyncStatePhase.RESOLVED && (
<>
{result.value.apps.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}>
{t('Terms_of_use')}
</Box>
)}
{privacyLink && (
<Box is='a' href={privacyLink}>
{t('Privacy_policy')}
</Box>
)}
</Box>
</Box>
</Margins>
Expand Down
5 changes: 2 additions & 3 deletions apps/meteor/client/views/admin/apps/ReleaseItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ type release = {

type ReleaseItemProps = {
release: release;
key: string;
};

const ReleaseItem = ({ release, key, ...props }: ReleaseItemProps): JSX.Element => {
const ReleaseItem = ({ release, ...props }: ReleaseItemProps): JSX.Element => {
const formatDate = useTimeAgo();

const title = (
Expand All @@ -32,7 +31,7 @@ const ReleaseItem = ({ release, key, ...props }: ReleaseItemProps): JSX.Element
);

return (
<Accordion.Item key={key} title={title} {...props}>
<Accordion.Item title={title} {...props}>
{release.detailedChangelog?.rendered ? (
<Box dangerouslySetInnerHTML={{ __html: release.detailedChangelog?.rendered }} />
) : (
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3596,6 +3596,7 @@
"Priority_removed": "Priority removed",
"Privacy": "Privacy",
"Privacy_Policy": "Privacy Policy",
"Privacy_policy": "Privacy policy",
"Privacy_summary": "Privacy summary",
"Private": "Private",
"Private_Channel": "Private Channel",
Expand Down Expand Up @@ -4400,6 +4401,7 @@
"Teams_New_Read_only_Label": "Read Only",
"Technology_Services": "Technology Services",
"Terms": "Terms",
"Terms_of_use": "Terms of use",
"Test_Connection": "Test Connection",
"Test_Desktop_Notifications": "Test Desktop Notifications",
"Test_LDAP_Search": "Test LDAP Search",
Expand Down
6 changes: 6 additions & 0 deletions packages/rest-typings/src/apps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export type AppsEndpoints = {
};
};

'/apps/:id/versions': {
GET: () => {
apps: App[];
};
};

'/apps': {
GET:
| ((params: { buildExternalUrl: 'true'; purchaseType?: 'buy' | 'subscription'; appId?: string; details?: 'true' | 'false' }) => {
Expand Down