Compare commits
No commits in common. "9f04b36e7e0c0ed322406b6b99839cf3d8781053" and "e6560aa990ae9807ea2bfc33c195858d28e1dd3f" have entirely different histories.
9f04b36e7e
...
e6560aa990
@ -1,11 +1,5 @@
|
|||||||
# @warkypublic/zustandsyncstore
|
# @warkypublic/zustandsyncstore
|
||||||
|
|
||||||
## 0.0.17
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- 03210a3: Updated selected cols bug
|
|
||||||
|
|
||||||
## 0.0.16
|
## 0.0.16
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@warkypublic/oranguru",
|
"name": "@warkypublic/oranguru",
|
||||||
"author": "Warky Devs",
|
"author": "Warky Devs",
|
||||||
"version": "0.0.17",
|
"version": "0.0.16",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@ -67,7 +67,6 @@ export const Computer = React.memo(() => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//When values change, update selection
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const searchSelection = async () => {
|
const searchSelection = async () => {
|
||||||
const page_data = getState('_page_data');
|
const page_data = getState('_page_data');
|
||||||
@ -129,12 +128,40 @@ export const Computer = React.memo(() => {
|
|||||||
}
|
}
|
||||||
}, [values]);
|
}, [values]);
|
||||||
|
|
||||||
//Fire onChange when selection changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onChange = getState('onChange');
|
const onChange = getState('onChange');
|
||||||
if (onChange && typeof onChange === 'function') {
|
if (onChange && typeof onChange === 'function') {
|
||||||
const getGridSelectedRows = getState('getGridSelectedRows');
|
const page_data = getState('_page_data');
|
||||||
const buffers = getGridSelectedRows();
|
const pageSize = getState('pageSize');
|
||||||
|
|
||||||
|
const buffers = [];
|
||||||
|
if (_gridSelectionRows) {
|
||||||
|
for (const range of _gridSelectionRows) {
|
||||||
|
let buffer = undefined;
|
||||||
|
|
||||||
|
for (const p in page_data) {
|
||||||
|
for (const r in page_data[p]) {
|
||||||
|
const idx = Number(p) * pageSize + Number(r);
|
||||||
|
if (isNaN(idx)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Number(page_data[p][r]?._rownumber) === range + 1) {
|
||||||
|
buffer = page_data[p][r];
|
||||||
|
//console.log('Found row', range, idx, page_data[p][r]?._rownumber);
|
||||||
|
break;
|
||||||
|
} else if (idx === range + 1) {
|
||||||
|
buffer = page_data[p][r];
|
||||||
|
//console.log('Found row 2', range, idx, page_data[p][r]?._rownumber);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (buffer !== undefined) {
|
||||||
|
buffers.push(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const _values = getState('values');
|
const _values = getState('values');
|
||||||
|
|
||||||
@ -251,7 +278,6 @@ export const Computer = React.memo(() => {
|
|||||||
});
|
});
|
||||||
}, [colOrder]);
|
}, [colOrder]);
|
||||||
|
|
||||||
//Initial Load
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!_glideref) {
|
if (!_glideref) {
|
||||||
return;
|
return;
|
||||||
@ -265,12 +291,11 @@ export const Computer = React.memo(() => {
|
|||||||
});
|
});
|
||||||
}, [ready, loadPage]);
|
}, [ready, loadPage]);
|
||||||
|
|
||||||
//Logic to select first row on mount
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const _events = getState('_events');
|
const _events = getState('_events');
|
||||||
const loadPage = () => {
|
const loadPage = () => {
|
||||||
const selectFirstRowOnMount = getState('selectFirstRowOnMount');
|
const selectFirstRowOnMount = getState('selectFirstRowOnMount');
|
||||||
if (ready && selectFirstRowOnMount) {
|
if (selectFirstRowOnMount) {
|
||||||
const scrollToRowKey = getState('scrollToRowKey');
|
const scrollToRowKey = getState('scrollToRowKey');
|
||||||
if (scrollToRowKey && scrollToRowKey >= 0) {
|
if (scrollToRowKey && scrollToRowKey >= 0) {
|
||||||
return;
|
return;
|
||||||
@ -303,28 +328,28 @@ export const Computer = React.memo(() => {
|
|||||||
return () => {
|
return () => {
|
||||||
_events?.removeEventListener('loadPage', loadPage);
|
_events?.removeEventListener('loadPage', loadPage);
|
||||||
};
|
};
|
||||||
}, [ready]);
|
}, []);
|
||||||
|
|
||||||
/// logic to apply the selected row.
|
/// logic to apply the selected row.
|
||||||
// useEffect(() => {
|
useEffect(() => {
|
||||||
// const ready = getState('ready');
|
const ready = getState('ready');
|
||||||
// const ref = getState('_glideref');
|
const ref = getState('_glideref');
|
||||||
// const getRowIndexByKey = getState('getRowIndexByKey');
|
const getRowIndexByKey = getState('getRowIndexByKey');
|
||||||
|
|
||||||
// if (scrollToRowKey && ref && ready) {
|
if (scrollToRowKey && ref && ready) {
|
||||||
// getRowIndexByKey?.(scrollToRowKey).then((r) => {
|
getRowIndexByKey?.(scrollToRowKey).then((r) => {
|
||||||
// if (r !== undefined) {
|
if (r !== undefined) {
|
||||||
// //console.log('Scrolling to selected row:', scrollToRowKey, r);
|
//console.log('Scrolling to selected row:', scrollToRowKey, r);
|
||||||
// ref.scrollTo(0, r);
|
ref.scrollTo(0, r);
|
||||||
// getState('_events').dispatchEvent(
|
getState('_events').dispatchEvent(
|
||||||
// new CustomEvent('scrollToRowKeyFound', {
|
new CustomEvent('scrollToRowKeyFound', {
|
||||||
// detail: { rowNumber: r, scrollToRowKey: scrollToRowKey },
|
detail: { rowNumber: r, scrollToRowKey: scrollToRowKey },
|
||||||
// })
|
})
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// }, [scrollToRowKey]);
|
}, [scrollToRowKey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const ready = getState('ready');
|
const ready = getState('ready');
|
||||||
|
|||||||
@ -155,14 +155,13 @@ export interface GridlerState {
|
|||||||
selection: Rectangle,
|
selection: Rectangle,
|
||||||
abortSignal: AbortSignal
|
abortSignal: AbortSignal
|
||||||
) => CellArray | GetCellsThunk;
|
) => CellArray | GetCellsThunk;
|
||||||
getGridSelectedRows: () => Array<any>;
|
|
||||||
getRowBuffer: (row: number) => Record<string, any>;
|
getRowBuffer: (row: number) => Record<string, any>;
|
||||||
getRowIndexByKey: (key: number | string) => Promise<number | undefined>;
|
getRowIndexByKey: (key: number | string) => Promise<number | undefined>;
|
||||||
getState: <K extends keyof GridlerStoreState>(key: K) => GridlerStoreState[K];
|
getState: <K extends keyof GridlerStoreState>(key: K) => GridlerStoreState[K];
|
||||||
hasLocalData: boolean;
|
hasLocalData: boolean;
|
||||||
isEmpty: boolean;
|
isEmpty: boolean;
|
||||||
|
|
||||||
loadingData?: boolean;
|
loadingData?: boolean;
|
||||||
|
|
||||||
loadPage: (page: number, clearMode?: 'all' | 'page') => Promise<void>;
|
loadPage: (page: number, clearMode?: 'all' | 'page') => Promise<void>;
|
||||||
mounted: boolean;
|
mounted: boolean;
|
||||||
onCellActivated: (cell: Item) => void;
|
onCellActivated: (cell: Item) => void;
|
||||||
@ -279,42 +278,6 @@ const { Provider, useStore: useGridlerStore } = createSyncStore<GridlerStoreStat
|
|||||||
return result as CellArray;
|
return result as CellArray;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getGridSelectedRows: () => {
|
|
||||||
const state = get();
|
|
||||||
const buffers: Array<any> = [];
|
|
||||||
const page_data = state._page_data;
|
|
||||||
const pageSize = state.pageSize;
|
|
||||||
|
|
||||||
if (state._gridSelectionRows) {
|
|
||||||
for (const range of state._gridSelectionRows) {
|
|
||||||
let buffer = undefined;
|
|
||||||
|
|
||||||
for (const p in page_data) {
|
|
||||||
for (const r in page_data[p]) {
|
|
||||||
const idx = Number(p) * pageSize + Number(r);
|
|
||||||
if (isNaN(idx)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Number(page_data[p][r]?._rownumber) === range + 1) {
|
|
||||||
buffer = page_data[p][r];
|
|
||||||
//console.log('Found row', range, idx, page_data[p][r]?._rownumber);
|
|
||||||
break;
|
|
||||||
} else if (idx === range + 1) {
|
|
||||||
buffer = page_data[p][r];
|
|
||||||
//console.log('Found row 2', range, idx, page_data[p][r]?._rownumber);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (buffer !== undefined) {
|
|
||||||
buffers.push(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buffers;
|
|
||||||
},
|
|
||||||
|
|
||||||
getRowBuffer: (row: number) => {
|
getRowBuffer: (row: number) => {
|
||||||
const state = get();
|
const state = get();
|
||||||
//Handle local data
|
//Handle local data
|
||||||
@ -337,6 +300,7 @@ const { Provider, useStore: useGridlerStore } = createSyncStore<GridlerStoreStat
|
|||||||
|
|
||||||
return rowData;
|
return rowData;
|
||||||
},
|
},
|
||||||
|
|
||||||
getRowIndexByKey: async (key: number | string) => {
|
getRowIndexByKey: async (key: number | string) => {
|
||||||
const state = get();
|
const state = get();
|
||||||
|
|
||||||
@ -513,7 +477,6 @@ const { Provider, useStore: useGridlerStore } = createSyncStore<GridlerStoreStat
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
onColumnResize: (
|
onColumnResize: (
|
||||||
column: GridColumn,
|
column: GridColumn,
|
||||||
newSize: number,
|
newSize: number,
|
||||||
@ -538,6 +501,7 @@ const { Provider, useStore: useGridlerStore } = createSyncStore<GridlerStoreStat
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onContextClick: (area: string, event: CellClickedEventArgs, col?: number, row?: number) => {
|
onContextClick: (area: string, event: CellClickedEventArgs, col?: number, row?: number) => {
|
||||||
const s = get();
|
const s = get();
|
||||||
const coldef = s.renderColumns?.[col ?? -1];
|
const coldef = s.renderColumns?.[col ?? -1];
|
||||||
|
|||||||
@ -77,7 +77,6 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
|
|||||||
(f) =>
|
(f) =>
|
||||||
!f.disableFilter &&
|
!f.disableFilter &&
|
||||||
!f.disableSearch &&
|
!f.disableSearch &&
|
||||||
!f.virtual &&
|
|
||||||
((searchFields ?? []).length == 0 || searchFields?.includes(f.id))
|
((searchFields ?? []).length == 0 || searchFields?.includes(f.id))
|
||||||
)
|
)
|
||||||
?.forEach((filter: any) => {
|
?.forEach((filter: any) => {
|
||||||
@ -113,13 +112,6 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
|
|||||||
col_ids?.push(props.hotfields.join(','));
|
col_ids?.push(props.hotfields.join(','));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col_ids && col_ids.length > 0) {
|
|
||||||
ops.push({
|
|
||||||
type: 'select-fields',
|
|
||||||
value: col_ids.join(','),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ops && ops.length > 0) {
|
if (ops && ops.length > 0) {
|
||||||
const optionHeaders = GoAPIHeaders(ops);
|
const optionHeaders = GoAPIHeaders(ops);
|
||||||
for (const oh in GoAPIHeaders(ops)) {
|
for (const oh in GoAPIHeaders(ops)) {
|
||||||
@ -127,6 +119,13 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (col_ids && col_ids.length > 0) {
|
||||||
|
ops.push({
|
||||||
|
type: 'select-fields',
|
||||||
|
value: col_ids.join(','),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const currentRequestIndex = _active_requests?.findIndex((f) => f.page === index) ?? -1;
|
const currentRequestIndex = _active_requests?.findIndex((f) => f.page === index) ?? -1;
|
||||||
_active_requests?.forEach((r) => {
|
_active_requests?.forEach((r) => {
|
||||||
if ((r.page >= 0 && r.page < index - 2) || (index >= 0 && r.page > index + 2)) {
|
if ((r.page >= 0 && r.page < index - 2) || (index >= 0 && r.page > index + 2)) {
|
||||||
@ -263,14 +262,7 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
|
|||||||
|
|
||||||
//Reset the loaded pages to new rules
|
//Reset the loaded pages to new rules
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadPage(0, 'all').then(() => {
|
loadPage(0, 'all');
|
||||||
const onChange = getState('onChange');
|
|
||||||
const getGridSelectedRows = getState('getGridSelectedRows');
|
|
||||||
if (onChange && typeof onChange === 'function') {
|
|
||||||
const buffers = getGridSelectedRows?.();
|
|
||||||
onChange(buffers);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [JSON.stringify(props.options), props.filter, props.url, props.authtoken]);
|
}, [JSON.stringify(props.options), props.filter, props.url, props.authtoken]);
|
||||||
|
|
||||||
//Reset the function in the store.
|
//Reset the function in the store.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user