diff --git a/src/components/UI/DataTable.tsx b/src/components/UI/DataTable.tsx index 55df07c493..9d51e45178 100644 --- a/src/components/UI/DataTable.tsx +++ b/src/components/UI/DataTable.tsx @@ -11,8 +11,16 @@ import { Stack } from '@chakra-ui/react'; import { FC } from 'react'; + +import { + getOS, + getParsedDate, + isDarwinPrimaryRelease, + isLinuxPrimaryRelease, + isMobilePrimaryRelease, + isWindowsPrimaryRelease +} from '../../utils'; import { OpenPGPSignaturesData, ReleaseData } from '../../types'; -import { getParsedDate } from '../../utils'; interface Props { columnHeaders: string[]; @@ -71,11 +79,26 @@ export const DataTable: FC = ({ columnHeaders, data }) => { {dataType === 'Releases' && data.map((r: ReleaseData, idx: number) => { + const url = r?.release?.url; + const os = getOS(url); + + const _isLinuxPrimaryRelease = isLinuxPrimaryRelease(r, os, data); + const _isDarwinPrimaryRelease = isDarwinPrimaryRelease(r, os, data); + const _isWindowsPrimaryRelease = isWindowsPrimaryRelease(r, os, data); + const _isMobilePrimaryRelease = isMobilePrimaryRelease(r, os, data); + + const isPrimaryRelease = + _isLinuxPrimaryRelease || + _isDarwinPrimaryRelease || + _isWindowsPrimaryRelease || + _isMobilePrimaryRelease; + return ( {Object.entries(r).map((item, idx) => { const objectItems = ['release', 'commit', 'signature']; diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 83030e64c9..a28c91b28b 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -15,7 +15,7 @@ export default function Document() { {/* Inter */} diff --git a/src/types.ts b/src/types.ts index 5104fe71fd..4a93eed9aa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -50,3 +50,5 @@ export interface OpenPGPSignaturesData { }; fingerprint: string; } + +export type OS = 'linux' | 'darwin' | 'windows' | 'mobile'; diff --git a/src/utils/getOS.ts b/src/utils/getOS.ts new file mode 100644 index 0000000000..b2a3c61a1d --- /dev/null +++ b/src/utils/getOS.ts @@ -0,0 +1,11 @@ +import { OS } from '../types'; + +// slice to get the last part of the url that includes the os +export const getOS = (url: string): OS => + url?.slice(46).includes('darwin') + ? 'darwin' + : url?.slice(46).includes('linux') + ? 'linux' + : url?.slice(46).includes('windows') + ? 'windows' + : 'mobile'; diff --git a/src/utils/index.ts b/src/utils/index.ts index 206b319fe8..f950ec7d46 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -5,6 +5,7 @@ export { fetchXMLData } from './fetchXMLData'; export { getChecksum } from './getChecksum'; export { getKebabCaseFromName } from './getKebabCaseFromName'; export { getLatestBinaryURL } from './getLatestBinaryURL'; +export { getOS } from './getOS'; export { getParsedDate } from './getParsedDate'; export { getProgrammingLanguageName } from './getProgrammingLanguageName'; export { getReleaseArch } from './getReleaseArch'; @@ -16,4 +17,8 @@ export { getReleaseSize } from './getReleaseSize'; export { getReleaseURL } from './getReleaseURL'; export { getSignatureURL } from './getSignatureURL'; export { getSortedReleases } from './getSortedReleases'; +export { isDarwinPrimaryRelease } from './isDarwinPrimaryRelease'; +export { isLinuxPrimaryRelease } from './isLinuxPrimaryRelease'; +export { isMobilePrimaryRelease } from './isMobilePrimaryRelease'; +export { isWindowsPrimaryRelease } from './isWindowsPrimaryRelease'; export { mapReleasesData } from './mapReleasesData'; diff --git a/src/utils/isDarwinPrimaryRelease.ts b/src/utils/isDarwinPrimaryRelease.ts new file mode 100644 index 0000000000..1b4f0327e3 --- /dev/null +++ b/src/utils/isDarwinPrimaryRelease.ts @@ -0,0 +1,8 @@ +import { OS, ReleaseData } from '../types'; + +export const isDarwinPrimaryRelease = (r: ReleaseData, os: OS, data: ReleaseData[]) => + os === 'darwin' && + data + .slice(0, 2) // get latest build to filter on + .filter((e: ReleaseData) => e.arch === '64-bit') + .includes(r); diff --git a/src/utils/isLinuxPrimaryRelease.ts b/src/utils/isLinuxPrimaryRelease.ts new file mode 100644 index 0000000000..e2c9437e11 --- /dev/null +++ b/src/utils/isLinuxPrimaryRelease.ts @@ -0,0 +1,8 @@ +import { OS, ReleaseData } from '../types'; + +export const isLinuxPrimaryRelease = (r: ReleaseData, os: OS, data: ReleaseData[]) => + os === 'linux' && + data + .slice(0, 12) // get latest build to filter on + .filter((e: ReleaseData) => e.arch === '64-bit') + .includes(r); diff --git a/src/utils/isMobilePrimaryRelease.ts b/src/utils/isMobilePrimaryRelease.ts new file mode 100644 index 0000000000..fcbdcdc7dc --- /dev/null +++ b/src/utils/isMobilePrimaryRelease.ts @@ -0,0 +1,8 @@ +import { OS, ReleaseData } from '../types'; + +export const isMobilePrimaryRelease = (r: ReleaseData, os: OS, data: ReleaseData[]) => + os === 'mobile' && + data + .filter((e: ReleaseData) => e.arch === 'all') + .slice(0, 1) // get latest build + .includes(r); diff --git a/src/utils/isWindowsPrimaryRelease.ts b/src/utils/isWindowsPrimaryRelease.ts new file mode 100644 index 0000000000..d197232838 --- /dev/null +++ b/src/utils/isWindowsPrimaryRelease.ts @@ -0,0 +1,8 @@ +import { OS, ReleaseData } from '../types'; + +export const isWindowsPrimaryRelease = (r: ReleaseData, os: OS, data: ReleaseData[]) => + os === 'windows' && + data + .slice(0, 6) // get latest build to filter on + .filter((e: ReleaseData) => e.kind === 'Installer' && e.arch === '64-bit') + .includes(r);