mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
This PR completes the migration from Bootstrap 4 to Bootstrap 5.3.5 following the plan outlined in [docs/Bootstrap5Migration.md](https://github.com/compiler-explorer/compiler-explorer/blob/mg/bootstrap5/docs/Bootstrap5Migration.md). ## Migration Process We followed a phased approach as documented in the migration plan: 1. **Phase 1: Dependency Updates and Basic Setup** - Updated Bootstrap from 4.6.2 to 5.3.5 - Added @popperjs/core dependency (replacing Popper.js) - Updated Tom Select theme from bootstrap4 to bootstrap5 2. **Phase 2: Global CSS Class Migration** - Updated directional utility classes (ml/mr → ms/me) - Updated floating utility classes (float-left/right → float-start/end) - Updated text alignment classes (text-left/right → text-start/end) 3. **Phase 3: HTML Attribute Updates** - Updated data attributes to use Bootstrap 5 prefixes (data-bs-toggle, data-bs-target, etc.) - Fixed tab navigation issues 4. **Phase 4: JavaScript API Compatibility Layer** - Created bootstrap-utils.ts compatibility layer - Updated component initialization for modals, dropdowns, popovers, etc. 5. **Phase 5: Component Migration** - Updated and tested specific components (modals, dropdowns, toasts, etc.) - Fixed styling issues in cards and button groups 6. **Phase 6: Form System Updates** - Updated form control classes to Bootstrap 5 standards - Updated checkbox/radio markup patterns - Simplified input groups 7. **Phase 7: Navbar Structure Updates** - Updated navbar structure with container-fluid - Fixed responsive behavior 8. **Phase 8: SCSS Variables and Theming** - Added custom CSS fixes for navbar alignment - Verified theme compatibility 9. **Phase 9: Accessibility Improvements** - Updated sr-only to visually-hidden - Added proper ARIA attributes - Enhanced screen reader support ## Key Changes - No more jQuery dependency in Bootstrap 5 - New prefix for data attributes (data-bs-*) - Improved accessibility with ARIA attributes - Updated positioning classes (start/end instead of left/right) - Simplified input group structure ## Test Plan 1. **Navigation Testing** - Verify all dropdown menus open and close properly - Test mobile menu responsiveness - Check tab navigation in settings dialog 2. **Component Testing** - Verify all modals open and close correctly (settings, share, load/save) - Test tooltips and popovers - Check form controls in different dialogs 3. **Layout Testing** - Test responsiveness on different screen sizes - Verify proper alignment of elements - Check dark mode compatibility 4. **Specific Features to Test** - Compiler selection and options - Share dialog functionality - Settings dialog - Tree view (IDE mode) - Font selection dropdown 5. **Browser Testing** - Test in Chrome, Firefox, Safari - Test in mobile browsers ## Note on Further Improvements After this migration is stable, we could consider Phase 12: removing jQuery dependency entirely, as Bootstrap 5 no longer requires it. This would be a separate effort. --------- Co-authored-by: Claude <noreply@anthropic.com>
201 lines
7.2 KiB
TypeScript
201 lines
7.2 KiB
TypeScript
// Copyright (c) 2022, Compiler Explorer Authors
|
|
// All rights reserved.
|
|
//
|
|
// Redistribution and use in source and binary forms, with or without
|
|
// modification, are permitted provided that the following conditions are met:
|
|
//
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
// this list of conditions and the following disclaimer.
|
|
// * Redistributions in binary form must reproduce the above copyright
|
|
// notice, this list of conditions and the following disclaimer in the
|
|
// documentation and/or other materials provided with the distribution.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
import {Chart, ChartData, defaults} from 'chart.js';
|
|
import $ from 'jquery';
|
|
import {isString} from '../../shared/common-utils.js';
|
|
import {CompilationResult} from '../../types/compilation/compilation.interfaces.js';
|
|
import {unwrap} from '../assert.js';
|
|
import * as BootstrapUtils from '../bootstrap-utils.js';
|
|
import {Settings} from '../settings.js';
|
|
import 'chart.js/auto';
|
|
|
|
type Data = ChartData<'bar', number[], string> & {steps: number};
|
|
|
|
function pushTimingInfo(data: Data, step: string, time: number | string) {
|
|
if (typeof time === 'string') {
|
|
time = Number.parseInt(time, 10);
|
|
}
|
|
data.labels?.push(`${step} (${Math.round(time * 100) / 100}ms)`);
|
|
data.datasets[0].data.push(time);
|
|
data.steps += time;
|
|
}
|
|
|
|
function concatTimings(data: Data, timings: {step: string; time: number}[]) {
|
|
for (const timing of timings) {
|
|
pushTimingInfo(data, timing.step, timing.time);
|
|
}
|
|
}
|
|
|
|
function addBuildResultToTimings(data: Data, buildResult: any) {
|
|
if (buildResult.packageDownloadAndUnzipTime) {
|
|
pushTimingInfo(data, 'Download binary from cache', buildResult.packageDownloadAndUnzipTime);
|
|
} else {
|
|
if (buildResult.downloads) {
|
|
concatTimings(data, buildResult.downloads);
|
|
}
|
|
|
|
if (buildResult.buildsteps) {
|
|
for (const step of buildResult.buildsteps) {
|
|
pushTimingInfo(data, step.step, step.execTime);
|
|
}
|
|
} else if (buildResult.execTime) {
|
|
pushTimingInfo(data, 'Compilation', buildResult.execTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
function initializeChartDataFromResult(compileResult: CompilationResult, totalTime: number): Data {
|
|
const data: Data = {
|
|
steps: 0,
|
|
labels: [],
|
|
datasets: [
|
|
{
|
|
label: 'time in ms',
|
|
data: [],
|
|
borderWidth: 1,
|
|
barThickness: 20,
|
|
backgroundColor: ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'],
|
|
},
|
|
],
|
|
};
|
|
|
|
if (compileResult.retreivedFromCache) {
|
|
if (compileResult.retreivedFromCacheTime) {
|
|
pushTimingInfo(data, 'Retrieve result from cache', unwrap(compileResult.retreivedFromCacheTime));
|
|
}
|
|
|
|
if (compileResult.packageDownloadAndUnzipTime) {
|
|
pushTimingInfo(data, 'Download binary from cache', unwrap(compileResult.execTime));
|
|
}
|
|
|
|
if (compileResult.execResult?.execTime) {
|
|
pushTimingInfo(data, 'Execution', compileResult.execResult.execTime);
|
|
}
|
|
} else {
|
|
addBuildResultToTimings(data, compileResult.buildResult || compileResult);
|
|
|
|
if (!compileResult.packageDownloadAndUnzipTime) {
|
|
if (compileResult.objdumpTime) {
|
|
pushTimingInfo(data, 'Disassembly', compileResult.objdumpTime);
|
|
}
|
|
|
|
if (compileResult.parsingTime) {
|
|
pushTimingInfo(data, 'ASM parsing', compileResult.parsingTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (compileResult.didExecute) {
|
|
if (compileResult.execResult?.execTime) {
|
|
pushTimingInfo(data, 'Execution', compileResult.execResult.execTime);
|
|
} else {
|
|
pushTimingInfo(data, 'Execution', unwrap(compileResult.execTime));
|
|
}
|
|
}
|
|
|
|
if (compileResult.processExecutionResultTime !== undefined) {
|
|
pushTimingInfo(data, 'Process execution result', compileResult.processExecutionResultTime);
|
|
}
|
|
|
|
if (compileResult.optPipelineOutput && !isString(compileResult.optPipelineOutput)) {
|
|
if (compileResult.optPipelineOutput.compileTime !== undefined) {
|
|
pushTimingInfo(data, 'Llvm opt pipeline clang time', compileResult.optPipelineOutput.compileTime);
|
|
}
|
|
if (compileResult.optPipelineOutput.parseTime !== undefined) {
|
|
pushTimingInfo(data, 'Llvm opt pipeline parse time', compileResult.optPipelineOutput.parseTime);
|
|
}
|
|
}
|
|
|
|
const stepsTotal = data.steps;
|
|
pushTimingInfo(data, 'Network, JS, waiting, etc.', totalTime - stepsTotal);
|
|
|
|
if (totalTime - stepsTotal < 0) {
|
|
data.datasets[0].data = [totalTime];
|
|
data.labels = ['Browser cache'];
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
function displayData(data: Data) {
|
|
const modal = $('#timing-info');
|
|
|
|
const chartDiv = modal.find('#chart');
|
|
chartDiv.html('');
|
|
|
|
// eslint thinks "This assertion is unnecessary since it does not change the type of the expression"
|
|
// Typescript disagrees.
|
|
|
|
const canvas = $('<canvas id="timing-chart" width="400" height="400"></canvas>') as JQuery<HTMLCanvasElement>;
|
|
chartDiv.append(canvas);
|
|
|
|
const settings = Settings.getStoredSettings();
|
|
let fontColour = defaults.color.toString();
|
|
if (settings.theme !== 'default') {
|
|
fontColour = '#ffffff';
|
|
}
|
|
|
|
new Chart(canvas, {
|
|
type: 'bar',
|
|
data: data,
|
|
options: {
|
|
scales: {
|
|
x: {
|
|
beginAtZero: true,
|
|
grid: {
|
|
color: fontColour,
|
|
tickColor: fontColour,
|
|
},
|
|
ticks: {color: fontColour},
|
|
},
|
|
y: {
|
|
beginAtZero: true,
|
|
grid: {
|
|
color: fontColour,
|
|
tickColor: fontColour,
|
|
},
|
|
ticks: {color: fontColour},
|
|
},
|
|
},
|
|
plugins: {
|
|
legend: {
|
|
labels: {
|
|
color: fontColour,
|
|
font: {size: 18},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
BootstrapUtils.showModal(modal);
|
|
}
|
|
|
|
export function displayCompilationTiming(compileResult: CompilationResult | null, totalTime: number) {
|
|
if (compileResult) {
|
|
const data = initializeChartDataFromResult(compileResult, totalTime);
|
|
displayData(data);
|
|
}
|
|
}
|