Skip to content

Commit 9cbe539

Browse files
author
Philip
committed
fix: fragmentation fix
1 parent f358fe8 commit 9cbe539

10 files changed

Lines changed: 486 additions & 191 deletions

File tree

src/actions/getFragmentationEventGabbardData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ export async function getFragmentationEventGabbardData(shortId: string) {
2929
}
3030

3131
gabbardData.set(report.event_epoch, {
32-
actual_gabbard_points: reportData.actual_gabbard_points.map(point => ({
32+
actual_gabbard_points: reportData.actual_gabbard_points?.map(point => ({
3333
apogee: round(point.apogee, 2),
3434
perigee: round(point.perigee, 2),
3535
period: round(point.period, 2),
3636
})) ?? [],
37-
modelled_gabbard_points: reportData.modelled_gabbard_points.map(point => ({
37+
modelled_gabbard_points: reportData.modelled_gabbard_points?.map(point => ({
3838
apogee: round(point.apogee, 2),
3939
perigee: round(point.perigee, 2),
4040
period: round(point.period, 2),

src/app/(auth)/satellites/[noradId]/page.tsx

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import { notFound } from 'next/navigation';
2-
import { getTranslations } from 'next-intl/server';
32

4-
import { getEphemerises } from '@/actions/getEphemerises';
3+
import type { TypeEpoch, TypeReportFlagSettings } from '@/__generated__/data-contracts';
54
import { getSatellite } from '@/actions/getSatellite';
6-
import { getSession } from '@/actions/getSession';
75
import { ContentNavigation } from '@/components/ContentNavigation';
8-
import { SatelliteAdditionalInformations } from '@/components/satellite/SatelliteAdditionalInformation';
9-
import { SatelliteConjunctionEvents } from '@/components/satellite/SatelliteConjunctionEvents';
10-
import { SatelliteEphemerisData } from '@/components/satellite/SatelliteEphemerisData';
11-
import { SatelliteInformation } from '@/components/satellite/SatelliteInformation';
12-
import Button from '@/ui/button/button';
13-
import { isAgencyApprover, isSatteliteOperator } from '@/utils/Roles';
6+
import { SatelliteAccordion } from '@/components/satellite/SatelliteAccordion';
147

158
type PageProps = {
169
params: Promise<{ noradId: string }>;
1710
searchParams?: Promise<{
18-
upcoming_search_like?: string;
19-
previous_search_link?: string;
11+
report?: TypeReportFlagSettings;
12+
epoch?: TypeEpoch;
2013
}>;
2114
};
2215

@@ -31,16 +24,9 @@ export async function generateMetadata({
3124
}
3225

3326
export default async function Satellite(props: PageProps) {
34-
const t = await getTranslations('Common');
35-
const session = await getSession();
36-
3727
const { noradId } = await props.params;
38-
const { upcoming_search_like, previous_search_link } = await props.searchParams || {};
28+
const { epoch, report } = await props.searchParams || {};
3929
const satellite = await getSatellite(noradId);
40-
const ephemerises = await getEphemerises({
41-
norad_id: noradId,
42-
sort_by: 'updated_at',
43-
});
4430

4531
if (!satellite.norad_id) {
4632
return notFound();
@@ -52,16 +38,7 @@ export default async function Satellite(props: PageProps) {
5238
<div className="grid md:grid-cols-4 gap-7">
5339
<ContentNavigation />
5440
<article className="md:col-span-3">
55-
<SatelliteConjunctionEvents noradId={noradId} query={upcoming_search_like} epoch="future" id="future_search_bar" ariaLabel="Upcoming Conjunction Events" />
56-
<SatelliteEphemerisData
57-
noradId={noradId}
58-
ephemerises={ephemerises}
59-
showButtons={isAgencyApprover(session?.user.role) || isSatteliteOperator(session?.user.role)}
60-
/>
61-
<SatelliteInformation object={satellite} />
62-
<SatelliteAdditionalInformations object={satellite} />
63-
<SatelliteConjunctionEvents noradId={noradId} query={previous_search_link} epoch="past" id="past_search_bar" ariaLabel="Previous Conjunction Events" />
64-
<Button as="link" href="/satellites" variant="secondary" aria-label={t('return', { to: 'all satellites' })}>{t('return', { to: 'all satellites' })}</Button>
41+
<SatelliteAccordion object={satellite} noradId={noradId} epoch={epoch} report={report} />
6542
</article>
6643
</div>
6744
</div>

src/components/activities/data-table/ActivitiesDataTableColumns.tsx

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,88 @@ import { renderReasonForFlagTag } from '@/utils/Tags';
99

1010
export const activitiesColumns: TranslatedColumnDef<TypeActivityEventOut>[] = [
1111
{
12-
accessorKey: 'reason_for_flag',
13-
header: 'Activities.reason_for_flag',
14-
cell: ({ getValue }) => {
15-
const value = getValue<TypeActivityReasonForFlag>();
16-
return renderReasonForFlagTag(value);
17-
},
12+
header: 'Activities.event_information',
13+
columns: [
14+
{
15+
accessorKey: 'reason_for_flag',
16+
header: 'Activities.reason_for_flag',
17+
cell: ({ getValue }) => {
18+
const value = getValue<TypeActivityReasonForFlag>();
19+
return renderReasonForFlagTag(value);
20+
},
21+
},
22+
{
23+
accessorKey: 'short_id',
24+
header: 'Activities.short_id',
25+
cell: ({ getValue }) => {
26+
const value = getValue<string>();
27+
return (
28+
<Link
29+
href={`/activity/${value}`}
30+
className="govuk-link"
31+
>
32+
{value}
33+
</Link>
34+
);
35+
},
36+
},
37+
{
38+
accessorKey: 'common_name',
39+
header: 'Activities.common_name',
40+
cell: ({ renderValue, row }) => (
41+
<Link
42+
href={`/satellites/${row?.original.norad_id}`}
43+
className="govuk-link"
44+
>
45+
{renderValue<string>()}
46+
</Link>
47+
),
48+
},
49+
{
50+
accessorKey: 'operator_name',
51+
header: 'Activities.operator_name',
52+
cell: ({ getValue, row }) => {
53+
const value = getValue<string>();
54+
const operatorId = row.original.operator;
55+
return (
56+
<Link
57+
href={`/organisations/${operatorId}`}
58+
className="govuk-link"
59+
>
60+
{value}
61+
</Link>
62+
);
63+
},
64+
},
65+
{
66+
accessorKey: 'norad_id',
67+
header: 'Activities.norad_id',
68+
},
69+
{
70+
accessorKey: 'flag_date',
71+
header: 'Activities.flag_date',
72+
cell: ({ getValue }) => {
73+
const value = getValue<string>();
74+
return value ? dayjs(value).format(FORMAT_DATE_FULL_MONTH) : '-';
75+
},
76+
},
77+
],
1878
},
1979
{
20-
accessorKey: 'short_id',
21-
header: 'Activities.short_id',
22-
cell: ({ getValue }) => {
23-
const value = getValue<string>();
24-
return (
25-
<Link
26-
href={`/activity/${value}`}
27-
className="govuk-link"
28-
>
29-
{value}
30-
</Link>
31-
);
32-
},
33-
},
34-
{
35-
accessorKey: 'common_name',
36-
header: 'Activities.common_name',
37-
cell: ({ renderValue, row }) => (
38-
<Link
39-
href={`/satellites/${row?.original.norad_id}`}
40-
className="govuk-link"
41-
>
42-
{renderValue<string>()}
43-
</Link>
44-
),
45-
},
46-
{
47-
accessorKey: 'operator_name',
48-
header: 'Activities.operator_name',
49-
cell: ({ getValue, row }) => {
50-
const value = getValue<string>();
51-
const operatorId = row.original.operator;
52-
return (
53-
<Link
54-
href={`/organisations/${operatorId}`}
55-
className="govuk-link"
56-
>
57-
{value}
58-
</Link>
59-
);
60-
},
61-
},
62-
{
63-
accessorKey: 'norad_id',
64-
header: 'Activities.norad_id',
65-
},
66-
{
67-
accessorKey: 'flag_date',
68-
header: 'Activities.flag_date',
69-
cell: ({ getValue }) => {
70-
const value = getValue<string>();
71-
return value ? dayjs(value).format(FORMAT_DATE_FULL_MONTH) : '-';
72-
},
73-
},
74-
{
75-
accessorKey: 'orbit_type',
76-
header: 'Activities.orbit_type',
77-
},
78-
{
79-
accessorKey: 'altitude',
80-
header: 'Activities.altitude',
81-
},
82-
{
83-
accessorKey: 'longitude',
84-
header: 'Activities.longitude',
80+
header: 'Activities.object_information',
81+
columns: [
82+
{
83+
accessorKey: 'orbit_type',
84+
header: 'Activities.orbit_type',
85+
},
86+
{
87+
accessorKey: 'altitude',
88+
header: 'Activities.altitude',
89+
},
90+
{
91+
accessorKey: 'longitude',
92+
header: 'Activities.longitude',
93+
},
94+
],
8595
},
8696
];
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { getTranslations } from 'next-intl/server';
2+
3+
import type { TypeEpoch, TypeReportFlagSettings, TypeSatelliteOut } from '@/__generated__/data-contracts';
4+
import { getEphemerises } from '@/actions/getEphemerises';
5+
import { getSession } from '@/actions/getSession';
6+
import Accordion from '@/ui/accordion/accordion';
7+
import { isAgencyApprover, isSatteliteOperator } from '@/utils/Roles';
8+
9+
import { SatelliteAdditionalInformations } from './SatelliteAdditionalInformation';
10+
import { SatelliteConjunctionEvents } from './SatelliteConjunctionEvents';
11+
import { SatelliteEphemerisData } from './SatelliteEphemerisData';
12+
import { SatelliteInformation } from './SatelliteInformation';
13+
14+
type SatelliteAccordionProps = {
15+
noradId: string;
16+
object: TypeSatelliteOut;
17+
epoch?: TypeEpoch;
18+
report?: TypeReportFlagSettings;
19+
};
20+
21+
const SatelliteAccordion = async ({
22+
noradId,
23+
object,
24+
epoch,
25+
report,
26+
}: SatelliteAccordionProps) => {
27+
const t = await getTranslations('Satellite.accordion');
28+
const session = await getSession();
29+
30+
const ephemerises = await getEphemerises({
31+
norad_id: noradId,
32+
sort_by: 'updated_at',
33+
});
34+
35+
return (
36+
<>
37+
<h2 data-anchor="information" className="govuk-heading-l">{t('satellite_information')}</h2>
38+
<Accordion
39+
id="satellite-event"
40+
initialItems={[
41+
{
42+
id: 'object_data',
43+
heading: t('object_data'),
44+
content: (
45+
<>
46+
<SatelliteInformation object={object} dataPdf={t('object_data')} haveAnchor={false} />
47+
<SatelliteAdditionalInformations object={object} />
48+
</>
49+
),
50+
},
51+
{
52+
id: 'ephemeris_data',
53+
heading: t('ephemeris_data'),
54+
content: (
55+
<SatelliteEphemerisData
56+
noradId={noradId}
57+
ephemerises={ephemerises}
58+
showButtons={isAgencyApprover(session?.user.role) || isSatteliteOperator(session?.user.role)}
59+
/>
60+
),
61+
},
62+
]}
63+
/>
64+
<h2 data-anchor="conjunction_events" className="govuk-heading-l">{t('conjunction_events')}</h2>
65+
<Accordion
66+
id="conjunction-events"
67+
initialItems={[
68+
{
69+
id: 'all_conjunction_events',
70+
heading: t('all_conjunction_events'),
71+
content: <SatelliteConjunctionEvents noradId={noradId} epoch={epoch} report={report} />,
72+
},
73+
]}
74+
/>
75+
</>
76+
77+
);
78+
};
79+
80+
export { SatelliteAccordion };

src/components/satellite/SatelliteConjunctionEvents.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1-
import { getTranslations } from 'next-intl/server';
1+
import type { TypeEpoch, TypeGetConjunctionEventsListParams, TypeReportFlagSettings } from '@/__generated__/data-contracts';
2+
import { getConjunctionEventsList } from '@/actions/getConjunctionEventsList';
3+
import { getSession } from '@/actions/getSession';
4+
import { isAnalysist, isGovUser, isSatteliteUser } from '@/utils/Roles';
25

3-
import type { TypeEpoch, TypeGetConjunctionEventsListParams } from '@/__generated__/data-contracts';
4-
import { getConjunctions } from '@/actions/getConjunctions';
5-
6-
import { SearchBar } from '../SearchBar';
76
import { SatelliteConjunctionsDataTable } from './data-table/SatelliteConjunctionsDataTable';
7+
import { SatelliteConjunctionEventsFilters } from './SatelliteConjunctionEventsFilters';
88

99
type SatelliteConjunctionEventsProps = {
1010
noradId: string;
11-
epoch: TypeEpoch;
12-
id: string;
13-
query?: string;
14-
ariaLabel?: string;
11+
epoch?: TypeEpoch;
12+
report?: TypeReportFlagSettings;
1513
};
1614

17-
const SatelliteConjunctionEvents = async ({ noradId, query, epoch, id, ariaLabel }: SatelliteConjunctionEventsProps) => {
18-
const t = await getTranslations('Satellite.Conjunction_events');
19-
const type = epoch === 'future' ? t('type.future') : t('type.past');
20-
const searchParamName = epoch === 'future' ? 'upcoming_search_like' : 'previous_search_link';
21-
const searchBarLabel = epoch === 'future' ? t('search_bar.upcomingLabel') : t('search_bar.previousLabel');
15+
const SatelliteConjunctionEvents = async ({ noradId, epoch, report }: SatelliteConjunctionEventsProps) => {
16+
const session = await getSession();
17+
const role = session?.user.role;
2218

2319
const params: TypeGetConjunctionEventsListParams = {
24-
search_like: query,
2520
norad_id: noradId,
26-
sort_by: 'tca_time',
27-
sort_order: epoch === 'future' ? 'asc' : 'desc',
2821
epoch,
22+
report,
2923
limit: 50,
3024
};
3125

32-
const initialData = await getConjunctions(params);
26+
const initialData = await getConjunctionEventsList(params);
3327

3428
return (
3529
<div className="mb-12">
36-
<h2 className="govuk-heading-l" data-anchor={`${epoch}-conjunction-events`}>{t('title', { type })}</h2>
37-
<SearchBar label={searchBarLabel} placeholder={t('search_bar.placeholder')} paramName={searchParamName} ariaLabel={ariaLabel} id={id} />
38-
<SatelliteConjunctionsDataTable params={params} initialData={initialData} />
30+
<SatelliteConjunctionEventsFilters
31+
params={{
32+
epoch,
33+
report,
34+
}}
35+
showFilterRadios={!isSatteliteUser(session?.user.role)}
36+
/>
37+
<SatelliteConjunctionsDataTable
38+
params={params}
39+
initialData={initialData}
40+
isAnalyst={isAnalysist(role) || isGovUser(role)}
41+
haveAccessToAlerts={!isSatteliteUser(role)}
42+
/>
3943
</div>
4044
);
4145
};

0 commit comments

Comments
 (0)