Skip to content
Open
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
156 changes: 156 additions & 0 deletions src/assets/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,98 @@ table tr.is-edited + .detail {
min-height: 100px;
}

// Scrollbars that are always drawn. macOS (and Windows 11 by default) show overlay scrollbars only
// while scrolling, which hides that a table scrolls sideways from mouse users. Chrome, Edge and Safari
// draw these; Firefox keeps its own. Keep the size in step with MIN_BAR_HEIGHT_PX in FloatingScrollbar.
// Setting scrollbar-width or scrollbar-color here would make Chrome ignore these rules.
@mixin visible-scrollbars {
&::-webkit-scrollbar {
width: 12px;
height: 12px;
}

&::-webkit-scrollbar-track,
&::-webkit-scrollbar-corner {
background-color: $white-ter;
}

&::-webkit-scrollbar-thumb {
background-color: $grey-light;
border: 3px solid $white-ter;
border-radius: 6px;

&:hover {
background-color: $grey;
}
}
}

// Tables taller than the window scroll inside a box (sized by BoundedTableMixin) so the header row and
// horizontal scrollbar stay on screen. Shorter tables look the same as unbounded ones.
.bounded-table {
.table-wrapper.has-sticky-header,
.bounded-table-scroll {
// Buefy gives a sticky-header wrapper a fixed 300px height: cap the height instead.
height: auto;
max-height: var(--bounded-table-max-height, calc(100vh - 10rem));
overflow: auto;
@include visible-scrollbars;

// Collapsed borders belong to the table rather than the pinned header cells, so rows would show
// through them while scrolling. Bulma only draws bottom borders, so this looks the same.
> .table {
border-collapse: separate;
border-spacing: 0;
}

// The box scrolls on any overflow, so keep content that used to spill harmlessly past the table
// inside it: Buefy's sort arrow sits just past its label, and the empty message's Bulma columns
// have negative margins.
thead th:last-child .th-wrap {
padding-right: 1rem;
}

tr.is-empty > td {
overflow: hidden;
}
}

// Pin the whole header, including the column filter row, not only Buefy's first header row.
// Its z-index stays below the sticky .main-header (30).
.table-wrapper.has-sticky-header thead,
.bounded-table-scroll thead {
position: sticky;
top: 0;
z-index: 2;

th,
td {
background-color: $white;
}
}
}

.table-result-count {
margin-bottom: 0.5rem;
}

// Stand-in for a bounded table's horizontal scrollbar while the box's own is below the window
// (FloatingScrollbar). Above the table's pinned header (2), below the sticky .main-header (30).
.floating-scrollbar {
position: fixed;
bottom: 0;
z-index: 20;
overflow-x: auto;
overflow-y: hidden;
background-color: $white;
border-top: 1px solid $grey-lighter;
@include visible-scrollbars;

> div {
height: 1px;
}
}

.menu-scroll {
position: absolute;
height: 100%;
Expand Down Expand Up @@ -920,6 +1012,70 @@ tr:nth-child(odd) td.db-filled {
}
}

// An experiment's description and fields, in a box whose header collapses it to bring the
// datasets up. The header and body set their own padding so the header's hover fills the box.
.experiment-details {
padding: 0;
margin-bottom: 1.5rem;
// Same indent as the dataset tabs and .tab-content below it.
margin-left: 2em;
// Flat, like the tabs, table and dataset summary around it.
border: 1px solid $grey-lighter;
box-shadow: none;
}

// A dataset's figures on one line above its table.
.dataset-summary {
display: flex;
flex-wrap: wrap;
column-gap: 2.5rem;
row-gap: 0.25rem;
}

.experiment-details-toggle {
display: flex;
align-items: center;
gap: 0.5rem;
width: 100%;
padding: 0.75rem 1.25rem;
border: none;
border-radius: inherit;
background: none;
// Link blue, as DeltaBreed marks text actions.
color: $link;
font: inherit;
font-weight: $weight-bold;
text-align: left;
cursor: pointer;

&:hover {
background-color: $white-ter;
}

&:focus-visible {
outline: 2px solid $link;
outline-offset: -2px;
}
}

.experiment-details-body {
padding: 1rem 1.25rem 0.5rem;
border-top: 1px solid $grey-lighter;

// Line the fields up with the description.
ul {
margin-left: 0;
}
}

// At a readable line length; long citations carry unbroken URLs.
.experiment-description {
max-width: 60rem;
margin-bottom: 1rem;
overflow-wrap: break-word;
word-break: break-word;
}

.collaborators-section {
display: flex;
align-items: flex-start;
Expand Down
94 changes: 94 additions & 0 deletions src/breeding-insight/model/view_models/TableResultRange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* The pagination fields the range needs. Both PaginationController and the server's Pagination have
* them; only PaginationController has showAll.
*/
export interface TablePageState {
currentPage: number;
pageSize: number;
totalCount: number;
showAll?: boolean;
}

/**
* The rows a paginated table is showing: rows start to end of total (1-based), or all of them.
*
* When the table's own column filters narrow a single page of server results, the filter only sees
* that page: matchedOnPage of the page's pageCount rows match, and total is the server's total.
*/
export class TableResultRange {
constructor(
public readonly start: number,
public readonly end: number,
public readonly total: number,
public readonly showAll: boolean,
public readonly matchedOnPage: number | null = null,
public readonly pageCount: number | null = null
) {}

static readonly EMPTY = new TableResultRange(0, 0, 0, false);

/** True when a column filter is narrowing one page of server results. */
get filteredOnPage(): boolean {
return this.matchedOnPage !== null;
}

/**
* Works out the range for a table whose records are either one page from the server, or every
* record with the table paging (and possibly filtering) them in the browser.
*
* @param pagination the table's pagination state
* @param recordCount the number of records passed to the table
* @param filteredCount the number of records left after the table's own (client-side) filters
*/
static of(pagination: TablePageState, recordCount: number, filteredCount: number): TableResultRange {
const pageSize = Math.max(pagination.pageSize, 1);
const showAll = !!pagination.showAll;
// The server holds more rows than it sent, so the records are a single page of server results.
const serverPaged = pagination.totalCount > recordCount;

if (serverPaged) {
// No rows yet, e.g. while the next page loads: say nothing rather than a range that isn't there.
if (recordCount === 0) {
return TableResultRange.EMPTY;
}
const total = pagination.totalCount;
if (filteredCount < recordCount) {
return new TableResultRange(0, 0, total, showAll, filteredCount, recordCount);
}
const start = Math.min((Math.max(pagination.currentPage, 1) - 1) * pageSize + 1, total);
const end = Math.max(Math.min(start + recordCount - 1, total), start);
return new TableResultRange(start, end, total, showAll);
}

const total = filteredCount;
if (total === 0) {
return new TableResultRange(0, 0, 0, showAll);
}
if (showAll || total <= pageSize) {
// Matches Buefy, which shows every row when they all fit on one page, whatever the current page.
return new TableResultRange(1, total, total, showAll);
}
const lastPage = Math.ceil(total / pageSize);
const page = Math.min(Math.max(pagination.currentPage, 1), lastPage);
const start = (page - 1) * pageSize + 1;
const end = Math.min(start + pageSize - 1, total);
return new TableResultRange(start, end, total, showAll);
}
}
94 changes: 94 additions & 0 deletions src/breeding-insight/utils/LayoutUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// ResizeObserver is in every supported browser, but not in this TypeScript version's DOM types.
interface ResizeObserverLike {
observe(element: Element): void;
disconnect(): void;
}

type ResizeObserverConstructor = new (callback: () => void) => ResizeObserverLike;

export interface FrameThrottle {
/** Runs the function on the next animation frame, once however often this is called before then. */
schedule(): void;
/** Drops a scheduled run, e.g. when the component is destroyed. */
cancel(): void;
}

export class LayoutUtils {

private static pageResizeSubscribers: Set<() => void> = new Set();
private static pageResizeObserver: ResizeObserverLike | null = null;

/** Wraps a function so that it runs at most once per animation frame. */
static frameThrottle(fn: () => void): FrameThrottle {
let frame: number | null = null;
return {
schedule() {
if (frame !== null) return;
frame = window.requestAnimationFrame(() => {
frame = null;
fn();
});
},
cancel() {
if (frame !== null) {
window.cancelAnimationFrame(frame);
frame = null;
}
}
};
}

/**
* Calls the callback when any of the elements changes size. Returns a function that stops observing.
* Does nothing in browsers without ResizeObserver.
*/
static observeResize(elements: Element[], callback: () => void): () => void {
const observer = LayoutUtils.createResizeObserver(callback);
if (!observer) return () => {};
elements.forEach(element => observer.observe(element));
return () => observer.disconnect();
}

/**
* Calls the callback when the page's height or width changes, e.g. when content above a table
* collapses. Every subscriber shares one observer. Returns a function that unsubscribes.
*/
static onPageResize(callback: () => void): () => void {
LayoutUtils.pageResizeSubscribers.add(callback);
if (!LayoutUtils.pageResizeObserver) {
LayoutUtils.pageResizeObserver = LayoutUtils.createResizeObserver(
() => LayoutUtils.pageResizeSubscribers.forEach(subscriber => subscriber())
);
if (LayoutUtils.pageResizeObserver) LayoutUtils.pageResizeObserver.observe(document.body);
}
return () => {
LayoutUtils.pageResizeSubscribers.delete(callback);
if (LayoutUtils.pageResizeSubscribers.size === 0 && LayoutUtils.pageResizeObserver) {
LayoutUtils.pageResizeObserver.disconnect();
LayoutUtils.pageResizeObserver = null;
}
};
}

private static createResizeObserver(callback: () => void): ResizeObserverLike | null {
const ResizeObserverClass = (window as unknown as { ResizeObserver?: ResizeObserverConstructor }).ResizeObserver;
return ResizeObserverClass ? new ResizeObserverClass(callback) : null;
}
}
6 changes: 6 additions & 0 deletions src/breeding-insight/utils/StringFormatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ export class StringFormatters {
return undefined;
}

/** A count with thousands separators, e.g. 25218 as "25,218". Values that aren't numbers pass through. */
static formatCount(value: number | string): string {
const count = Number(value);
return value === '' || isNaN(count) ? String(value) : count.toLocaleString('en-US');
}

}
2 changes: 2 additions & 0 deletions src/components/admin/AdminProgramsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
</NewDataForm>

<ExpandableTable
record-noun="programs"
record-noun-singular="program"
v-bind:records.sync="programs"
v-bind:loading="this.speciesLoading || this.programsLoading"
v-bind:row-validations="programEditValidations"
Expand Down
2 changes: 2 additions & 0 deletions src/components/admin/AdminUsersTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
</NewDataForm>

<ExpandableTable
record-noun="users"
record-noun-singular="user"
v-bind:records.sync="users"
v-bind:loading="this.rolesLoading || this.usersLoading"
v-bind:row-validations="userValidations"
Expand Down
2 changes: 2 additions & 0 deletions src/components/experiments/ExperimentsObservationsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<div class="is-clearfix"></div>

<ExpandableTable
record-noun="experiments"
record-noun-singular="experiment"
v-bind:records.sync="experiments"
v-bind:loading="this.experimentsLoading"
v-bind:pagination="paginationController"
Expand Down
Loading
Loading