@teselagen/ui 0.10.5 → 0.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -229,7 +229,6 @@ const DataTable = ({
229
229
  const {
230
230
  doNotCoercePageSize,
231
231
  isInfinite = isSimple && !withPaging,
232
- syncDisplayOptionsToDb,
233
232
  urlConnected,
234
233
  withSelectedEntities
235
234
  } = props;
@@ -255,7 +254,7 @@ const DataTable = ({
255
254
  _defaults.order = r;
256
255
  }
257
256
 
258
- if (!syncDisplayOptionsToDb && userSetPageSize) {
257
+ if (userSetPageSize) {
259
258
  _defaults.pageSize = userSetPageSize;
260
259
  }
261
260
 
@@ -266,7 +265,6 @@ const DataTable = ({
266
265
  isLocalCall,
267
266
  orderByFirstColumn,
268
267
  props.defaults,
269
- syncDisplayOptionsToDb,
270
268
  userSetPageSize
271
269
  ]);
272
270
 
@@ -393,8 +391,6 @@ const DataTable = ({
393
391
  controlled_setPage,
394
392
  controlled_setPageSize,
395
393
  controlled_total,
396
- currentUser,
397
- deleteTableConfiguration,
398
394
  disabled = false,
399
395
  disableSetPageSize,
400
396
  doNotShowEmptyRows,
@@ -471,8 +467,6 @@ const DataTable = ({
471
467
  tableConfigurations,
472
468
  tableName,
473
469
  topLeftItems,
474
- upsertFieldOption,
475
- upsertTableConfiguration,
476
470
  variables,
477
471
  withCheckboxes = false,
478
472
  withDisplayOptions,
@@ -537,11 +531,7 @@ const DataTable = ({
537
531
  useEffect(() => {
538
532
  if (withDisplayOptions) {
539
533
  let newTableConfig = {};
540
- if (syncDisplayOptionsToDb) {
541
- newTableConfig = tableConfigurations && tableConfigurations[0];
542
- } else {
543
- newTableConfig = getTableConfigFromStorage(formName);
544
- }
534
+ newTableConfig = getTableConfigFromStorage(formName);
545
535
  !noExcessiveCheck &&
546
536
  isBeingCalledExcessively({ uniqName: `dt_setTableConfig_${formName}` });
547
537
  // if the tableConfig is the same as the newTableConfig, don't update
@@ -564,7 +554,6 @@ const DataTable = ({
564
554
  convertedSchema, // If the schema changes we want to take into account the synced tableConfig again
565
555
  formName,
566
556
  setTableConfig,
567
- syncDisplayOptionsToDb,
568
557
  tableConfigurations,
569
558
  withDisplayOptions,
570
559
  noExcessiveCheck
@@ -628,8 +617,7 @@ const DataTable = ({
628
617
  if (noValsForField && entities.length) {
629
618
  return {
630
619
  ...field,
631
- isHidden: true,
632
- isForcedHidden: true
620
+ isHidden: true
633
621
  };
634
622
  } else if (fieldOpt) {
635
623
  return {
@@ -697,6 +685,7 @@ const DataTable = ({
697
685
  withDisplayOptions,
698
686
  recordIdToIsVisibleMap
699
687
  ]);
688
+ const [columns, setColumns] = useState([]);
700
689
 
701
690
  const {
702
691
  moveColumnPersist,
@@ -715,79 +704,45 @@ const DataTable = ({
715
704
 
716
705
  if (withDisplayOptions) {
717
706
  const fieldOptsByPath = keyBy(tableConfig.fieldOptions, "path");
718
- if (syncDisplayOptionsToDb) {
719
- // sync up to db
720
- // There must be a better way to set this variable...
721
- let tableConfigurationId;
722
- resetDefaultVisibility = function () {
723
- tableConfigurationId = tableConfig.id;
724
- if (tableConfigurationId) {
725
- deleteTableConfiguration(tableConfigurationId);
726
- }
727
- };
728
- updateColumnVisibility = function ({ shouldShow, path }) {
729
- if (tableConfigurationId) {
730
- const existingFieldOpt = fieldOptsByPath[path] || {};
731
- upsertFieldOption({
732
- id: existingFieldOpt.id,
733
- path,
734
- isHidden: !shouldShow,
735
- tableConfigurationId
736
- });
737
- } else {
738
- upsertTableConfiguration({
739
- userId: currentUser.user.id,
740
- formName,
741
- fieldOptions: [
742
- {
743
- path,
744
- isHidden: !shouldShow
745
- }
746
- ]
747
- });
748
- }
749
- };
750
- } else {
751
- const syncStorage = newTableConfig => {
752
- setTableConfig(newTableConfig);
753
- window.localStorage.setItem(formName, JSON.stringify(newTableConfig));
754
- };
755
707
 
756
- //sync display options with localstorage
757
- resetDefaultVisibility = function () {
758
- setTableConfig({ fieldOptions: [] });
759
- window.localStorage.removeItem(formName);
760
- };
761
- updateColumnVisibility = function ({ path, paths, shouldShow }) {
762
- const newFieldOpts = {
763
- ...fieldOptsByPath
764
- };
765
- const pathsToUse = paths ? paths : [path];
766
- pathsToUse.forEach(path => {
767
- newFieldOpts[path] = { path, isHidden: !shouldShow };
768
- });
769
- syncStorage({ ...tableConfig, fieldOptions: toArray(newFieldOpts) });
770
- };
771
- updateTableDisplayDensity = function (density) {
772
- syncStorage({ ...tableConfig, density: density });
773
- };
774
- persistPageSize = function (pageSize) {
775
- syncStorage({ ...tableConfig, userSetPageSize: pageSize });
776
- };
777
- moveColumnPersist = function ({ oldIndex, newIndex }) {
778
- // we might already have an array of the fields [path1, path2, ..etc]
779
- const columnOrderings =
780
- tableConfig.columnOrderings ||
781
- schema.fields.map(({ path }) => path); // columnOrderings is [path1, path2, ..etc]
782
- syncStorage({
783
- ...tableConfig,
784
- columnOrderings: arrayMove(columnOrderings, oldIndex, newIndex)
785
- });
786
- };
787
- resizePersist = function (newResized) {
788
- syncStorage({ ...tableConfig, resized: newResized });
708
+ const syncStorage = newTableConfig => {
709
+ setTableConfig(newTableConfig);
710
+ window.localStorage.setItem(formName, JSON.stringify(newTableConfig));
711
+ };
712
+
713
+ //sync display options with localstorage
714
+ resetDefaultVisibility = function () {
715
+ setTableConfig({ fieldOptions: [] });
716
+ window.localStorage.removeItem(formName);
717
+ };
718
+ updateColumnVisibility = function ({ path, paths, shouldShow }) {
719
+ const newFieldOpts = {
720
+ ...fieldOptsByPath
789
721
  };
790
- }
722
+ const pathsToUse = paths ? paths : [path];
723
+ pathsToUse.forEach(path => {
724
+ newFieldOpts[path] = { path, isHidden: !shouldShow };
725
+ });
726
+ syncStorage({ ...tableConfig, fieldOptions: toArray(newFieldOpts) });
727
+ };
728
+ updateTableDisplayDensity = function (density) {
729
+ syncStorage({ ...tableConfig, density: density });
730
+ };
731
+ persistPageSize = function (pageSize) {
732
+ syncStorage({ ...tableConfig, userSetPageSize: pageSize });
733
+ };
734
+ moveColumnPersist = function ({ oldIndex, newIndex }) {
735
+ // we might already have an array of the fields [path1, path2, ..etc]
736
+ const columnOrderings =
737
+ tableConfig.columnOrderings || columns.map(({ path }) => path); // columnOrderings is [path1, path2, ..etc]
738
+ syncStorage({
739
+ ...tableConfig,
740
+ columnOrderings: arrayMove(columnOrderings, oldIndex, newIndex)
741
+ });
742
+ };
743
+ resizePersist = function (newResized) {
744
+ syncStorage({ ...tableConfig, resized: newResized });
745
+ };
791
746
  }
792
747
  return {
793
748
  moveColumnPersist,
@@ -797,18 +752,7 @@ const DataTable = ({
797
752
  updateColumnVisibility,
798
753
  updateTableDisplayDensity
799
754
  };
800
- }, [
801
- currentUser?.user?.id,
802
- deleteTableConfiguration,
803
- formName,
804
- setTableConfig,
805
- schema.fields,
806
- syncDisplayOptionsToDb,
807
- tableConfig,
808
- upsertFieldOption,
809
- upsertTableConfiguration,
810
- withDisplayOptions
811
- ]);
755
+ }, [formName, setTableConfig, columns, tableConfig, withDisplayOptions]);
812
756
 
813
757
  let compact = _compact;
814
758
  let extraCompact = _extraCompact;
@@ -1524,7 +1468,6 @@ const DataTable = ({
1524
1468
  );
1525
1469
 
1526
1470
  const { handleKeyDown, handleKeyUp } = useHotkeys(hotKeys);
1527
- const [columns, setColumns] = useState([]);
1528
1471
  const [fullscreen, setFullscreen] = useState(false);
1529
1472
  const [selectingAll, setSelectingAll] = useState(false);
1530
1473
 
@@ -1735,21 +1678,19 @@ const DataTable = ({
1735
1678
  addFilters(additionalFilters);
1736
1679
  // eslint-disable-next-line react-hooks/exhaustive-deps
1737
1680
  }, [additionalFilters]);
1738
-
1739
1681
  useEffect(() => {
1740
- setColumns(
1741
- schema.fields
1742
- ? schema.fields.reduce((col, field, i) => {
1743
- if (field.isHidden) {
1744
- return col;
1745
- }
1746
- return col.concat({
1747
- ...field,
1748
- columnIndex: i
1749
- });
1750
- }, [])
1751
- : []
1752
- );
1682
+ const newCols = schema.fields
1683
+ ? schema.fields.reduce((columns, field, i) => {
1684
+ if (field.isHidden) {
1685
+ return columns.concat(field);
1686
+ }
1687
+ return columns.concat({
1688
+ ...field,
1689
+ columnIndex: i
1690
+ });
1691
+ }, [])
1692
+ : [];
1693
+ setColumns(newCols);
1753
1694
  }, [schema?.fields]);
1754
1695
 
1755
1696
  const setSelectedIds = useCallback(
@@ -1830,28 +1771,22 @@ const DataTable = ({
1830
1771
  const TheadComponent = useCallback(
1831
1772
  ({ className, style, children }) => {
1832
1773
  const moveColumn = ({ oldIndex, newIndex }) => {
1833
- let oldStateColumnIndex, newStateColumnIndex;
1834
- columns.forEach((column, i) => {
1835
- if (oldIndex === column.columnIndex) oldStateColumnIndex = i;
1836
- if (newIndex === column.columnIndex) newStateColumnIndex = i;
1837
- });
1838
1774
  // because it is all handled in state we need
1839
1775
  // to perform the move and update the columnIndices
1840
1776
  // because they are used for the sortable columns
1841
- const newColumns = arrayMove(
1842
- columns,
1843
- oldStateColumnIndex,
1844
- newStateColumnIndex
1845
- ).map((column, i) => {
1846
- return {
1847
- ...column,
1848
- columnIndex: i
1849
- };
1850
- });
1777
+ const newColumns = arrayMove(columns, oldIndex, newIndex).map(
1778
+ (column, i) => {
1779
+ return {
1780
+ ...column,
1781
+ columnIndex: i
1782
+ };
1783
+ }
1784
+ );
1851
1785
  setColumns(newColumns);
1852
1786
  };
1853
1787
  return (
1854
1788
  <SortableColumns
1789
+ sortedItemsFull={columns.map(c => c.path)}
1855
1790
  className={className}
1856
1791
  style={style}
1857
1792
  moveColumn={moveColumnPersist || moveColumn}
@@ -2825,7 +2760,7 @@ const DataTable = ({
2825
2760
  noVirtual={noVirtual}
2826
2761
  className={classNames({
2827
2762
  isCellEditable,
2828
- "loading": isLoading,
2763
+ loading: isLoading,
2829
2764
  "tg-table-loading": isLoading,
2830
2765
  "tg-table-disabled": disabled
2831
2766
  })}
@@ -3262,6 +3197,7 @@ const DataTable = ({
3262
3197
  resetDefaultVisibility={resetDefaultVisibility}
3263
3198
  updateColumnVisibility={updateColumnVisibility}
3264
3199
  updateTableDisplayDensity={updateTableDisplayDensity}
3200
+ moveColumnPersist={moveColumnPersist}
3265
3201
  showForcedHiddenColumns={showForcedHiddenColumns}
3266
3202
  setShowForcedHidden={setShowForcedHidden}
3267
3203
  hasOptionForForcedHidden={
@@ -598,3 +598,16 @@ body:not(.drag-active)
598
598
  display: flex;
599
599
  flex-direction: column;
600
600
  }
601
+ .th-dragging {
602
+ z-index: 999 !important;
603
+ cursor: grabbing !important;
604
+ opacity: 0.8;
605
+ background-color: #f5f8fa;
606
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
607
+ }
608
+
609
+ .bp3-dark .th-dragging {
610
+ background-color: #30404d;
611
+ box-shadow: 0 2px 8px rgba(250, 245, 245, 0.15);
612
+ outline: 1px solid #48aff0;
613
+ }
@@ -311,10 +311,15 @@ export function getQueryParams({
311
311
  const ccDisplayName = orderVal.replace(/^-/gi, "");
312
312
  const schemaForField = ccFields[ccDisplayName];
313
313
  if (schemaForField) {
314
- const { path } = schemaForField;
314
+ const { path, additionalSearchPaths } = schemaForField;
315
315
  const reversed = ccDisplayName !== orderVal;
316
316
  const prefix = reversed ? "-" : "";
317
317
  cleanedOrder.push(prefix + path);
318
+ if (additionalSearchPaths && additionalSearchPaths.length) {
319
+ additionalSearchPaths.forEach(additionalPath => {
320
+ cleanedOrder.push(prefix + additionalPath);
321
+ });
322
+ }
318
323
  } else {
319
324
  !noOrderError &&
320
325
  console.error(