Skip to content

Commit a82a3cd

Browse files
committed
tidy up feature patch I made last night
1 parent e504c46 commit a82a3cd

File tree

7 files changed

+164
-343
lines changed

7 files changed

+164
-343
lines changed

next/utils/colunnData/azure.tsx

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { PricingUnit } from "@/types";
2-
import { ColumnDef, Row } from "@tanstack/react-table";
2+
import { ColumnDef } from "@tanstack/react-table";
33
import {
44
doAllDataTablesMigrations,
55
gt,
66
regex,
77
makeSchemaWithDefaults,
8+
makeCellWithRegexSorter,
89
} from "./shared";
910
import { CostDuration } from "@/types";
1011
import RegionLinkPreloader from "@/components/RegionLinkPreloader";
@@ -188,28 +189,6 @@ export function calculateAndFormatCost(
188189
return `$${perTime.toFixed(precision)}${pricingMeasuringUnits}`;
189190
}
190191

191-
function makeCellWithRegexSorter(
192-
cellGet: (cell: { getValue: () => any; row: Row<AzureInstance> }) => any,
193-
): {
194-
cell: (info: { getValue: () => any; row: Row<AzureInstance> }) => any;
195-
filterFn: (
196-
row: Row<AzureInstance>,
197-
columnId: string,
198-
filterValue: string,
199-
) => boolean;
200-
} {
201-
return {
202-
cell: cellGet,
203-
filterFn: regex({
204-
getCell: (row) =>
205-
cellGet({
206-
getValue: () => row.original.pricing,
207-
row,
208-
}),
209-
}),
210-
};
211-
}
212-
213192
export const columnsGen = (
214193
selectedRegion: string,
215194
pricingUnit: PricingUnit,
@@ -311,7 +290,7 @@ export const columnsGen = (
311290
);
312291
return valueA - valueB;
313292
},
314-
...makeCellWithRegexSorter((info) => {
293+
...makeCellWithRegexSorter("pricing", (info) => {
315294
const pricing = info.getValue() as AzurePricing | undefined;
316295
const price = pricing?.[selectedRegion]?.linux?.ondemand;
317296
return calculateAndFormatCost(
@@ -345,7 +324,7 @@ export const columnsGen = (
345324
);
346325
return valueA - valueB;
347326
},
348-
...makeCellWithRegexSorter((info) => {
327+
...makeCellWithRegexSorter("pricing", (info) => {
349328
const pricing = info.getValue() as AzurePricing | undefined;
350329
const price =
351330
pricing?.[selectedRegion]?.linux?.reserved?.[savingsKey];
@@ -380,7 +359,7 @@ export const columnsGen = (
380359
);
381360
return valueA - valueB;
382361
},
383-
...makeCellWithRegexSorter((info) => {
362+
...makeCellWithRegexSorter("pricing", (info) => {
384363
const pricing = info.getValue() as AzurePricing | undefined;
385364
const price =
386365
pricing?.[selectedRegion]?.linux?.reserved?.[reservedTerm];
@@ -411,7 +390,7 @@ export const columnsGen = (
411390
);
412391
return valueA - valueB;
413392
},
414-
...makeCellWithRegexSorter((info) => {
393+
...makeCellWithRegexSorter("pricing", (info) => {
415394
const pricing = info.getValue() as AzurePricing | undefined;
416395
const price = pricing?.[selectedRegion]?.linux?.spot_min;
417396
return calculateAndFormatCost(
@@ -441,7 +420,7 @@ export const columnsGen = (
441420
);
442421
return valueA - valueB;
443422
},
444-
...makeCellWithRegexSorter((info) => {
423+
...makeCellWithRegexSorter("pricing", (info) => {
445424
const pricing = info.getValue() as AzurePricing | undefined;
446425
const price = pricing?.[selectedRegion]?.windows?.ondemand;
447426
return calculateAndFormatCost(
@@ -473,7 +452,7 @@ export const columnsGen = (
473452
);
474453
return valueA - valueB;
475454
},
476-
...makeCellWithRegexSorter((info) => {
455+
...makeCellWithRegexSorter("pricing", (info) => {
477456
const pricing = info.getValue() as AzurePricing | undefined;
478457
const price =
479458
pricing?.[selectedRegion]?.windows?.reserved?.[savingsKey];
@@ -506,7 +485,7 @@ export const columnsGen = (
506485
);
507486
return valueA - valueB;
508487
},
509-
...makeCellWithRegexSorter((info) => {
488+
...makeCellWithRegexSorter("pricing", (info) => {
510489
const pricing = info.getValue() as AzurePricing | undefined;
511490
const price =
512491
pricing?.[selectedRegion]?.windows?.reserved?.[
@@ -539,7 +518,7 @@ export const columnsGen = (
539518
);
540519
return valueA - valueB;
541520
},
542-
...makeCellWithRegexSorter((info) => {
521+
...makeCellWithRegexSorter("pricing", (info) => {
543522
const pricing = info.getValue() as AzurePricing | undefined;
544523
const price = pricing?.[selectedRegion]?.windows?.spot_min;
545524
return calculateAndFormatCost(

next/utils/colunnData/cache.tsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
gt,
66
makeSchemaWithDefaults,
77
regex,
8+
makeCellWithRegexSorter,
89
} from "./shared";
910
import { EC2Instance, PricingUnit, CostDuration, Pricing } from "@/types";
1011
import RegionLinkPreloader from "@/components/RegionLinkPreloader";
1112
import sortByInstanceType from "../sortByInstanceType";
12-
import { makeCellWithRegexSorter } from "./ec2/columns";
1313

1414
const initialColumnsArr = [
1515
["pretty_name", true],
@@ -136,7 +136,7 @@ export const columnsGen = (
136136
id: "cost-ondemand-redis",
137137
header: "Redis Cost",
138138
sortingFn: "alphanumeric",
139-
...makeCellWithRegexSorter((info) => {
139+
...makeCellWithRegexSorter("pricing", (info) => {
140140
const pricing = info.getValue() as Pricing;
141141
const region = pricing[selectedRegion];
142142
if (!region) return "N/A";
@@ -153,7 +153,7 @@ export const columnsGen = (
153153
id: "cost-reserved-redis",
154154
header: "Redis Reserved Cost",
155155
sortingFn: "alphanumeric",
156-
...makeCellWithRegexSorter((info) => {
156+
...makeCellWithRegexSorter("pricing", (info) => {
157157
const pricing = info.getValue() as Pricing;
158158
const region = pricing[selectedRegion];
159159
if (!region) return "N/A";
@@ -170,7 +170,7 @@ export const columnsGen = (
170170
id: "cost-ondemand-memcached",
171171
header: "Memcached On Demand Cost",
172172
sortingFn: "alphanumeric",
173-
...makeCellWithRegexSorter((info) => {
173+
...makeCellWithRegexSorter("pricing", (info) => {
174174
const pricing = info.getValue() as Pricing;
175175
const region = pricing[selectedRegion];
176176
if (!region) return "N/A";
@@ -187,7 +187,7 @@ export const columnsGen = (
187187
id: "cost-reserved-memcached",
188188
header: "Memcached Reserved Cost",
189189
sortingFn: "alphanumeric",
190-
...makeCellWithRegexSorter((info) => {
190+
...makeCellWithRegexSorter("pricing", (info) => {
191191
const pricing = info.getValue() as Pricing;
192192
const region = pricing[selectedRegion];
193193
if (!region) return "N/A";
@@ -204,7 +204,7 @@ export const columnsGen = (
204204
id: "cost-ondemand-valkey",
205205
header: "Valkey On Demand Cost",
206206
sortingFn: "alphanumeric",
207-
...makeCellWithRegexSorter((info) => {
207+
...makeCellWithRegexSorter("pricing", (info) => {
208208
const pricing = info.getValue() as Pricing;
209209
const region = pricing[selectedRegion];
210210
if (!region) return "N/A";
@@ -221,7 +221,7 @@ export const columnsGen = (
221221
id: "cost-reserved-valkey",
222222
header: "Valkey Reserved Cost",
223223
sortingFn: "alphanumeric",
224-
...makeCellWithRegexSorter((info) => {
224+
...makeCellWithRegexSorter("pricing", (info) => {
225225
const pricing = info.getValue() as Pricing;
226226
const region = pricing[selectedRegion];
227227
if (!region) return "N/A";
@@ -238,17 +238,10 @@ export const columnsGen = (
238238
id: "generation",
239239
header: "Generation",
240240
sortingFn: "alphanumeric",
241-
filterFn: regex({
242-
getCell: (row) => {
243-
// @ts-expect-error: Not typed
244-
const v = row.original.currentGeneration;
245-
if (v === "Yes") return "current";
246-
return "previous";
247-
},
248-
}),
249-
cell: (info) => {
241+
// @ts-expect-error: This accessor is not typed right now.
242+
...makeCellWithRegexSorter("currentGeneration", (info) => {
250243
if (info.getValue() === "Yes") return "current";
251244
return "previous";
252-
},
245+
}),
253246
},
254247
];

0 commit comments

Comments
 (0)