prevent table redirect to same page

This commit is contained in:
Shams mosowi
2020-02-03 10:18:51 +11:00
parent d148c4a463
commit b99d5a6a9b
2 changed files with 13 additions and 4 deletions

View File

@@ -116,7 +116,13 @@ const Navigation = (props: any) => {
<Button
key={table.collection}
onClick={() => {
router.history.push(table.collection);
if (
table.collection !==
router.location.pathname.replace("/table/", "")
) {
//prevent redirecting to the same table
router.history.push(table.collection);
}
}}
className={classes.button}
>

View File

@@ -1,11 +1,12 @@
import React, { lazy, Suspense } from "react";
import { FieldType } from "../Fields";
import { Editors } from "react-data-grid-addons";
import MultiSelect from "../Fields/MultiSelect";
import _uniq from "lodash/uniq";
import { algoliaUpdateDoc } from "../../firebase/callables";
const { AutoComplete } = Editors;
const MultiSelect = lazy(() => import("../Fields/MultiSelect"));
const DateField = lazy(() => import("../Fields/Date"));
const Rating = lazy(() => import("../Fields/Rating"));
const Number = lazy(() => import("../Fields/Number"));
@@ -39,9 +40,11 @@ export const editable = (fieldType: FieldType) => {
return true;
}
};
export const onSubmit = (key: string, row: any) => async (value: any) => {
const collection = row.ref.parent.path;
const data = { collection, id: row.ref.id, doc: { [key]: value } };
if (value !== null || value !== undefined) {
const updatedAt = new Date();
let updatedFields = [key];
@@ -85,7 +88,7 @@ export const cellFormatter = (column: any) => {
<Rating
{...props}
onSubmit={onSubmit(key, props.row)}
value={typeof props.value === "number" ? props.value : undefined}
value={typeof props.value === "number" ? props.value : 0}
/>
</Suspense>
);
@@ -97,7 +100,7 @@ export const cellFormatter = (column: any) => {
<Number
{...props}
onSubmit={onSubmit(key, props.row)}
value={typeof props.value === "number" ? props.value : 0}
value={typeof props.value === "number" ? props.value : undefined}
/>
</Suspense>
);