Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use EntriesList everywhere #2161

Merged
merged 1 commit into from
Apr 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import _ from "lodash";
import { SearchLink } from "./SearchLink";

export const EntriesList = ({ entries, fields, extra }) => {
export const EntriesList = ({ entries, fields, extraColumn }) => {
const grouped = _.groupBy(entries, (e) => fields.map((n) => e[n]).join(","));
const sorted = _.reverse(_.sortBy(_.values(grouped), "length")).map((a) => ({
count: a.length,
Expand All @@ -15,7 +15,7 @@ export const EntriesList = ({ entries, fields, extra }) => {
{fields.map((field) => (
<td key={field}>{e[field]}</td>
))}
<td>{extra && extra(e)}</td>
<td>{extraColumn && extraColumn(e)}</td>
<td>
<SearchLink e={e} fields={fields} />
</td>
Expand Down
22 changes: 0 additions & 22 deletions app/javascript/src/admin/micro-clusters/CollectedInksList.jsx

This file was deleted.

18 changes: 15 additions & 3 deletions app/javascript/src/admin/micro-clusters/DisplayMacroClusters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ScrollIntoViewIfNeeded from "react-scroll-into-view-if-needed";
import { matchSorter } from "match-sorter";

import { CollectedInksList } from "./CollectedInksList";
import { SearchLink } from "../components/clustering/SearchLink";
import { StateContext, DispatchContext } from "./GenericApp";
import {
Expand All @@ -18,6 +17,7 @@
setInBrandSelector
} from "../components/clustering/keyDownListener";
import { useCallback } from "react";
import { EntriesList } from "../components/clustering/EntriesList";

export const DisplayMacroClusters = ({ afterAssign, assignCluster }) => {
const dispatch = useContext(DispatchContext);
Expand Down Expand Up @@ -239,10 +239,12 @@
<td colSpan="7">
<table className="table macro-cluster-collected-inks">
<tbody>
<CollectedInksList
collectedInks={macroCluster.micro_clusters
<EntriesList
entries={macroCluster.micro_clusters
.map((c) => c.entries)
.flat()}
fields={["brand_name", "line_name", "ink_name"]}
extraColumn={extraColumn}
/>
</tbody>
</table>
Expand All @@ -252,3 +254,13 @@
</>
);
};

const extraColumn = (ci) => (
<div

Check warning on line 259 in app/javascript/src/admin/micro-clusters/DisplayMacroClusters.jsx

View check run for this annotation

Codecov / codecov/patch

app/javascript/src/admin/micro-clusters/DisplayMacroClusters.jsx#L259

Added line #L259 was not covered by tests
style={{
backgroundColor: ci.color,
height: "45px",
width: "45px"
}}
/>
);
21 changes: 18 additions & 3 deletions app/javascript/src/admin/micro-clusters/DisplayMicroCluster.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import { StateContext } from "./GenericApp";
import { DisplayMacroClusters } from "./DisplayMacroClusters";
import { CollectedInksList } from "./CollectedInksList";
import { CreateRow } from "../components/clustering/CreateRow";
import { createMacroClusterAndAssign } from "./createMacroClusterAndAssign";
import { ignoreCluster } from "./ignoreCluster";
import { EntriesList } from "../components/clustering/EntriesList";

export const DisplayMicroCluster = ({ afterCreate, assignCluster }) => {
const { activeCluster } = useContext(StateContext);
const fields = ["brand_name", "line_name", "ink_name"];

Check warning on line 12 in app/javascript/src/admin/micro-clusters/DisplayMicroCluster.jsx

View check run for this annotation

Codecov / codecov/patch

app/javascript/src/admin/micro-clusters/DisplayMicroCluster.jsx#L12

Added line #L12 was not covered by tests
return (
<div className="fpc-table fpc-table--full-width fpc-scroll-shadow">
<table className="table">
Expand All @@ -17,11 +18,15 @@
afterCreate={afterCreate}
createMacroClusterAndAssign={createMacroClusterAndAssign}
ignoreCluster={ignoreCluster}
fields={["brand_name", "line_name", "ink_name"]}
fields={fields}
/>
</thead>
<tbody>
<CollectedInksList collectedInks={activeCluster.entries} />
<EntriesList
entries={activeCluster.entries}
fields={fields}
extraColumn={extraColumn}
/>
<tr>
<td colSpan="8" style={{ backgroundColor: "black" }}></td>
</tr>
Expand All @@ -34,3 +39,13 @@
</div>
);
};

const extraColumn = (ci) => (
<div

Check warning on line 44 in app/javascript/src/admin/micro-clusters/DisplayMicroCluster.jsx

View check run for this annotation

Codecov / codecov/patch

app/javascript/src/admin/micro-clusters/DisplayMicroCluster.jsx#L44

Added line #L44 was not covered by tests
style={{
backgroundColor: ci.color,
height: "45px",
width: "45px"
}}
/>
);
Loading