Skip to content

Commit

Permalink
feat: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia committed Oct 15, 2024
1 parent 5929d82 commit 8a0d4c9
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
generateCustomColumns,
generateDateTime,
} from "../../../../../common/MatrixGrid/utils.ts";
import { ColumnTypes } from "../../../../../common/MatrixGrid/types.ts";
import { Column } from "../../../../../common/MatrixGrid/types.ts";
import SplitView from "../../../../../common/SplitView/index.tsx";
import ResultFilters from "./ResultFilters.tsx";
import { toError } from "../../../../../../utils/fnUtils.ts";
Expand Down Expand Up @@ -284,7 +284,7 @@ function ResultDetails() {
{
id: "date",
title: "Date",
type: ColumnTypes.DateTime,
type: Column.DateTime,
editable: false,
},
...generateCustomColumns({
Expand Down
20 changes: 10 additions & 10 deletions webapp/src/components/common/MatrixGrid/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { render } from "@testing-library/react";
import MatrixGrid, { MatrixGridProps } from ".";
import Box from "@mui/material/Box";
import { mockGetBoundingClientRect } from "../../../tests/mocks/mockGetBoundingClientRect";
import { type EnhancedGridColumn, ColumnTypes } from "./types";
import { type EnhancedGridColumn, Column } from "./types";
import { mockHTMLCanvasElement } from "../../../tests/mocks/mockHTMLCanvasElement";

beforeEach(() => {
Expand Down Expand Up @@ -67,23 +67,23 @@ describe("MatrixGrid rendering", () => {
id: "col1",
title: "Column 1",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 0,
},
{
id: "col2",
title: "Column 2",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 1,
},
{
id: "col3",
title: "Column 3",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 2,
},
Expand Down Expand Up @@ -118,23 +118,23 @@ describe("MatrixGrid rendering", () => {
id: "col1",
title: "Column 1",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 0,
},
{
id: "col2",
title: "Column 2",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 1,
},
{
id: "col3",
title: "Column 3",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 2,
},
Expand Down Expand Up @@ -171,23 +171,23 @@ describe("MatrixGrid rendering", () => {
id: "col1",
title: "Column 1",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 0,
},
{
id: "col2",
title: "Column 2",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 1,
},
{
id: "col3",
title: "Column 3",
width: 100,
type: ColumnTypes.Number,
type: Column.Number,
editable: true,
order: 2,
},
Expand Down
28 changes: 12 additions & 16 deletions webapp/src/components/common/MatrixGrid/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import {
// Enums
////////////////////////////////////////////////////////////////

// TODO update enums to be singular

export const ColumnTypes = {
export const Column = {
DateTime: "datetime",
Number: "number",
Text: "text",
Aggregate: "aggregate",
} as const;

export const Operations = {
export const Operation = {
Add: "+",
Sub: "-",
Mul: "*",
Expand All @@ -41,31 +39,29 @@ export const Operations = {
} as const;

// !NOTE: Keep lowercase to match Glide Data Grid column ids
export const Aggregates = {
export const Aggregate = {
Min: "min",
Max: "max",
Avg: "avg",
Total: "total",
} as const;

export const TimeFrequency = {
// TODO update old enum occurrences
ANNUAL: "annual",
MONTHLY: "monthly",
WEEKLY: "weekly",
DAILY: "daily",
HOURLY: "hourly",
Annual: "annual",
Monthly: "monthly",
Weekly: "weekly",
Daily: "daily",
Hourly: "hourly",
} as const;

////////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////////

// Derived types
export type ColumnType = (typeof ColumnTypes)[keyof typeof ColumnTypes];
// TODO add sufix Type
export type Operation = (typeof Operations)[keyof typeof Operations];
export type AggregateType = (typeof Aggregates)[keyof typeof Aggregates];
export type ColumnType = (typeof Column)[keyof typeof Column];
export type OperationType = (typeof Operation)[keyof typeof Operation];
export type AggregateType = (typeof Aggregate)[keyof typeof Aggregate];
export type TimeFrequencyType =
(typeof TimeFrequency)[keyof typeof TimeFrequency];

Expand Down Expand Up @@ -127,7 +123,7 @@ export interface GridUpdate {

// Shape of updates to be sent to the API
export interface MatrixUpdate {
operation: Operation;
operation: OperationType;
value: number;
}

Expand Down
20 changes: 10 additions & 10 deletions webapp/src/components/common/MatrixGrid/useColumnMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,42 @@
import { renderHook } from "@testing-library/react";
import { describe, test, expect } from "vitest";
import { useColumnMapping } from "./useColumnMapping";
import { EnhancedGridColumn, ColumnTypes } from "./types";
import { EnhancedGridColumn, Column } from "./types";

describe("useColumnMapping", () => {
const testColumns: EnhancedGridColumn[] = [
{
id: "text",
title: "Text",
type: ColumnTypes.Text,
type: Column.Text,
width: 100,
editable: false,
},
{
id: "date",
title: "Date",
type: ColumnTypes.DateTime,
type: Column.DateTime,
width: 100,
editable: false,
},
{
id: "num1",
title: "Number 1",
type: ColumnTypes.Number,
type: Column.Number,
width: 100,
editable: true,
},
{
id: "num2",
title: "Number 2",
type: ColumnTypes.Number,
type: Column.Number,
width: 100,
editable: true,
},
{
id: "agg",
title: "Aggregate",
type: ColumnTypes.Aggregate,
type: Column.Aggregate,
width: 100,
editable: false,
},
Expand Down Expand Up @@ -90,14 +90,14 @@ describe("useColumnMapping", () => {
{
id: "text",
title: "Text",
type: ColumnTypes.Text,
type: Column.Text,
width: 100,
editable: false,
},
{
id: "date",
title: "Date",
type: ColumnTypes.DateTime,
type: Column.DateTime,
width: 100,
editable: false,
},
Expand All @@ -113,14 +113,14 @@ describe("useColumnMapping", () => {
{
id: "num1",
title: "Number 1",
type: ColumnTypes.Number,
type: Column.Number,
width: 100,
editable: true,
},
{
id: "num2",
title: "Number 2",
type: ColumnTypes.Number,
type: Column.Number,
width: 100,
editable: true,
},
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/common/MatrixGrid/useColumnMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { useMemo } from "react";
import { Item } from "@glideapps/glide-data-grid";
import { EnhancedGridColumn, ColumnTypes } from "./types";
import { EnhancedGridColumn, Column } from "./types";

/**
* A custom hook that provides coordinate mapping functions for a grid with mixed column types.
Expand Down Expand Up @@ -48,7 +48,7 @@ import { EnhancedGridColumn, ColumnTypes } from "./types";
export function useColumnMapping(columns: EnhancedGridColumn[]) {
return useMemo(() => {
const dataColumnIndices = columns.reduce((acc, col, index) => {
if (col.type === ColumnTypes.Number) {
if (col.type === Column.Number) {
acc.push(index);
}
return acc;
Expand Down
Loading

0 comments on commit 8a0d4c9

Please sign in to comment.