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

feat: Trends #1123

Merged
merged 14 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
224 changes: 115 additions & 109 deletions client/components/AddTestToQueueWithConfirmation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ import {
SCHEDULE_COLLECTION_JOB_MUTATION,
EXISTING_TEST_PLAN_REPORTS
} from './queries';
import { TEST_QUEUE_PAGE_QUERY } from '../TestQueue2/queries';
import { TEST_PLAN_REPORT_STATUS_DIALOG_QUERY } from '../TestPlanReportStatusDialog/queries';
import { ME_QUERY } from '../App/queries';

function AddTestToQueueWithConfirmation({
testPlanVersion,
browser,
at,
exactAtVersion,
minimumAtVersion,
disabled = false,
buttonText = 'Add to Test Queue',
triggerUpdate = () => {}
Expand All @@ -27,8 +32,27 @@ function AddTestToQueueWithConfirmation({
useState(false);
const [showConfirmation, setShowConfirmation] = useState(false);
const [canUseOldResults, setCanUseOldResults] = useState(false);
const [addTestPlanReport] = useMutation(ADD_TEST_QUEUE_MUTATION);
const [scheduleCollection] = useMutation(SCHEDULE_COLLECTION_JOB_MUTATION);

const [addTestPlanReport] = useMutation(ADD_TEST_QUEUE_MUTATION, {
refetchQueries: [
ME_QUERY,
EXISTING_TEST_PLAN_REPORTS,
TEST_QUEUE_PAGE_QUERY,
TEST_PLAN_REPORT_STATUS_DIALOG_QUERY
],
awaitRefetchQueries: true
});

const [scheduleCollection] = useMutation(SCHEDULE_COLLECTION_JOB_MUTATION, {
refetchQueries: [
ME_QUERY,
EXISTING_TEST_PLAN_REPORTS,
TEST_QUEUE_PAGE_QUERY,
TEST_PLAN_REPORT_STATUS_DIALOG_QUERY
],
awaitRefetchQueries: true
});

const { data: existingTestPlanReportsData } = useQuery(
EXISTING_TEST_PLAN_REPORTS,
{
Expand All @@ -44,28 +68,26 @@ function AddTestToQueueWithConfirmation({
const existingTestPlanReports =
existingTestPlanReportsData?.existingTestPlanVersion?.testPlanReports;

const conflictingReportExists = existingTestPlanReports?.some(report => {
return (
report.at.id === at?.id &&
report.browser.id === browser?.id &&
report.isFinal
);
});

let latestOldVersion;
let oldReportToCopyResultsFrom;

// Prioritize a conflicting report for the current version, otherwise
// check if any results data available from a previous result
if (
!conflictingReportExists &&
existingTestPlanReportsData?.oldTestPlanVersions?.length
) {
latestOldVersion =
existingTestPlanReportsData?.oldTestPlanVersions?.reduce((a, b) =>
new Date(a.updatedAt) > new Date(b.updatedAt) ? a : b
);
// Check if any results data available from a previous result using the
// same testFormatVersion
const oldTestPlanVersions =
existingTestPlanReportsData?.oldTestPlanVersions?.filter(
({ metadata }) => {
return (
metadata.testFormatVersion ===
existingTestPlanReportsData?.existingTestPlanVersion
?.metadata.testFormatVersion
);
}
) || [];

if (oldTestPlanVersions?.length) {
latestOldVersion = oldTestPlanVersions?.reduce((a, b) =>
new Date(a.updatedAt) > new Date(b.updatedAt) ? a : b
);
if (
new Date(latestOldVersion?.updatedAt) <
new Date(testPlanVersion?.updatedAt)
Expand Down Expand Up @@ -132,32 +154,40 @@ function AddTestToQueueWithConfirmation({
actions.push({
label: 'Add and run later',
onClick: async () => {
await addTestToQueue(
canUseOldResults
? {
copyResultsFromTestPlanReportId:
latestOldVersion.id
}
: {}
);
await closeWithUpdate();
}
});

if (!alreadyHasBotInTestPlanReport) {
actions.push({
label: 'Add and run with bot',
onClick: async () => {
const testPlanReport = await addTestToQueue(
try {
await addTestToQueue(
canUseOldResults
? {
copyResultsFromTestPlanReportId:
copyResultsFromTestPlanVersionId:
latestOldVersion.id
}
: {}
);
await scheduleCollectionJob(testPlanReport);
await closeWithUpdate();
} catch (e) {
console.error(e);
}
}
});

if (!alreadyHasBotInTestPlanReport) {
actions.push({
label: 'Add and run with bot',
onClick: async () => {
try {
const testPlanReport = await addTestToQueue(
canUseOldResults
? {
copyResultsFromTestPlanVersionId:
latestOldVersion.id
}
: {}
);
await scheduleCollectionJob(testPlanReport);
await closeWithUpdate();
} catch (e) {
console.error(e);
}
}
});
}
Expand All @@ -184,76 +214,47 @@ function AddTestToQueueWithConfirmation({
};

const renderPreserveReportDataDialog = () => {
let title;
let content;
let actions = [];

if (oldReportToCopyResultsFrom) {
title = 'Older Results Data Found';
content =
'Older results with the same AT, browser and test plan ' +
'were found for the report being created. Would you like ' +
'to copy the older results into the report or create a ' +
'completely new report?';
actions = [
{
label: 'Create empty report',
onClick: async () => {
setShowPreserveReportDataMessage(false);
if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue();
}
}
},
{
label: 'Copy older results',
onClick: async () => {
setShowPreserveReportDataMessage(false);
setCanUseOldResults(true);

if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue({
copyResultsFromTestPlanReportId:
latestOldVersion.id
});
}
}
}
];
} else {
title = 'Conflicting Report Found';
content =
'The report could not be created because an existing ' +
'report was found on the reports page with the same AT, ' +
'browser and test plan version. Would you like to return ' +
'the existing report back to the test queue?';
actions = [
{
label: 'Proceed',
onClick: async () => {
setShowPreserveReportDataMessage(false);
if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue();
}
}
}
];
}

return (
<BasicModal
show={showPreserveReportDataMessage}
title={title}
content={content}
title="Older Results Data Found"
content={
'Older results with the same AT, browser and test plan ' +
'were found for the report being created. Would you like ' +
'to copy the older results into the report or create a ' +
'completely new report?'
}
closeLabel="Cancel"
staticBackdrop={true}
actions={actions}
actions={[
{
label: 'Create empty report',
onClick: async () => {
setShowPreserveReportDataMessage(false);
if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue();
}
}
},
{
label: 'Copy older results',
onClick: async () => {
setShowPreserveReportDataMessage(false);
setCanUseOldResults(true);

if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue({
copyResultsFromTestPlanVersionId:
latestOldVersion.id
});
}
}
}
]}
useOnHide
handleClose={async () => {
setShowPreserveReportDataMessage(false);
Expand All @@ -262,20 +263,23 @@ function AddTestToQueueWithConfirmation({
);
};

const addTestToQueue = async ({ copyResultsFromTestPlanReportId } = {}) => {
const addTestToQueue = async ({
copyResultsFromTestPlanVersionId
} = {}) => {
let tpr;
await triggerLoad(async () => {
const res = await addTestPlanReport({
variables: {
testPlanVersionId: testPlanVersion.id,
atId: at.id,
minimumAtVersionId: minimumAtVersion?.id,
exactAtVersionId: exactAtVersion?.id,
browserId: browser.id,
copyResultsFromTestPlanReportId
copyResultsFromTestPlanVersionId
}
});
const testPlanReport =
res?.data?.findOrCreateTestPlanReport?.populatedData
?.testPlanReport ?? null;
res?.data?.createTestPlanReport?.testPlanReport ?? null;
tpr = testPlanReport;
}, 'Adding Test Plan to Test Queue');
setShowConfirmation(true);
Expand All @@ -300,7 +304,7 @@ function AddTestToQueueWithConfirmation({
disabled={disabled}
variant="secondary"
onClick={async () => {
if (conflictingReportExists || oldReportToCopyResultsFrom) {
if (oldReportToCopyResultsFrom) {
setShowPreserveReportDataMessage(true);
} else {
if (hasAutomationSupport) {
Expand Down Expand Up @@ -333,6 +337,8 @@ AddTestToQueueWithConfirmation.propTypes = {
key: PropTypes.string.isRequired,
name: PropTypes.string.isRequired
}),
exactAtVersion: PropTypes.object,
minimumAtVersion: PropTypes.object,
buttonRef: PropTypes.object,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
Expand Down
2 changes: 2 additions & 0 deletions client/components/AddTestToQueueWithConfirmation/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const EXISTING_TEST_PLAN_REPORTS = gql`
id
}
}
metadata
}
oldTestPlanVersions: testPlanVersions(
phases: [CANDIDATE, RECOMMENDED]
Expand All @@ -46,6 +47,7 @@ export const EXISTING_TEST_PLAN_REPORTS = gql`
id
}
}
metadata
}
}
`;
Loading
Loading