Skip to content

Commit

Permalink
Fix the off by one error
Browse files Browse the repository at this point in the history
- _pkid was still used in columns but not in cell values
- Allow one click group change
  • Loading branch information
CannonLock committed Nov 8, 2023
1 parent 29deba5 commit 2cfaf10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/pages/maps/@id/edit/edit-table.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hyper from "@macrostrat/hyper";

import { useState, useEffect, useCallback, useRef, useLayoutEffect } from "react";
import { useState, useEffect, useCallback, useRef, useLayoutEffect, useMemo } from "react";
import { HotkeysProvider, InputGroup, Button } from "@blueprintjs/core";
import { Spinner, ButtonGroup } from "@blueprintjs/core";
import {
Expand Down Expand Up @@ -76,6 +76,11 @@ export default function EditTable({ url }) {
// Sparse array to hold edited data
const [editedData, setEditedData] = useState(new Array());

// Memoize non-id columns
const nonIdColumns = useMemo(() => {
return data.length ? Object.keys(data[0]).filter(x => x != "_pkid") : []
}, [data])

const onChange = (key, row, text) => {
let rowSpec = {};
if (text == data[row][key] || (text == "" && data[row][key] == null)) {
Expand Down Expand Up @@ -106,7 +111,7 @@ export default function EditTable({ url }) {

const columnHeaderCellRenderer = (columnIndex: number) => {

const columnName: string = Object.keys(data[0])[columnIndex]
const columnName: string = nonIdColumns[columnIndex]

const onFilterChange = (param: OperatorQueryParameter) => {

Expand Down Expand Up @@ -198,7 +203,7 @@ export default function EditTable({ url }) {
return h(Spinner)
}

const columns = Object.keys(data[0]).filter(x => x != "_pkid").map((key) => {
const columns = nonIdColumns.map((key) => {
return h(Column, {
name: key,
className: FINAL_COLUMNS.includes(key) ? "final-column" : "",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/maps/@id/edit/table-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const TableMenu = ({onFilterChange, filter, onGroupChange, group} : TableMenuPro
intent: groupActive ? "success" : "warning",
text: groupActive ? "Active" : "Inactive",
fill: true,
onClick: () => onGroupChange(group ? "" : filter.column_name)
onClick: () => onGroupChange(group == filter.column_name ? undefined : filter.column_name)
}, [])
]),
])
Expand Down

0 comments on commit 2cfaf10

Please sign in to comment.