Skip to content

Commit e504c46

Browse files
committed
add back regex support (fixes #781)
1 parent 94e5742 commit e504c46

File tree

7 files changed

+495
-157
lines changed

7 files changed

+495
-157
lines changed

next/utils/colunnData/azure.tsx

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { PricingUnit } from "@/types";
2-
import { ColumnDef } from "@tanstack/react-table";
3-
import { doAllDataTablesMigrations, gt } from "./shared";
4-
import { makeSchemaWithDefaults } from "./shared";
2+
import { ColumnDef, Row } from "@tanstack/react-table";
3+
import {
4+
doAllDataTablesMigrations,
5+
gt,
6+
regex,
7+
makeSchemaWithDefaults,
8+
} from "./shared";
59
import { CostDuration } from "@/types";
610
import RegionLinkPreloader from "@/components/RegionLinkPreloader";
711

@@ -184,6 +188,28 @@ export function calculateAndFormatCost(
184188
return `$${perTime.toFixed(precision)}${pricingMeasuringUnits}`;
185189
}
186190

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+
187213
export const columnsGen = (
188214
selectedRegion: string,
189215
pricingUnit: PricingUnit,
@@ -198,6 +224,7 @@ export const columnsGen = (
198224
id: "pretty_name_azure",
199225
header: "Name",
200226
sortingFn: "alphanumeric",
227+
filterFn: regex({}),
201228
},
202229
{
203230
accessorKey: "instance_type",
@@ -215,6 +242,7 @@ export const columnsGen = (
215242
</RegionLinkPreloader>
216243
);
217244
},
245+
filterFn: regex({}),
218246
},
219247
{
220248
accessorKey: "memory",
@@ -254,6 +282,7 @@ export const columnsGen = (
254282
header: "GPUs",
255283
size: 160,
256284
id: "GPU",
285+
filterFn: regex({}),
257286
},
258287
{
259288
accessorKey: "size",
@@ -282,7 +311,7 @@ export const columnsGen = (
282311
);
283312
return valueA - valueB;
284313
},
285-
cell: (info) => {
314+
...makeCellWithRegexSorter((info) => {
286315
const pricing = info.getValue() as AzurePricing | undefined;
287316
const price = pricing?.[selectedRegion]?.linux?.ondemand;
288317
return calculateAndFormatCost(
@@ -291,7 +320,7 @@ export const columnsGen = (
291320
pricingUnit,
292321
costDuration,
293322
);
294-
},
323+
}),
295324
},
296325
{
297326
accessorKey: "pricing",
@@ -316,7 +345,7 @@ export const columnsGen = (
316345
);
317346
return valueA - valueB;
318347
},
319-
cell: (info) => {
348+
...makeCellWithRegexSorter((info) => {
320349
const pricing = info.getValue() as AzurePricing | undefined;
321350
const price =
322351
pricing?.[selectedRegion]?.linux?.reserved?.[savingsKey];
@@ -326,7 +355,7 @@ export const columnsGen = (
326355
pricingUnit,
327356
costDuration,
328357
);
329-
},
358+
}),
330359
},
331360
{
332361
accessorKey: "pricing",
@@ -351,7 +380,7 @@ export const columnsGen = (
351380
);
352381
return valueA - valueB;
353382
},
354-
cell: (info) => {
383+
...makeCellWithRegexSorter((info) => {
355384
const pricing = info.getValue() as AzurePricing | undefined;
356385
const price =
357386
pricing?.[selectedRegion]?.linux?.reserved?.[reservedTerm];
@@ -361,7 +390,7 @@ export const columnsGen = (
361390
pricingUnit,
362391
costDuration,
363392
);
364-
},
393+
}),
365394
},
366395
{
367396
accessorKey: "pricing",
@@ -382,7 +411,7 @@ export const columnsGen = (
382411
);
383412
return valueA - valueB;
384413
},
385-
cell: (info) => {
414+
...makeCellWithRegexSorter((info) => {
386415
const pricing = info.getValue() as AzurePricing | undefined;
387416
const price = pricing?.[selectedRegion]?.linux?.spot_min;
388417
return calculateAndFormatCost(
@@ -391,7 +420,7 @@ export const columnsGen = (
391420
pricingUnit,
392421
costDuration,
393422
);
394-
},
423+
}),
395424
},
396425
{
397426
accessorKey: "pricing",
@@ -412,7 +441,7 @@ export const columnsGen = (
412441
);
413442
return valueA - valueB;
414443
},
415-
cell: (info) => {
444+
...makeCellWithRegexSorter((info) => {
416445
const pricing = info.getValue() as AzurePricing | undefined;
417446
const price = pricing?.[selectedRegion]?.windows?.ondemand;
418447
return calculateAndFormatCost(
@@ -421,7 +450,7 @@ export const columnsGen = (
421450
pricingUnit,
422451
costDuration,
423452
);
424-
},
453+
}),
425454
},
426455
{
427456
accessorKey: "pricing",
@@ -444,7 +473,7 @@ export const columnsGen = (
444473
);
445474
return valueA - valueB;
446475
},
447-
cell: (info) => {
476+
...makeCellWithRegexSorter((info) => {
448477
const pricing = info.getValue() as AzurePricing | undefined;
449478
const price =
450479
pricing?.[selectedRegion]?.windows?.reserved?.[savingsKey];
@@ -454,7 +483,7 @@ export const columnsGen = (
454483
pricingUnit,
455484
costDuration,
456485
);
457-
},
486+
}),
458487
},
459488
{
460489
accessorKey: "pricing",
@@ -477,7 +506,7 @@ export const columnsGen = (
477506
);
478507
return valueA - valueB;
479508
},
480-
cell: (info) => {
509+
...makeCellWithRegexSorter((info) => {
481510
const pricing = info.getValue() as AzurePricing | undefined;
482511
const price =
483512
pricing?.[selectedRegion]?.windows?.reserved?.[
@@ -489,7 +518,7 @@ export const columnsGen = (
489518
pricingUnit,
490519
costDuration,
491520
);
492-
},
521+
}),
493522
},
494523
{
495524
accessorKey: "pricing",
@@ -510,7 +539,7 @@ export const columnsGen = (
510539
);
511540
return valueA - valueB;
512541
},
513-
cell: (info) => {
542+
...makeCellWithRegexSorter((info) => {
514543
const pricing = info.getValue() as AzurePricing | undefined;
515544
const price = pricing?.[selectedRegion]?.windows?.spot_min;
516545
return calculateAndFormatCost(
@@ -519,7 +548,7 @@ export const columnsGen = (
519548
pricingUnit,
520549
costDuration,
521550
);
522-
},
551+
}),
523552
},
524553
];
525554
};

next/utils/colunnData/cache.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import {
44
doAllDataTablesMigrations,
55
gt,
66
makeSchemaWithDefaults,
7+
regex,
78
} from "./shared";
89
import { EC2Instance, PricingUnit, CostDuration, Pricing } from "@/types";
910
import RegionLinkPreloader from "@/components/RegionLinkPreloader";
1011
import sortByInstanceType from "../sortByInstanceType";
12+
import { makeCellWithRegexSorter } from "./ec2/columns";
1113

1214
const initialColumnsArr = [
1315
["pretty_name", true],
@@ -76,6 +78,7 @@ export const columnsGen = (
7678
id: "pretty_name",
7779
header: "Name",
7880
sortingFn: "alphanumeric",
81+
filterFn: regex({}),
7982
},
8083
{
8184
accessorKey: "instance_type",
@@ -86,6 +89,7 @@ export const columnsGen = (
8689
const valueB = rowB.original.instance_type;
8790
return sortByInstanceType(valueA, valueB, ".", "cache.");
8891
},
92+
filterFn: regex({}),
8993
cell: (info) => {
9094
const value = info.getValue() as string;
9195
return (
@@ -125,13 +129,14 @@ export const columnsGen = (
125129
id: "networkperf",
126130
sortingFn: "alphanumeric",
127131
header: "Network Performance",
132+
filterFn: regex({}),
128133
},
129134
{
130135
accessorKey: "pricing",
131136
id: "cost-ondemand-redis",
132137
header: "Redis Cost",
133138
sortingFn: "alphanumeric",
134-
cell: (info) => {
139+
...makeCellWithRegexSorter((info) => {
135140
const pricing = info.getValue() as Pricing;
136141
const region = pricing[selectedRegion];
137142
if (!region) return "N/A";
@@ -141,14 +146,14 @@ export const columnsGen = (
141146
pricingUnit,
142147
costDuration,
143148
);
144-
},
149+
}),
145150
},
146151
{
147152
accessorKey: "pricing",
148153
id: "cost-reserved-redis",
149154
header: "Redis Reserved Cost",
150155
sortingFn: "alphanumeric",
151-
cell: (info) => {
156+
...makeCellWithRegexSorter((info) => {
152157
const pricing = info.getValue() as Pricing;
153158
const region = pricing[selectedRegion];
154159
if (!region) return "N/A";
@@ -158,14 +163,14 @@ export const columnsGen = (
158163
pricingUnit,
159164
costDuration,
160165
);
161-
},
166+
}),
162167
},
163168
{
164169
accessorKey: "pricing",
165170
id: "cost-ondemand-memcached",
166171
header: "Memcached On Demand Cost",
167172
sortingFn: "alphanumeric",
168-
cell: (info) => {
173+
...makeCellWithRegexSorter((info) => {
169174
const pricing = info.getValue() as Pricing;
170175
const region = pricing[selectedRegion];
171176
if (!region) return "N/A";
@@ -175,14 +180,14 @@ export const columnsGen = (
175180
pricingUnit,
176181
costDuration,
177182
);
178-
},
183+
}),
179184
},
180185
{
181186
accessorKey: "pricing",
182187
id: "cost-reserved-memcached",
183188
header: "Memcached Reserved Cost",
184189
sortingFn: "alphanumeric",
185-
cell: (info) => {
190+
...makeCellWithRegexSorter((info) => {
186191
const pricing = info.getValue() as Pricing;
187192
const region = pricing[selectedRegion];
188193
if (!region) return "N/A";
@@ -192,14 +197,14 @@ export const columnsGen = (
192197
pricingUnit,
193198
costDuration,
194199
);
195-
},
200+
}),
196201
},
197202
{
198203
accessorKey: "pricing",
199204
id: "cost-ondemand-valkey",
200205
header: "Valkey On Demand Cost",
201206
sortingFn: "alphanumeric",
202-
cell: (info) => {
207+
...makeCellWithRegexSorter((info) => {
203208
const pricing = info.getValue() as Pricing;
204209
const region = pricing[selectedRegion];
205210
if (!region) return "N/A";
@@ -209,14 +214,14 @@ export const columnsGen = (
209214
pricingUnit,
210215
costDuration,
211216
);
212-
},
217+
}),
213218
},
214219
{
215220
accessorKey: "pricing",
216221
id: "cost-reserved-valkey",
217222
header: "Valkey Reserved Cost",
218223
sortingFn: "alphanumeric",
219-
cell: (info) => {
224+
...makeCellWithRegexSorter((info) => {
220225
const pricing = info.getValue() as Pricing;
221226
const region = pricing[selectedRegion];
222227
if (!region) return "N/A";
@@ -226,13 +231,21 @@ export const columnsGen = (
226231
pricingUnit,
227232
costDuration,
228233
);
229-
},
234+
}),
230235
},
231236
{
232237
accessorKey: "currentGeneration",
233238
id: "generation",
234239
header: "Generation",
235240
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+
}),
236249
cell: (info) => {
237250
if (info.getValue() === "Yes") return "current";
238251
return "previous";

0 commit comments

Comments
 (0)