Skip to content

Commit 74f6370

Browse files
committed
chore: Remove sorting and filtering from serial logs table
1 parent 042ea5b commit 74f6370

4 files changed

Lines changed: 12 additions & 85 deletions

File tree

static/js/publisher/pages/SerialLog/SerialLog.tsx

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { useEffect } from "react";
22
import { useAtomValue, useSetAtom } from "jotai";
3-
import { useParams, useSearchParams } from "react-router-dom";
4-
import { Notification, Icon, Row, Col } from "@canonical/react-components";
3+
import { useParams } from "react-router-dom";
4+
import { Notification, Icon } from "@canonical/react-components";
55

66
import { useSerialLogs } from "../../hooks";
7-
import {
8-
serialLogsListFilterState,
9-
serialLogsListState,
10-
} from "../../state/serialLogsState";
7+
import { serialLogsListState } from "../../state/serialLogsState";
118
import { brandIdState, brandStoreState } from "../../state/brandStoreState";
129
import { setPageTitle } from "../../utils";
1310

14-
import Filter from "../../components/Filter";
1511
import SerialLogTable from "./SerialLogTable";
1612

1713
import type { UseQueryResult } from "react-query";
@@ -30,9 +26,7 @@ function SerialLog(): React.JSX.Element {
3026
modelId,
3127
);
3228
const setSerialLogs = useSetAtom(serialLogsListState);
33-
const setFilter = useSetAtom(serialLogsListFilterState);
3429
const brandStore = useAtomValue(brandStoreState(id));
35-
const [searchParams] = useSearchParams();
3630

3731
brandStore
3832
? setPageTitle(`Serial logs in ${brandStore.name}`)
@@ -41,7 +35,6 @@ function SerialLog(): React.JSX.Element {
4135
useEffect(() => {
4236
if (!isLoading && !isError && data) {
4337
setSerialLogs(data.data?.items || []);
44-
setFilter(searchParams.get("filter") || "");
4538
}
4639
}, [isLoading, error, data, brandId, id]);
4740

@@ -63,20 +56,9 @@ function SerialLog(): React.JSX.Element {
6356
{data.message || "Unable to fetch serial logs"}
6457
</Notification>
6558
) : (
66-
<>
67-
<Row>
68-
<Col size={6}>
69-
<Filter
70-
state={serialLogsListFilterState}
71-
label="Search serial logs"
72-
placeholder="Search serial logs"
73-
/>
74-
</Col>
75-
</Row>
76-
<div className="u-flex-column u-flex-grow">
77-
<SerialLogTable />
78-
</div>
79-
</>
59+
<div className="u-flex-column u-flex-grow">
60+
<SerialLogTable />
61+
</div>
8062
)}
8163
</div>
8264
</>

static/js/publisher/pages/SerialLog/SerialLogTable.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@ import { MainTable, TablePagination } from "@canonical/react-components";
44
import { format } from "date-fns";
55

66
import { brandStoreState } from "../../state/brandStoreState";
7-
import { filteredSerialLogsListState } from "../../state/serialLogsState";
8-
import { useSortTableData } from "../../hooks";
7+
import { serialLogsListState } from "../../state/serialLogsState";
98

109
import type { SerialLog } from "../../types/shared";
1110

1211
function SerialLogTable(): React.JSX.Element {
1312
const { id } = useParams();
14-
const serialLogs = useAtomValue(filteredSerialLogsListState);
13+
const serialLogs = useAtomValue(serialLogsListState);
1514
const brandStore = useAtomValue(brandStoreState(id));
1615

1716
const headers = [
1817
{ content: "Brand" },
19-
{
20-
content: "Model",
21-
sortKey: "model-name",
22-
},
23-
{
24-
content: "Serial",
25-
sortKey: "serial",
26-
},
18+
{ content: "Model" },
19+
{ content: "Serial" },
2720
{
2821
content: "Created date",
2922
className: "u-align--right",
@@ -44,20 +37,16 @@ function SerialLogTable(): React.JSX.Element {
4437
};
4538
});
4639

47-
const { rows: sortedRows, updateSort } = useSortTableData({ rows });
48-
4940
return (
5041
<TablePagination
51-
data={sortedRows}
42+
data={rows}
5243
pageLimits={[25, 50, 100, 200]}
5344
position="below"
5445
>
5546
<MainTable
5647
data-testid="serial-log-table"
57-
sortable
5848
emptyStateMsg="No serial logs match this filter"
5949
headers={headers}
60-
onUpdateSort={updateSort}
6150
/>
6251
</TablePagination>
6352
);

static/js/publisher/pages/SerialLog/__tests__/SerialLog.test.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ describe("SerialLog", () => {
9494
).toBeInTheDocument();
9595
});
9696

97-
it("doesn't display filter if user has no serial logs access", () => {
98-
mockuseSerialLogs.mockReturnValue(useSerialLogsNoPermissions);
99-
renderComponent();
100-
expect(
101-
screen.queryByLabelText("Search serial logs"),
102-
).not.toBeInTheDocument();
103-
});
104-
10597
it("doesn't display table if user has no serial logs access", () => {
10698
mockuseSerialLogs.mockReturnValue(useSerialLogsNoPermissions);
10799
renderComponent();
@@ -116,12 +108,6 @@ describe("SerialLog", () => {
116108
).not.toBeInTheDocument();
117109
});
118110

119-
it("displays filter if user has serial logs access", () => {
120-
mockuseSerialLogs.mockReturnValue(useSerialLogsPermissions);
121-
renderComponent();
122-
expect(screen.getByLabelText("Search serial logs")).toBeInTheDocument();
123-
});
124-
125111
it("displays table if user has serial logs access", () => {
126112
mockuseSerialLogs.mockReturnValue(useSerialLogsPermissions);
127113
renderComponent();

static/js/publisher/state/serialLogsState.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,4 @@ import type { SerialLog } from "../types/shared";
44

55
const serialLogsListState = atom([] as SerialLog[]);
66

7-
const serialLogsListFilterState = atom("" as string);
8-
9-
function getFilteredSerialLogs(
10-
serialLogs: Array<SerialLog>,
11-
filterQuery?: string | null,
12-
) {
13-
if (!filterQuery) {
14-
return serialLogs;
15-
}
16-
17-
return serialLogs.filter((serialLog: SerialLog) => {
18-
if (serialLog.serial && serialLog.serial.includes(filterQuery)) {
19-
return true;
20-
}
21-
22-
return false;
23-
});
24-
}
25-
26-
const filteredSerialLogsListState = atom<Array<SerialLog>>((get) => {
27-
const filter = get(serialLogsListFilterState);
28-
const SerialLogs = get(serialLogsListState);
29-
30-
return getFilteredSerialLogs(SerialLogs, filter);
31-
});
32-
33-
export {
34-
serialLogsListState,
35-
serialLogsListFilterState,
36-
filteredSerialLogsListState,
37-
};
7+
export { serialLogsListState };

0 commit comments

Comments
 (0)