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

Upgrade to react 18 rendering api #1246

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions client/HelpCentrePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'core-js/stable';
import 'regenerator-runtime/runtime';
import * as Sentry from '@sentry/browser';
import 'ophan-tracker-js/build/ophan.manage-my-account';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';
import { HelpCentrePage } from './components/helpCentre/HelpCentrePage';

declare let WEBPACK_BUILD: string;
Expand All @@ -15,5 +15,6 @@ if (typeof window !== 'undefined' && window.guardian && window.guardian.dsn) {
});
}

const element = document.getElementById('app');
render(HelpCentrePage, element);
const element = document.getElementById('app') as HTMLElement;
const root = createRoot(element);
root.render(HelpCentrePage);
7 changes: 4 additions & 3 deletions client/MMAPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'core-js/stable';
import 'regenerator-runtime/runtime';
import * as Sentry from '@sentry/browser';
import 'ophan-tracker-js/build/ophan.manage-my-account';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';
import { MMAPage } from './components/mma/MMAPage';

declare let WEBPACK_BUILD: string;
Expand All @@ -15,5 +15,6 @@ if (typeof window !== 'undefined' && window.guardian && window.guardian.dsn) {
});
}

const element = document.getElementById('app');
render(MMAPage, element);
const element = document.getElementById('app') as HTMLElement;
mxdvl marked this conversation as resolved.
Show resolved Hide resolved
const root = createRoot(element);
root.render(MMAPage);
61 changes: 35 additions & 26 deletions client/components/mma/holiday/HolidayCalendarTables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SvgArrowRightStraight,
} from '@guardian/source-react-components';
import { useContext, useState } from 'react';
import { flushSync } from 'react-dom';
import type { DateStates } from '../../../../shared/dates';
import {
dateAddDays,
Expand Down Expand Up @@ -174,38 +175,46 @@ export const HolidayCalendarTables = (props: HolidayCalendarTablesProps) => {
} else if (inSelectionMode) {
setSelectionModeTo(false);
}

setMouseDownStartDate(day);
};

const dayMouseEnter = (day: Date) => {
if (
inSelectionMode &&
dateIsSameOrAfter(
day,
props.maybeLockedStartDate || props.minimumDate,
) &&
dateIsSameOrBefore(day, props.maximumDate)
) {
const targetStateDayIndex = holidayDates.findIndex(
(holidayDate) => holidayDate.date.valueOf() === day.valueOf(),
);
if (targetStateDayIndex > -1 && startOfSelectionDateIndex > -1) {
const dateIndexesThatShouldBeSelected = selectDatesFromRange(
holidayDates,
startOfSelectionDateIndex,
targetStateDayIndex,
);
setHolidayDates(
holidayDates.map((holidayDate, holidayDateIndex) => ({
...holidayDate,
isSelected: dateIndexesThatShouldBeSelected.some(
(selectedIndex) =>
selectedIndex === holidayDateIndex,
),
})),
flushSync(() => {
if (
inSelectionMode &&
dateIsSameOrAfter(
day,
props.maybeLockedStartDate || props.minimumDate,
) &&
dateIsSameOrBefore(day, props.maximumDate)
) {
const targetStateDayIndex = holidayDates.findIndex(
(holidayDate) =>
holidayDate.date.valueOf() === day.valueOf(),
);
if (
targetStateDayIndex > -1 &&
startOfSelectionDateIndex > -1
) {
const dateIndexesThatShouldBeSelected =
selectDatesFromRange(
holidayDates,
startOfSelectionDateIndex,
targetStateDayIndex,
);
setHolidayDates(
holidayDates.map((holidayDate, holidayDateIndex) => ({
...holidayDate,
isSelected: dateIndexesThatShouldBeSelected.some(
(selectedIndex) =>
selectedIndex === holidayDateIndex,
),
})),
);
}
}
}
});
};

const dayTouchStart = (day: Date) => {
Expand Down
6 changes: 4 additions & 2 deletions cypress/e2e/parallel-3/holidayStops.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ describe('Holiday stops', () => {

cy.findByText('No issues occur during selected period').should('exist');

cy.get('@product_detail.all').should('have.length', 1);
// ToDo: why is this being called more times?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you worked this out yet?

cy.get('@product_detail.all').should('have.length', 2);
cy.get('@fetch_potential_holidays.all').should('have.length', 1);
});

Expand Down Expand Up @@ -135,7 +136,8 @@ describe('Holiday stops', () => {
cy.get('table').contains('9 February - 11 February 2022');

cy.get('@fetch_existing_holidays.all').should('have.length', 1);
cy.get('@product_detail.all').should('have.length', 1);
// ToDo: why is this being called more times?
cy.get('@product_detail.all').should('have.length', 3);

cy.findByText('Confirm').click();
cy.wait('@amend_holiday_stop');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"copy-node-modules": "1.1.1",
"copy-webpack-plugin": "9.1.0",
"core-js": "3.19.1",
"cypress": "13.2.0",
"cypress": "13.5.0",
"cypress-plugin-stripe-elements": "1.0.2",
"eslint": "8.49.0",
"eslint-plugin-jest": "27.0.4",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8127,10 +8127,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/cypress-plugin-stripe-elements/-/cypress-plugin-stripe-elements-1.0.2.tgz#b298d5da820228aafebfa8d3376993ac65f02f71"
integrity sha512-tNXZ9BHooO8IGGmOpVRhNfGde/vmPY4D56pi4VHw1EWbfSuwCoveeqqjKDeRfPzMTD5gGYGwXdX2qO1S9O9GEg==

cypress@13.2.0:
version "13.2.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.2.0.tgz#10f73d06a0764764ffbb903a31e96e2118dcfc1d"
integrity sha512-AvDQxBydE771GTq0TR4ZUBvv9m9ffXuB/ueEtpDF/6gOcvFR96amgwSJP16Yhqw6VhmwqspT5nAGzoxxB+D89g==
cypress@13.5.0:
version "13.5.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.5.0.tgz#8c149074186130972f08b2cdce6ded41f014bacd"
integrity sha512-oh6U7h9w8wwHfzNDJQ6wVcAeXu31DlIYlNOBvfd6U4CcB8oe4akawQmH+QJVOMZlM42eBoCne015+svVqdwdRQ==
dependencies:
"@cypress/request" "^3.0.0"
"@cypress/xvfb" "^1.2.4"
Expand Down
Loading