Skip to content

Commit

Permalink
[repo] Add ReleaseStateSummary Component
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 10, 2024
1 parent cd73160 commit 223f1df
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 0 deletions.
1 change: 1 addition & 0 deletions .markdownlint-cli2.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ config.MD033 = {
"DbAccessPHP",
"SettingsPHP",
"LocalLib",
"ReleaseStateSummary",
]
};

Expand Down
170 changes: 170 additions & 0 deletions src/components/ReleaseStateSummary/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/**
* Copyright (c) Moodle Pty Ltd.
*
* Moodle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Moodle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react';
import type { majorVersionData } from '@site/src/utils/SupportedReleases';
import { getReleaseStatus, getVersion } from '@site/src/utils/SupportedReleases';
import Link from '@docusaurus/Link';
import Admonition from '@theme/Admonition';
import Heading from '@theme/Heading';

export interface ReleaseInfoProps {
releaseName: string,
}

function supportedRelease({ releaseData }: majorVersionData): JSX.Element {
const generalEndDate = new Date(releaseData.generalEndDate);
const securityEndDate = new Date(releaseData.securityEndDate);

return (
<>
<Heading as="h2">Release status</Heading>
<Admonition type="info" title="Important dates">
<p>
Moodle
{' '}
{releaseData.name}
, which
{' '}
{releaseData.isLTS && <strong>is an LTS release</strong>}
{!releaseData.isLTS && <strong>is not an LTS release</strong>}
, was released on
{' '}
<strong>
{releaseData.releaseDate}
</strong>
.
</p>
<p>
General support
{' '}
{generalEndDate < new Date() && <>ended</>}
{generalEndDate >= new Date() && <>will end</>}
{' '}
on
{' '}
<strong>
{releaseData.generalEndDate}
</strong>
.
</p>
<p>
Security support
{' '}
{securityEndDate < new Date() && <>ended</>}
{securityEndDate >= new Date() && <>will end</>}
{' '}
on
{' '}
<strong>
{releaseData.securityEndDate}
</strong>
.
</p>
</Admonition>
</>
);
}

function getAdmonitionType(date): string {
const today = new Date();
if (date < today) {
return 'danger';
}

return 'info';
}

function futureRelease({ releaseData }: majorVersionData): JSX.Element {
const today = new Date();
const codeFreezeDate = new Date(releaseData.codeFreezeDate);

console.log(releaseData);
return (
<>
<Heading as="h2">Release status</Heading>
<Admonition type={getAdmonitionType(codeFreezeDate)} title="Important dates">
<p>
Moodle
{' '}
{releaseData.name}
, which
{' '}
{releaseData.isLTS && <strong>will be an LTS release</strong>}
{!releaseData.isLTS && <strong>will not an LTS release</strong>}
, is scheduled for release on
{' '}
<strong>
{releaseData.releaseDate}
</strong>
.
</p>
<p>
The
{' '}
<Link to="/general/development/process/integration#during-continuous-integrationfreezeqa-period">
code freeze
</Link>
{' '}
{codeFreezeDate < today && <strong>started</strong>}
{codeFreezeDate >= today && <strong>will start</strong>}
{' '}
on
{' '}
<strong>
{releaseData.codeFreezeDate}
</strong>
.
</p>
<p>
General support will end on
{' '}
<strong>
{releaseData.generalEndDate}
</strong>
.
</p>
<p>
Security support will end on
{' '}
<strong>
{releaseData.securityEndDate}
</strong>
.
</p>
</Admonition>
</>
);
}

export default function ReleaseStateSummary({ releaseName }: ReleaseInfoProps): JSX.Element {
const releaseData = getVersion(releaseName);
const status = getReleaseStatus(releaseData);

if (status === 'future') {
return futureRelease({ releaseData });
}

if (status === 'current' || status === 'security') {
return supportedRelease({ releaseData });
}

return (
<>
</>
);
}

0 comments on commit 223f1df

Please sign in to comment.