Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
epompeii committed Oct 5, 2023
1 parent dd8b448 commit bd59551
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 50 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions scripts/smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ while ! nc -z localhost 61016; do
sleep 1
done

RUST_BACKTRACE=full cargo test --features seed --test seed -- --nocapture

source ../../scripts/mock.sh
source ../../scripts/seed.sh
5 changes: 1 addition & 4 deletions services/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,13 @@ async-compression = { version = "0.4", features = ["tokio", "gzip"] }
aws-credential-types = "0.56"
aws-sdk-s3 = "0.31"
css-inline = "0.11"
diesel = { version = "2.1", features = ["sqlite", "chrono"] }
diesel = { version = "2.1", features = ["chrono", "sqlite"] }
diesel_migrations = "2.1"
hyper = "0.14"
http = "0.2"
mail-send = "0.4"
sentry = { version = "0.31", optional = true }

[dev-dependencies]
pretty_assertions.workspace = true

[[bin]]
name = "api"

Expand Down
11 changes: 7 additions & 4 deletions services/api/src/util/typed_uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ macro_rules! typed_uuid {
impl<DB> diesel::serialize::ToSql<diesel::sql_types::Text, DB> for $name
where
DB: diesel::backend::Backend,
str: diesel::serialize::ToSql<diesel::sql_types::Text, DB>,
for<'a> String: diesel::serialize::ToSql<diesel::sql_types::Text, DB>
+ Into<
<DB::BindCollector<'a> as diesel::query_builder::BindCollector<'a, DB>>::Buffer,
>,
{
fn to_sql<'b>(
&'b self,
out: &mut diesel::serialize::Output<'b, '_, DB>,
) -> diesel::serialize::Result {
// TODO it may be worth imitating this impl
// https://docs.rs/diesel/2.1.2/src/diesel/pg/types/uuid.rs.html#23
std::str::from_utf8(self.0.as_bytes())?.to_sql(out)
// https://docs.rs/diesel/latest/diesel/serialize/trait.ToSql.html#examples
out.set_value(self.to_string());
Ok(diesel::serialize::IsNull::No)
}
}

Expand Down
4 changes: 2 additions & 2 deletions services/console/src/components/console/perf/PerfHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { debounce } from "@solid-primitives/scheduled";
import {
Accessor,
type Accessor,
createEffect,
createMemo,
createSignal,
Resource,
type Resource,
Show,
} from "solid-js";
import type {
Expand Down
27 changes: 23 additions & 4 deletions services/console/src/components/console/perf/plot/PlotTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { For, type Accessor, Switch, Match } from "solid-js";
import { For, type Accessor, Switch, Match, createMemo } from "solid-js";
import { PerfTab } from "../../../../config/types";
import type {
JsonBenchmark,
Expand Down Expand Up @@ -76,6 +76,25 @@ const PlotTab = (props: Props) => {
}
};

const reportsLength = createMemo(() => props.reports_tab.length);
const branchesLength = createMemo(() => props.branches_tab.length);
const testbedsLength = createMemo(() => props.testbeds_tab.length);
const benchmarksLength = createMemo(() => props.benchmarks_tab.length);
const getTabLength = () => {
switch (props.tab()) {
case PerfTab.REPORTS:
return reportsLength;
case PerfTab.BRANCHES:
return branchesLength;
case PerfTab.TESTBEDS:
return testbedsLength;
case PerfTab.BENCHMARKS:
return benchmarksLength;
default:
return () => 0;
}
};

const getPerPage = () => {
switch (props.tab()) {
case PerfTab.REPORTS:
Expand Down Expand Up @@ -174,9 +193,9 @@ const PlotTab = (props: Props) => {
<br />
<Pagination
size={PaginationSize.SMALL}
data_len={getTab()?.length}
per_page={getPerPage()?.()}
page={getPage()?.()}
data_len={getTabLength()}
per_page={getPerPage()}
page={getPage()}
handlePage={getHandlePage()}
/>
<br />
Expand Down
7 changes: 4 additions & 3 deletions services/console/src/components/console/table/TablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const TablePanel = (props: Props) => {
fetcher,
getData,
);
const tableDataLength = createMemo(() => tableData()?.length);

createEffect(() => {
const newParams: Record<string, null | number | boolean> = {};
Expand Down Expand Up @@ -192,9 +193,9 @@ const TablePanel = (props: Props) => {
<div class="container">
<Pagination
size={PaginationSize.REGULAR}
data_len={tableData()?.length}
per_page={per_page()}
page={page()}
data_len={tableDataLength}
per_page={per_page}
page={page}
handlePage={handlePage}
/>
</div>
Expand Down
11 changes: 6 additions & 5 deletions services/console/src/components/field/kinds/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export interface RadioConfig {

const Radio = (props: Props) => {
const params = createMemo(() => props.params);
const per_page = 8;
const per_page = createMemo(() => 8);
const [page, setPage] = createSignal(1);

const fetcher = createMemo(() => {
return {
url: props.config?.url(params(), per_page, page()),
url: props.config?.url(params(), per_page(), page()),
token: authUser()?.token,
};
});
Expand All @@ -48,6 +48,7 @@ const Radio = (props: Props) => {
});
};
const [data] = createResource(fetcher, getRadio);
const dataLength = createMemo(() => data()?.length);

return (
<>
Expand Down Expand Up @@ -90,7 +91,7 @@ const Radio = (props: Props) => {
</>
)}
</For>
{data()?.length === 0 && page() !== 1 && (
{dataLength() === 0 && page() !== 1 && (
<BackButton
name={props.config?.name}
page={page()}
Expand All @@ -105,9 +106,9 @@ const Radio = (props: Props) => {
<div class="column is-half">
<Pagination
size={PaginationSize.SMALL}
data_len={data()?.length}
data_len={dataLength}
per_page={per_page}
page={page()}
page={page}
handlePage={setPage}
/>
</div>
Expand Down
11 changes: 6 additions & 5 deletions services/console/src/components/perf/PublicProjects.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Accessor,
type Accessor,
createEffect,
createMemo,
createResource,
Expand Down Expand Up @@ -78,6 +78,7 @@ const PublicProjects = (props: Props) => {
});
};
const [projects] = createResource<JsonProject[]>(fetcher, fetchProjects);
const projectsLength = createMemo(() => projects()?.length);

createEffect(() => {
const newParams: Record<string, number> = {};
Expand Down Expand Up @@ -118,7 +119,7 @@ const PublicProjects = (props: Props) => {
</a>
)}
</For>
{projects()?.length === 0 && page() !== 1 && (
{projectsLength() === 0 && page() !== 1 && (
<div class="box">
<BackButton page={page} handlePage={handlePage} />
</div>
Expand All @@ -129,9 +130,9 @@ const PublicProjects = (props: Props) => {
</div>
<Pagination
size={PaginationSize.REGULAR}
data_len={projects()?.length}
per_page={per_page()}
page={page()}
data_len={projectsLength}
per_page={per_page}
page={page}
handlePage={handlePage}
/>
</div>
Expand Down
40 changes: 21 additions & 19 deletions services/console/src/components/site/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Accessor } from "solid-js";

export enum PaginationSize {
SMALL = "is-small",
REGULAR = "",
Expand All @@ -7,9 +9,9 @@ export enum PaginationSize {

const Pagination = (props: {
size: PaginationSize;
data_len: undefined | number;
per_page: number;
page: number;
data_len: Accessor<undefined | number>;
per_page: Accessor<number>;
page: Accessor<number>;
handlePage: (page: number) => void;
}) => {
return (
Expand All @@ -21,16 +23,16 @@ const Pagination = (props: {
<button
class="pagination-previous"
title="Go to previous page"
disabled={props.page < 2}
disabled={props.page() < 2}
onClick={(e) => {
e.preventDefault();
props.handlePage(props.page - 1);
props.handlePage(props.page() - 1);
}}
>
Previous
</button>
<ul class="pagination-list">
{props.page > 2 && (
{props.page() > 2 && (
<li>
<button
class="pagination-link"
Expand All @@ -44,56 +46,56 @@ const Pagination = (props: {
</button>
</li>
)}
{props.page > 3 && (
{props.page() > 3 && (
<li>
<span class="pagination-ellipsis">&hellip;</span>
</li>
)}
{props.page > 1 && (
{props.page() > 1 && (
<li>
<button
class="pagination-link"
title={`Go to page ${props.page - 1}`}
title={`Go to page ${props.page() - 1}`}
onClick={(e) => {
e.preventDefault();
props.handlePage(props.page - 1);
props.handlePage(props.page() - 1);
}}
>
{props.page - 1}
{props.page() - 1}
</button>
</li>
)}
<li>
<button
class="pagination-link is-current"
title={`Page ${props.page}`}
title={`Page ${props.page()}`}
aria-current="page"
>
{props.page ? props.page : 0}
{props.page() ? props.page() : 0}
</button>
</li>
{props.data_len === props.per_page && (
{props.data_len() === props.per_page() && (
<li>
<button
class="pagination-link"
title={`Go to page ${props.page + 1}`}
title={`Go to page ${props.page() + 1}`}
onClick={(e) => {
e.preventDefault();
props.handlePage(props.page + 1);
props.handlePage(props.page() + 1);
}}
>
{props.page + 1}
{props.page() + 1}
</button>
</li>
)}
</ul>
<button
class="pagination-next"
title="Go to next page"
disabled={props.data_len < props.per_page}
disabled={props.data_len() < props.per_page()}
onClick={(e) => {
e.preventDefault();
props.handlePage(props.page + 1);
props.handlePage(props.page() + 1);
}}
>
Next page
Expand Down

0 comments on commit bd59551

Please sign in to comment.