Skip to content

Commit 25ed5aa

Browse files
authored
Merge pull request #264 from galasa-dev/JamesC-fix-3270-bugs
# Why? James - fix some 3270 tab bugs with refreshing and css styling.
2 parents e9b1541 + 9c2ea72 commit 25ed5aa

File tree

7 files changed

+243
-79
lines changed

7 files changed

+243
-79
lines changed

galasa-ui/src/components/test-runs/test-run-details/3270Tab/TabFor3270.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ export default function TabFor3270({
1919
zos3270TerminalData,
2020
is3270CurrentlySelected,
2121
handleNavigateTo3270,
22+
isLoading,
23+
setIsLoading,
2224
}: {
2325
runId: string;
2426
zos3270TerminalData: TreeNodeData[];
2527
is3270CurrentlySelected: boolean;
2628
handleNavigateTo3270: (highlightedRowId: string) => void;
29+
isLoading: boolean;
30+
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
2731
}) {
2832
const [isError, setIsError] = useState(false);
29-
const [isLoading, setIsLoading] = useState(true);
3033
const [imageData, setImageData] = useState<TerminalImage>();
3134
const [moveImageSelection, setMoveImageSelection] = useState<number>(0);
3235
const [cannotSwitchToPreviousImage, setCannotSwitchToPreviousImage] = useState<boolean>(true);
@@ -44,17 +47,6 @@ export default function TabFor3270({
4447
// eslint-disable-next-line
4548
}, [highlightedRowId, is3270CurrentlySelected]);
4649

47-
// Get the 'terminalScreen' parameter
48-
useEffect(() => {
49-
if (is3270CurrentlySelected && highlightedRowId === '') {
50-
const url = new URL(window.location.href);
51-
setHighlightedRowId(url.searchParams.get('terminalScreen') || '');
52-
}
53-
54-
// If you're adding extra state to this hook, make sure to review the dependency array due to the warning suppression:
55-
// eslint-disable-next-line
56-
}, [is3270CurrentlySelected]);
57-
5850
if (isError) {
5951
return <ErrorPage />;
6052
}

galasa-ui/src/components/test-runs/test-run-details/3270Tab/TableOfScreenshots.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export default function TableOfScreenshots({
7878
const [searchTerm, setSearchTerm] = useState('');
7979
const [selectedTerminal, setSelectedTerminal] = useState<DropdownOption | null>(null);
8080
const [allImageData, setAllImageData] = useState<TerminalImage[]>([]);
81-
const [initialHighlightedRowSet, setInitialHighlightedRowSet] = useState<boolean>(false);
8281

8382
const screenshotsCollected = useRef<boolean | null>(false);
8483

@@ -116,12 +115,16 @@ export default function TableOfScreenshots({
116115
useEffect(() => {
117116
// Highlight and display first element when the page loads, unless already set.
118117
const highlightFirstRowOnPageLoad = () => {
119-
if (!initialHighlightedRowSet && filteredRows[0]) {
120-
setInitialHighlightedRowSet(true);
118+
if (!highlightedRowId && filteredRows[0]) {
119+
const url = new URL(window.location.href);
120+
const terminalScreen = url.searchParams.get('terminalScreen');
121+
121122
if (
122-
highlightedRowId === '' ||
123-
!filteredRows.find((filteredRow) => filteredRow.id === highlightedRowId)
123+
terminalScreen &&
124+
filteredRows.find((filteredRow) => filteredRow.id === terminalScreen)
124125
) {
126+
setHighlightedRowId(terminalScreen);
127+
} else {
125128
setHighlightedRowId(filteredRows[0].id);
126129
}
127130
}
@@ -147,7 +150,6 @@ export default function TableOfScreenshots({
147150
// Ensure screenshots are only collected once.
148151
if (!screenshotsCollected.current?.valueOf() && flattenedZos3270TerminalData.length === 0) {
149152
screenshotsCollected.current = true;
150-
setIsLoading(true);
151153
const fetchData = async () => {
152154
try {
153155
setFlattenedZos3270TerminalData([]);
@@ -285,7 +287,7 @@ export default function TableOfScreenshots({
285287
getRowProps: (options: any) => TableRowProps;
286288
getTableProps: () => TableBodyProps;
287289
}) => (
288-
<Table stickyHeader {...getTableProps()} className={styles.innerScreenshotTable}>
290+
<Table stickyHeader {...getTableProps()} id={styles.innerScreenshotTable}>
289291
<TableHead>
290292
<TableRow>
291293
{headers.map((header) => (

galasa-ui/src/components/test-runs/test-run-details/LogTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ export default function LogTab({ logs, initialLine, runId }: LogTabProps) {
536536
lineElement.scrollIntoView({ behavior: ANIMATION_BEHAVIOUR, block: 'start' });
537537
}
538538
}
539-
}, [initialLine, processedLines]);
539+
}, [ANIMATION_BEHAVIOUR, initialLine, processedLines]);
540540

541541
// Scroll to current match
542542
useEffect(() => {
@@ -549,7 +549,7 @@ export default function LogTab({ logs, initialLine, runId }: LogTabProps) {
549549
});
550550
}
551551
}
552-
}, [currentMatchIndex]);
552+
}, [ANIMATION_BEHAVIOUR, currentMatchIndex]);
553553

554554
useEffect(() => {
555555
const matchCount = searchMatches.length;

galasa-ui/src/components/test-runs/test-run-details/OverviewTab.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,26 @@ import useHistoryBreadCrumbs from '@/hooks/useHistoryBreadCrumbs';
1616
import { TEST_RUNS_QUERY_PARAMS } from '@/utils/constants/common';
1717
import { TIME_TO_WAIT_BEFORE_CLOSING_TAG_EDIT_MODAL_MS } from '@/utils/constants/common';
1818
import RenderTags from '@/components/test-runs/test-run-details/RenderTags';
19-
import { updateRunTags, getExistingTagObjects } from '@/actions/runsAction';
19+
import { updateRunTags } from '@/actions/runsAction';
2020

2121
type DisplayedTagType = {
2222
id: string;
2323
label: string;
2424
};
2525

26-
const OverviewTab = ({ metadata }: { metadata: RunMetadata }) => {
26+
const OverviewTab = ({
27+
metadata,
28+
existingTagObjectNames,
29+
}: {
30+
metadata: RunMetadata;
31+
existingTagObjectNames: string[];
32+
}) => {
2733
const translations = useTranslations('OverviewTab');
2834
const { pushBreadCrumb } = useHistoryBreadCrumbs();
2935

3036
const [weekBefore, setWeekBefore] = useState<string | null>(null);
3137

3238
const [tags, setTags] = useState<string[]>(metadata?.tags || []);
33-
const [existingTagObjectNames, setExistingTagObjectNames] = useState<string[]>([]);
3439

3540
const [isTagsEditModalOpen, setIsTagsEditModalOpen] = useState<boolean>(false);
3641
const [filterInput, setFilterInput] = useState<string>('');
@@ -46,22 +51,6 @@ const OverviewTab = ({ metadata }: { metadata: RunMetadata }) => {
4651
const OTHER_RECENT_RUNS = `/test-runs?${TEST_RUNS_QUERY_PARAMS.TEST_NAME}=${fullTestName}&${TEST_RUNS_QUERY_PARAMS.BUNDLE}=${metadata?.bundle}&${TEST_RUNS_QUERY_PARAMS.PACKAGE}=${metadata?.package}&${TEST_RUNS_QUERY_PARAMS.DURATION}=60,0,0&${TEST_RUNS_QUERY_PARAMS.TAB}=results&${TEST_RUNS_QUERY_PARAMS.QUERY_NAME}=Recent runs of test ${metadata?.testName}`;
4752
const RETRIES_FOR_THIS_TEST_RUN = `/test-runs?${TEST_RUNS_QUERY_PARAMS.SUBMISSION_ID}=${metadata?.submissionId}&${TEST_RUNS_QUERY_PARAMS.FROM}=${weekBefore}&${TEST_RUNS_QUERY_PARAMS.TAB}=results&${TEST_RUNS_QUERY_PARAMS.QUERY_NAME}=All attempts of test run ${metadata?.runName}`;
4853

49-
useEffect(() => {
50-
const fetchExistingTags = async () => {
51-
try {
52-
const result = await getExistingTagObjects();
53-
setExistingTagObjectNames(result.tags || []);
54-
55-
if (!result.success) {
56-
console.error('Failed to fetch existing tags:', result.error);
57-
}
58-
} catch (error) {
59-
console.error('Error fetching existing tags:', error);
60-
}
61-
};
62-
fetchExistingTags();
63-
}, []);
64-
6554
useEffect(() => {
6655
const validateTime = () => {
6756
const validatedTime = getAWeekBeforeSubmittedTime(metadata?.rawSubmittedAt!);

galasa-ui/src/components/test-runs/test-run-details/TestRunDetails.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { NotificationType } from '@/utils/types/common';
4545
import { TreeNodeData } from '@/utils/functions/artifacts';
4646
import { TEST_RUNS } from '@/utils/constants/breadcrumb';
4747
import TestRunsSearch from '../TestRunsSearch';
48+
import { getExistingTagObjects } from '@/actions/runsAction';
4849

4950
interface TestRunDetailsProps {
5051
runId: string;
@@ -74,9 +75,11 @@ const TestRunDetails = ({
7475
const [isError, setIsError] = useState(false);
7576
const [isDownloading, setIsDownloading] = useState(false);
7677
const [notification, setNotification] = useState<NotificationType | null>(null);
78+
const [existingTagObjectNames, setExistingTagObjectNames] = useState<string[]>([]);
7779
const { formatDate } = useDateTimeFormat();
7880

7981
const indexOf3270Tab = TEST_RUN_PAGE_TABS.indexOf('3270');
82+
const [is3270TabLoading, setIs3270TabLoading] = useState(true);
8083
const [is3270TabSelectedInURL, setIs3270TabSelectedInURL] = useState<boolean>(false);
8184
const [zos3270TerminalFolderExists, setZos3270TerminalFolderExists] = useState<Boolean>(false);
8285
const [zos3270TerminalData, setZos3270TerminalData] = useState<TreeNodeData[]>([]);
@@ -100,12 +103,16 @@ const TestRunDetails = ({
100103

101104
const handleZos3270TerminalFolderCheck = (newZos3270TerminalFolderExists: boolean) => {
102105
setZos3270TerminalFolderExists(newZos3270TerminalFolderExists);
106+
};
103107

108+
useEffect(() => {
104109
// If 3270 tab has been selected in the URL, move them to the 3270 pannel from the overview page redirection
105-
if (is3270TabSelectedInURL && newZos3270TerminalFolderExists) {
110+
if (is3270TabSelectedInURL && zos3270TerminalFolderExists && !is3270TabLoading) {
106111
setSelectedTabIndex(indexOf3270Tab);
107112
}
108-
};
113+
// Ignore missing dependecies as they will be finalised by the time is3270TabLoading switches to false
114+
// eslint-disable-next-line react-hooks/exhaustive-deps
115+
}, [is3270TabLoading]);
109116

110117
const handleSetZos3270TerminalData = (newZos3270TerminalData: TreeNodeData[]) => {
111118
setZos3270TerminalData(newZos3270TerminalData);
@@ -182,6 +189,23 @@ const TestRunDetails = ({
182189
loadRunDetails();
183190
}, [run, runDetailsPromise, runArtifactsPromise, runLogPromise, extractRunDetails]);
184191

192+
// Fetch existing tags once on component mount (persists across tab changes)
193+
useEffect(() => {
194+
const fetchExistingTags = async () => {
195+
try {
196+
const result = await getExistingTagObjects();
197+
if (result.success) {
198+
setExistingTagObjectNames(result.tags || []);
199+
} else {
200+
console.error('Failed to fetch existing tags:', result.error);
201+
}
202+
} catch (error) {
203+
console.error('Error fetching existing tags:', error);
204+
}
205+
};
206+
fetchExistingTags();
207+
}, []);
208+
185209
useEffect(() => {
186210
// If the 'Test Runs' breadcrumb is already in the items, skip.
187211
if (breadCrumbItems.length > 1) return;
@@ -383,7 +407,7 @@ const TestRunDetails = ({
383407
</TabList>
384408
<TabPanels>
385409
<TabPanel>
386-
<OverviewTab metadata={run!} />
410+
<OverviewTab metadata={run!} existingTagObjectNames={existingTagObjectNames} />
387411
</TabPanel>
388412
<TabPanel>
389413
<MethodsTab methods={methods} onMethodClick={handleNavigateToLog} />
@@ -407,6 +431,8 @@ const TestRunDetails = ({
407431
zos3270TerminalData={zos3270TerminalData}
408432
is3270CurrentlySelected={indexOf3270Tab === selectedTabIndex}
409433
handleNavigateTo3270={handleNavigateTo3270}
434+
isLoading={is3270TabLoading}
435+
setIsLoading={setIs3270TabLoading}
410436
/>
411437
</TabPanel>
412438
)}

galasa-ui/src/styles/test-runs/test-run-details/Tab3270.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66

77
.tab3270Container {
8-
height: min(calc(100vh - 400px), 550px);
8+
height: min(calc(100vh - 400px), 600px);
99
}
1010

1111
.clickableRow {
1212
cursor: pointer;
1313
}
1414

15-
.innerScreenshotTable {
15+
#innerScreenshotTable {
1616
max-height: min(calc(100vh - 450px), 550px);
1717
overflow-y: auto;
1818
/* Stops sticky header overlapping table elements when scrollToTop() is called. */

0 commit comments

Comments
 (0)