An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
refactor: remove useless dnd fix & refactor button
ObservedObserver6d59b7c5d7e2
diff --git a/packages/graphic-walker/src/components/button/base.ts b/packages/graphic-walker/src/components/button/base.tsnew file mode 100644index 00000000..1a2cd693--- /dev/null+++ b/packages/graphic-walker/src/components/button/base.ts@@ -0,0 +1,7 @@+import React from 'react';++export interface ButtonBaseProps {+ onClick: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;+ text: string;+ disabled?: boolean;+}\ No newline at end of filediff --git a/packages/graphic-walker/src/components/button/default.tsx b/packages/graphic-walker/src/components/button/default.tsxnew file mode 100644index 00000000..d007e259--- /dev/null+++ b/packages/graphic-walker/src/components/button/default.tsx@@ -0,0 +1,17 @@+import React from "react";+import { ButtonBaseProps } from "./base";++const DefaultButton: React.FC<ButtonBaseProps> = (props) => {+ const { text, onClick, disabled } = props;+ return (+ <button+ className="inline-block min-w-96 text-xs ml-2 pt-1 pb-1 pl-6 pr-6 border border-gray-500 rounded-sm hover:bg-gray-800 hover:border-gray-800 hover:text-white disabled:bg-gray-400 disabled:border-gray-400 disabled:text-white disabled:cursor-not-allowed disabled:text-white"+ onClick={onClick}+ disabled={disabled}+ >+ {text}+ </button>+ );+};++export default DefaultButton;diff --git a/packages/graphic-walker/src/components/button/primary.tsx b/packages/graphic-walker/src/components/button/primary.tsxnew file mode 100644index 00000000..8b92deed--- /dev/null+++ b/packages/graphic-walker/src/components/button/primary.tsx@@ -0,0 +1,17 @@+import React from "react";+import { ButtonBaseProps } from "./base";++const PrimaryButton: React.FC<ButtonBaseProps> = (props) => {+ const { text, onClick, disabled } = props;+ return (+ <button+ className="inline-block min-w-96 text-xs ml-2 pt-1 pb-1 pl-6 pr-6 border border-gray-800 bg-gray-800 text-white rounded-sm hover:bg-white border-gray-800 hover:text-gray-800 cursor-pointer disabled:bg-gray-400 disabled:border-gray-400 disabled:text-white disabled:cursor-not-allowed disabled:text-white"+ onClick={onClick}+ disabled={disabled}+ >+ {text}+ </button>+ );+};++export default PrimaryButton;diff --git a/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx b/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsxindex 70d0fb15..a85914d4 100644--- a/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx+++ b/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx@@ -6,6 +6,8 @@ import styled from "styled-components";import { useGlobalStore } from "../../store";import { observer } from "mobx-react-lite";import { useTranslation } from "react-i18next";+import DefaultButton from "../../components/button/default";+import PrimaryButton from "../../components/button/primary";const Container = styled.div`overflow-x: auto;@@ -44,25 +46,21 @@ const CSVData: React.FC<ICSVData> = (props) => {}}/><div className="mt-1 mb-1">- <button- className="inline-block min-w-96 text-xs mr-2 pt-1 pb-1 pl-6 pr-6 border border-gray-500 rounded-sm cursor-pointer hover:bg-gray-200"+ <DefaultButtononClick={() => {if (fileRef.current) {fileRef.current.click();}}}- >- {t("open")}- </button>- <button- className="inline-block min-w-96 text-xs mr-2 pt-1 pb-1 pl-6 pr-6 bg-black rounded-sm hover:bg-gray-500 text-white font-bold disabled:bg-gray-300"+ text={t("open")}+ />+ <PrimaryButton+ text={t("submit")}disabled={tmpDataSource.length === 0}onClick={() => {onSubmitData();}}- >- {t("submit")}- </button>+ /></div><div className="my-2"><label className="block text-xs text-gray-800 mb-1 font-bold">{t("dataset_name")}</label>diff --git a/packages/graphic-walker/src/dataSource/dataSelection/publicData.tsx b/packages/graphic-walker/src/dataSource/dataSelection/publicData.tsxindex dcc54e0f..0477d5d0 100644--- a/packages/graphic-walker/src/dataSource/dataSelection/publicData.tsx+++ b/packages/graphic-walker/src/dataSource/dataSelection/publicData.tsx@@ -4,6 +4,7 @@ import { DemoDataAssets, PUBLIC_DATA_LIST } from '../config'import { useGlobalStore } from '../../store';import { observer } from 'mobx-react-lite';import { useTranslation } from 'react-i18next';+import PrimaryButton from '../../components/button/primary';interface IPublicDataProps {@@ -43,12 +44,11 @@ const PublicData: React.FC<IPublicDataProps> = props => {}</div><hr className="m-1" />- <button className="inline-block min-w-96 text-xs mr-2 pt-1 pb-1 pl-6 pr-6 bg-black rounded-sm hover:bg-gray-500 text-white font-bold disabled:bg-gray-300"+ <PrimaryButtondisabled={tmpDataSource.length === 0}onClick={() => { commonStore.commitTempDS() }}- >- {t('submit')}- </button>+ text={t('submit')}+ /><hr className="m-1" /><Table /></div>diff --git a/packages/graphic-walker/src/dataSource/index.tsx b/packages/graphic-walker/src/dataSource/index.tsxindex f6af4086..0eb14a19 100644--- a/packages/graphic-walker/src/dataSource/index.tsx+++ b/packages/graphic-walker/src/dataSource/index.tsx@@ -8,6 +8,7 @@ import { useGlobalStore } from '../store';import { download } from '../utils/save';import GwFile from './dataSelection/gwFile';import DataSelection from './dataSelection';+import DefaultButton from '../components/button/default';interface DSSegmentProps {preWorkDone: boolean;@@ -39,28 +40,25 @@ const DataSourceSegment: React.FC<DSSegmentProps> = props => {))}</select>- <button className="inline-block min-w-96 text-xs ml-2 pt-1 pb-1 pl-6 pr-6 border border-gray-500 rounded-sm hover:bg-gray-200"+ <DefaultButton+ text={t('DataSource.buttons.create_dataset')}onClick={() => { commonStore.startDSBuildingTask() }}- >- {t('DataSource.buttons.create_dataset')}- </button>- <button className="inline-block min-w-96 text-xs ml-2 pt-1 pb-1 pl-6 pr-6 border border-gray-500 rounded-sm hover:bg-gray-200"+ />+ <DefaultButton+ text={t('DataSource.buttons.export_as_file')}onClick={() => {const res = vizStore.exportAsRaw();download(res, 'graphic-walker-notebook.json', 'text/plain')}}- >- {t('DataSource.buttons.export_as_file')}- </button>- <button className="inline-block min-w-96 text-xs ml-2 pt-1 pb-1 pl-6 pr-6 border border-gray-500 rounded-sm hover:bg-gray-200"+ />+ <DefaultButton+ text={t('DataSource.buttons.import_file')}onClick={() => {if (gwFileRef.current) {gwFileRef.current.click();}}}- >- {t('DataSource.buttons.import_file')}- </button>+ />{showDSPanel && (<Modaltitle={t('DataSource.dialog.create_data_source')}diff --git a/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx b/packages/graphic-walker/src/fields/datasetFields/dimFields.tsxindex a3eb5694..ef249145 100644--- a/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx+++ b/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx@@ -4,7 +4,6 @@ import { observer } from 'mobx-react-lite';import { useGlobalStore } from '../../store';import DataTypeIcon from '../../components/dataTypeIcon';import { FieldPill } from './fieldPill';-import { fixDraggableOffset } from '../../pitch/dnd-offset';interface Props {provided: DroppableProvided;@@ -17,9 +16,6 @@ const DimFields: React.FC<Props> = props => {{dimensions.map((f, index) => (<Draggable key={f.dragId} draggableId={f.dragId} index={index}>{(provided, snapshot) => {- if (snapshot.isDragging && provided.draggableProps.style) {- fixDraggableOffset(provided, commonStore.rootContainer)- }return (<>diff --git a/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx b/packages/graphic-walker/src/fields/datasetFields/meaFields.tsxindex f1005e28..14dca9db 100644--- a/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx+++ b/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx@@ -4,7 +4,6 @@ import { observer } from 'mobx-react-lite';import { useGlobalStore } from '../../store';import DataTypeIcon from '../../components/dataTypeIcon';import { FieldPill } from './fieldPill';-import { fixDraggableOffset } from '../../pitch/dnd-offset';interface Props {provided: DroppableProvided;@@ -17,9 +16,6 @@ const MeaFields: React.FC<Props> = props => {{measures.map((f, index) => (<Draggable key={f.dragId} draggableId={f.dragId} index={index}>{(provided, snapshot) => {- if (snapshot.isDragging && provided.draggableProps.style) {- fixDraggableOffset(provided, commonStore.rootContainer)- }return (<><FieldPilldiff --git a/packages/graphic-walker/src/fields/obComponents/obFContainer.tsx b/packages/graphic-walker/src/fields/obComponents/obFContainer.tsxindex f4db33cb..1c43f8cd 100644--- a/packages/graphic-walker/src/fields/obComponents/obFContainer.tsx+++ b/packages/graphic-walker/src/fields/obComponents/obFContainer.tsx@@ -8,7 +8,6 @@ import {} from "@kanaries/react-beautiful-dnd";import { IDraggableStateKey } from '../../interfaces';import OBPill from './obPill';-import { fixDraggableOffset } from '../../pitch/dnd-offset';interface FieldContainerProps {provided: DroppableProvided@@ -29,9 +28,6 @@ const OBFieldContainer: React.FC<FieldContainerProps> = props => {{draggableFieldState[dkey.id].map((f, index) => (<Draggable key={f.dragId} draggableId={f.dragId} index={index}>{(provided, snapshot) => {- if (snapshot.isDragging && provided.draggableProps.style) {- fixDraggableOffset(provided, commonStore.rootContainer)- }return (<OBPill dkey={dkey} fIndex={index} provided={provided} />);diff --git a/packages/graphic-walker/src/main.tsx b/packages/graphic-walker/src/main.tsxindex 5bb5dcca..96201f19 100644--- a/packages/graphic-walker/src/main.tsx+++ b/packages/graphic-walker/src/main.tsx@@ -9,7 +9,7 @@ inject();ReactDOM.render(<React.StrictMode>- <GraphicWalker />+ <GraphicWalker fixContainer /></React.StrictMode>,document.getElementById("root"));diff --git a/packages/graphic-walker/src/pitch/dnd-offset.ts b/packages/graphic-walker/src/pitch/dnd-offset.tsdeleted file mode 100644index 2f4b5a82..00000000--- a/packages/graphic-walker/src/pitch/dnd-offset.ts+++ /dev/null@@ -1,64 +0,0 @@-import { DraggableProvided } from "react-beautiful-dnd";--function getElementBoxInfo(ele: HTMLElement) {- const style = window.getComputedStyle(ele);- const borderLeft = parseInt(style.borderLeftWidth);- const paddingLeft = parseInt(style.paddingLeft);- const marginLeft = parseInt(style.marginLeft);- const borderTop = parseInt(style.borderTopWidth);- const paddingTop = parseInt(style.paddingTop);- const marginTop = parseInt(style.marginTop);- return {- borderLeft,- paddingLeft,- marginLeft,- borderTop,- paddingTop,- marginTop,- style- };-}--export function fixDraggableOffset(provided: DraggableProvided, containerDOM: HTMLElement | undefined | null) {- if (typeof containerDOM === 'undefined' || containerDOM === null) return;- const containerRect = containerDOM.getBoundingClientRect();- const offset = { x: containerRect.left, y: containerRect.top };- let parent: HTMLElement | null = containerDOM.parentElement;- while (parent !== null) {- const box = getElementBoxInfo(parent);- const {- borderLeft: parentBorderLeft,- paddingLeft: parentPaddingLeft,- marginLeft: parentMarginLeft,- borderTop: parentBorderTop,- paddingTop: parentPaddingTop,- marginTop: parentMarginTop,- style- } = box;- offset.x -= ( parentBorderLeft + parentPaddingLeft + parentMarginLeft);- offset.y -= (parentBorderTop + parentPaddingTop + parentMarginTop);- if (style.position === 'absolute' || style.position === 'fixed') {-- break;- }-- parent = parent.parentElement;- }- const root = document.documentElement;- const scrollTop = (window.pageYOffset || root.scrollTop) - (root.clientTop || 0);- const scrollLeft = (window.pageXOffset || root.scrollLeft) - (root.clientLeft || 0);- offset.y += scrollTop;- offset.x += scrollLeft;- //@ts-ignore- const x = (provided.draggableProps.style.left! ?? 0) - offset.x;- //@ts-ignore- const y = (provided.draggableProps.style.top! ?? 0) - offset.y- // TODO: Fix the offset error when there is a layer has padding between fixed layer and provided.draggableProps.style ele.- // the error seems to be 16px which is the pill's height- // provided.draggableProps.style.height;// - 2 - 2 - 1 - 1;-- // @ts-ignore- provided.draggableProps.style.left = x;- // @ts-ignore- provided.draggableProps.style.top = y;-}\ No newline at end of file