Skip to content

Commit

Permalink
frontend: use more css modules; small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Jun 30, 2023
1 parent cbd79c4 commit fa4ebdd
Show file tree
Hide file tree
Showing 115 changed files with 1,095 additions and 1,177 deletions.
1 change: 0 additions & 1 deletion backend/trcustoms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def parse_date_range(
) -> tuple[datetime | None, datetime | None] | None:
date_min: datetime | None = None
date_max: datetime | None = None
print("source", source, flush=1)
if source and (
match := re.match(r"^(?P<year>\d{4})(?:-(?P<month>\d{1,2}))?$", source)
):
Expand Down
38 changes: 0 additions & 38 deletions frontend/src/App.css

This file was deleted.

1 change: 0 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "./App.css";
import "./themes.css";
import { useEffect } from "react";
import { Routes } from "react-router-dom";
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/components/common/AuditLogSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,16 @@ const AuditLogSearch = ({
>
{({ submitForm, resetForm }) => (
<Form className="ChildMarginClear">
<SectionHeader className={styles.header}>
Search filter
<Link
className={styles.resetButton}
onClick={() => handleClear(resetForm)}
>
(reset)
</Link>
<SectionHeader>
<span className={styles.header}>
Search filter
<Link
className={styles.resetButton}
onClick={() => handleClear(resetForm)}
>
(reset)
</Link>
</span>
</SectionHeader>

<div className={styles.form}>
Expand Down
37 changes: 0 additions & 37 deletions frontend/src/components/common/AuditLogTable/index.css

This file was deleted.

26 changes: 26 additions & 0 deletions frontend/src/components/common/AuditLogTable/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.table :global td {
border-bottom: 1px solid var(--label-bg-color);
}

.table :global .created,
.table :global .author {
white-space: nowrap;
width: 10%;
}

.table :global .object {
width: 40%;
}
.table :global .changes {
width: 40%;
}

.changesWrapper {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 0 0.5rem;
}
.requiresAction {
white-space: nowrap;
}
26 changes: 12 additions & 14 deletions frontend/src/components/common/AuditLogTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./index.css";
import styles from "./index.module.css";
import { useQuery } from "react-query";
import type { DataTableColumn } from "src/components/common/DataTable";
import { DataTable } from "src/components/common/DataTable";
Expand Down Expand Up @@ -192,10 +192,10 @@ const AuditLogTable = ({
name: "changes",
label: "Changes",
itemElement: ({ item }) => (
<span className="AuditLogTable--changesWrapper">
<span className={styles.changesWrapper}>
{item.changes.join(" ")}
{item.is_action_required && (
<span className="AuditLogTable--requiresAction">
<span className={styles.requiresAction}>
<IconExclamation /> Requires action
</span>
)}
Expand All @@ -207,17 +207,15 @@ const AuditLogTable = ({
const itemKey = (auditLog: AuditLogListing) => `${auditLog.id}`;

return (
<div className="AuditLogTable">
<DataTable
className="AuditLogTable"
queryName="auditLogs"
columns={columns}
itemKey={itemKey}
searchQuery={searchQuery}
searchFunc={AuditLogService.searchAuditLogs}
onSearchQueryChange={onSearchQueryChange}
/>
</div>
<DataTable
className={styles.table}
queryName="auditLogs"
columns={columns}
itemKey={itemKey}
searchQuery={searchQuery}
searchFunc={AuditLogService.searchAuditLogs}
onSearchQueryChange={onSearchQueryChange}
/>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.Checkbox--label {
.label {
cursor: pointer;
}

.Checkbox--input {
.input {
position: relative;
cursor: pointer;
width: 20px;
Expand All @@ -12,7 +12,7 @@
margin: 0 0.5rem 0 0;
display: inline-flex;
}
.Checkbox--input:before {
.input:before {
content: "";
display: block;
position: absolute;
Expand All @@ -25,7 +25,7 @@
color: var(--input-fg-color);
box-sizing: border-box;
}
.Checkbox--input:checked:before {
.input:checked:before {
content: "";
display: block;
position: absolute;
Expand All @@ -36,7 +36,7 @@
border-color: var(--button-bg-color);
background-color: var(--button-bg-color);
}
.Checkbox--input:checked:after {
.input:checked:after {
content: "";
display: block;
width: 30%;
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/common/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./index.css";
import styles from "./index.module.css";

interface CheckboxProps {
label: string | React.ReactNode;
Expand All @@ -9,9 +9,9 @@ interface CheckboxProps {

const Checkbox = ({ label, ...props }: CheckboxProps) => {
return (
<div className="Checkbox">
<label className="Checkbox--label">
<input type="checkbox" className="Checkbox--input" {...props} />
<div>
<label className={styles.label}>
<input type="checkbox" className={styles.input} {...props} />
{label}
</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.DataList--page {
.page {
display: contents;
}
49 changes: 30 additions & 19 deletions frontend/src/components/common/DataList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./index.css";
import styles from "./index.module.css";
import { useRef } from "react";
import { Fragment } from "react";
import { useEffect } from "react";
Expand All @@ -17,6 +17,7 @@ interface DataListProps<TItem, TQuery> {
queryName: string;
itemKey: (item: TItem) => string;
itemView: (item: TItem) => React.ReactNode;
pageView?: (children: React.ReactNode) => React.ReactNode;

searchQuery: TQuery;
searchFunc: (
Expand All @@ -27,6 +28,11 @@ interface DataListProps<TItem, TQuery> {
onSearchQueryChange?: ((searchQuery: TQuery) => void) | undefined;
}

interface ConcreteDataListProps<TItem, TQuery>
extends DataListProps<TItem, TQuery> {
pageView: (children: React.ReactNode) => React.ReactNode;
}

const PagedDataList = <TItem extends {}, TQuery extends GenericSearchQuery>({
className,
searchQuery,
Expand All @@ -35,8 +41,9 @@ const PagedDataList = <TItem extends {}, TQuery extends GenericSearchQuery>({
onSearchQueryChange,
itemKey,
itemView,
pageView,
queryName,
}: DataListProps<TItem, TQuery>) => {
}: ConcreteDataListProps<TItem, TQuery>) => {
const result = useQuery<GenericSearchResult<TQuery, TItem>, Error>(
[queryName, searchFunc, searchQuery],
async () => searchFunc(searchQuery)
Expand All @@ -55,13 +62,13 @@ const PagedDataList = <TItem extends {}, TQuery extends GenericSearchQuery>({
}

return (
<div className={`DataList ChildMarginClear ${className || ""}`}>
<div className={`ChildMarginClear ${className || ""}`}>
{result.data.results.length ? (
<div className="DataList--body">
{result.data.results.map((item) => (
pageView(
result.data.results.map((item) => (
<Fragment key={itemKey(item)}>{itemView(item)}</Fragment>
))}
</div>
))
)
) : (
<p>There are no results to show.</p>
)}
Expand All @@ -87,8 +94,9 @@ const InfiniteDataList = <TItem extends {}, TQuery extends GenericSearchQuery>({
onResultCountChange,
itemKey,
itemView,
pageView,
queryName,
}: DataListProps<TItem, TQuery>) => {
}: ConcreteDataListProps<TItem, TQuery>) => {
const result = useInfiniteQuery<GenericSearchResult<TQuery, TItem>, Error>(
[queryName, searchQuery],
async ({ pageParam }) => {
Expand Down Expand Up @@ -131,20 +139,20 @@ const InfiniteDataList = <TItem extends {}, TQuery extends GenericSearchQuery>({
}, [onResultCountChange, result]);

return (
<div className={`DataList ChildMarginClear ${className}`}>
<div className={`ChildMarginClear ${className}`}>
{result.data?.pages?.[0]?.total_count === 0 && (
<p>There are no results to show.</p>
)}

<div className="DataList--body">
{result.data?.pages?.map((result, i) => (
<div key={`body${i}`} className="DataList--page">
{pageView(
result.data?.pages?.map((result, i) => (
<div key={`body${i}`} className={styles.page}>
{result.results.map((item) => (
<Fragment key={itemKey(item)}>{itemView(item)}</Fragment>
))}
</div>
))}
</div>
))
)}

<span ref={infiniteScrollRef} />

Expand All @@ -153,14 +161,17 @@ const InfiniteDataList = <TItem extends {}, TQuery extends GenericSearchQuery>({
);
};

const DataList = <TItem extends {}, TQuery extends GenericSearchQuery>(
props: DataListProps<TItem, TQuery>
) => {
const DataList = <TItem extends {}, TQuery extends GenericSearchQuery>({
pageView,
...props
}: DataListProps<TItem, TQuery>) => {
const { infiniteScroll } = useSettings();
pageView ||= (children) => <div>{children}</div>;

if (infiniteScroll) {
return <InfiniteDataList {...props} />;
return <InfiniteDataList pageView={pageView} {...props} />;
}
return <PagedDataList {...props} />;
return <PagedDataList pageView={pageView} {...props} />;
};

export { PagedDataList, InfiniteDataList, DataList };
30 changes: 0 additions & 30 deletions frontend/src/components/common/DataTable/index.css

This file was deleted.

Loading

0 comments on commit fa4ebdd

Please sign in to comment.