A lot of refectoring
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useGridlerStore } from './Store';
|
||||
import { useGridlerStore } from './GridlerStore';
|
||||
|
||||
export function BottomBar() {
|
||||
const { _activeTooltip, tooltipBarProps } = useGridlerStore((s) => ({
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useDebouncedValue } from '@mantine/hooks';
|
||||
import { IconX } from '@tabler/icons-react';
|
||||
import { type ReactNode, useEffect, useState } from 'react';
|
||||
|
||||
import type { FilterOption, FilterOptionOperator, GridlerStoreState } from './Store';
|
||||
import type { FilterOption, FilterOptionOperator, GridlerStoreState } from './GridlerStore';
|
||||
|
||||
export type GridCellLoose = {
|
||||
kind: GridCellKind | string;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { CompactSelection } from '@glideapps/glide-data-grid';
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
|
||||
import { useGridlerStore } from './Store';
|
||||
import { useGridlerStore } from './GridlerStore';
|
||||
|
||||
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
|
||||
export const Computer = React.memo(() => {
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
type Item,
|
||||
type Rectangle,
|
||||
} from '@glideapps/glide-data-grid';
|
||||
import { IconGrid4x4 } from '@tabler/icons-react';
|
||||
import { getUUID } from '@warkypublic/artemis-kit';
|
||||
import { getNestedValue } from '@warkypublic/artemis-kit/object';
|
||||
import { createSyncStore } from '@warkypublic/zustandsyncstore';
|
||||
@@ -27,12 +28,10 @@ import {
|
||||
type MantineBetterMenuInstanceItem,
|
||||
useMantineBetterMenus,
|
||||
} from '../../MantineBetterMenu';
|
||||
import { type FormRequestType } from '../utils/types';
|
||||
import { ColumnFilterSet, type GridlerColumn, type GridlerColumns } from './Column';
|
||||
import { SortDownSprite } from './sprites/SortDown';
|
||||
import { SortUpSprite } from './sprites/SortUp';
|
||||
import { SpriteImage } from './sprites/SpriteImage';
|
||||
import { IconGrid4x4 } from '@tabler/icons-react';
|
||||
|
||||
export type FilterOption = {
|
||||
datatype?: 'array' | 'boolean' | 'date' | 'function' | 'number' | 'object' | 'string';
|
||||
@@ -99,6 +98,7 @@ export interface GridlerProps extends PropsWithChildren {
|
||||
selectMode?: 'cell' | 'row';
|
||||
showMenu?: (id: string, options?: Partial<MantineBetterMenuInstance>) => void;
|
||||
tooltipBarProps?: React.HTMLAttributes<HTMLDivElement>;
|
||||
total_rows?: number;
|
||||
uniqueid: string;
|
||||
useAPIQuery?: (index: number) => Promise<Array<Record<string, any>>>;
|
||||
values?: Array<Record<string, any>>;
|
||||
@@ -177,7 +177,6 @@ export interface GridlerState {
|
||||
value: (current: GridlerStoreState[K]) => Partial<GridlerStoreState[K]>
|
||||
) => Promise<void>;
|
||||
toCell: <TRowType extends Record<string, string>>(row: any, col: number) => GridCell;
|
||||
total_rows: number;
|
||||
}
|
||||
|
||||
export type GridlerStoreState = GridlerProps & GridlerState;
|
||||
@@ -850,10 +849,10 @@ const { Provider, useStore: useGridlerStore } = createSyncStore<GridlerStoreStat
|
||||
|
||||
return {
|
||||
...props,
|
||||
hasLocalData: props.data && props.data.length > 0,
|
||||
|
||||
hideMenu: props.hideMenu ?? menus.hide,
|
||||
showMenu: props.showMenu ?? menus.show,
|
||||
total_rows: props.data?.length ?? getState('total_rows'),
|
||||
total_rows: props.total_rows ?? getState('total_rows') ?? 0,
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -1,8 +1,7 @@
|
||||
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
import { range } from '../utils/range';
|
||||
import { useGridlerStore } from './Store';
|
||||
import { useGridlerStore } from './GridlerStore';
|
||||
|
||||
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
|
||||
export const Pager = React.memo(() => {
|
||||
@@ -14,7 +13,7 @@ export const Pager = React.memo(() => {
|
||||
pageSize,
|
||||
loadPage,
|
||||
_loadingList,
|
||||
hasLocalData
|
||||
hasLocalData,
|
||||
] = useGridlerStore((s) => [
|
||||
s.setState,
|
||||
s._glideref,
|
||||
@@ -24,17 +23,21 @@ export const Pager = React.memo(() => {
|
||||
s.loadPage,
|
||||
|
||||
s._loadingList,
|
||||
s.hasLocalData
|
||||
s.hasLocalData,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!glideref) {return;}
|
||||
if (!glideref) {
|
||||
return;
|
||||
}
|
||||
setState('mounted', true);
|
||||
}, [setState]);
|
||||
|
||||
//Maybe move this into a computer component.
|
||||
useEffect(() => {
|
||||
if (!glideref) {return;}
|
||||
if (!glideref) {
|
||||
return;
|
||||
}
|
||||
if (hasLocalData) {
|
||||
//using local data, no need to load pages
|
||||
return;
|
||||
@@ -56,7 +59,7 @@ export const Pager = React.memo(() => {
|
||||
for (const page of range(firstPage, lastPage + 1, 1)) {
|
||||
loadPage(page);
|
||||
}
|
||||
}, [loadPage, pageSize, visiblePages, glideref, _loadingList,hasLocalData]);
|
||||
}, [loadPage, pageSize, visiblePages, glideref, _loadingList, hasLocalData]);
|
||||
|
||||
return <></>;
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ActionIcon } from '@mantine/core';
|
||||
import { IconMenu2 } from '@tabler/icons-react';
|
||||
|
||||
import { useGridlerStore } from './Store';
|
||||
import { useGridlerStore } from './GridlerStore';
|
||||
|
||||
export function RightMenuIcon() {
|
||||
const { loadingData, onContextClick } = useGridlerStore((s) => ({
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
import type { APIOptions } from '../utils/types';
|
||||
import type { APIOptions } from '../../utils/types';
|
||||
|
||||
import { useGridlerStore } from './Store';
|
||||
import { useGridlerStore } from '../GridlerStore';
|
||||
|
||||
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
|
||||
export const APIAdaptorGoLangv2 = React.memo((props: APIOptions) => {
|
||||
export const GlidlerAPIAdaptorForGoLangv2 = React.memo((props: APIOptions) => {
|
||||
const [setStateFN, setState, getState, addError, mounted] = useGridlerStore((s) => [
|
||||
s.setStateFN,
|
||||
s.setState,
|
||||
@@ -7,13 +7,13 @@ import {
|
||||
} from '@tabler/icons-react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
import type { MantineBetterMenuInstanceItem } from '../../MantineBetterMenu';
|
||||
import type { FormRequestType } from '../utils/types';
|
||||
import type { GridlerColumn } from './Column';
|
||||
import type { MantineBetterMenuInstanceItem } from '../../../MantineBetterMenu';
|
||||
import type { FormRequestType } from '../../utils/types';
|
||||
import type { GridlerColumn } from '../Column';
|
||||
|
||||
import { type GridlerProps, type GridlerState, useGridlerStore } from './Store';
|
||||
import { type GridlerProps, type GridlerState, useGridlerStore } from '../GridlerStore';
|
||||
|
||||
export function GlidlerFormInterface(props: {
|
||||
export function GlidlerFormAdaptor(props: {
|
||||
descriptionField?: ((data: Record<string, unknown>) => string) | string;
|
||||
getMenuItems?: GridlerProps['getMenuItems'];
|
||||
onReload?: () => void;
|
||||
@@ -1,23 +1,14 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
import type { APIOptions } from '../utils/types';
|
||||
import { useGridlerStore } from '../GridlerStore';
|
||||
|
||||
import { useGridlerStore } from './Store';
|
||||
|
||||
interface LocalDataAdaptorProps {
|
||||
export interface GlidlerLocalDataAdaptorProps {
|
||||
data: Array<unknown>;
|
||||
}
|
||||
|
||||
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
|
||||
export const LocalDataAdaptor = React.memo((props: LocalDataAdaptorProps) => {
|
||||
const [setStateFN, setState, getState, addError, mounted] = useGridlerStore((s) => [
|
||||
s.setStateFN,
|
||||
s.setState,
|
||||
s.getState,
|
||||
s.addError,
|
||||
s.mounted,
|
||||
]);
|
||||
export const GlidlerLocalDataAdaptor = React.memo((props: GlidlerLocalDataAdaptorProps) => {
|
||||
const [setState, getState, mounted] = useGridlerStore((s) => [s.setState, s.getState, s.mounted]);
|
||||
|
||||
const useAPIQuery: (index: number) => Promise<any> = async (index: number) => {
|
||||
const pageSize = getState('pageSize');
|
||||
3
src/Gridler/components/adaptors/index.ts
Normal file
3
src/Gridler/components/adaptors/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './GlidlerAPIAdaptorForGoLangv2'
|
||||
export * from './GlidlerFormAdaptor'
|
||||
export * from './GlidlerLocalDataAdaptor'
|
||||
Reference in New Issue
Block a user