Skip to content

Commit

Permalink
feat: add spinner to column badge while computing
Browse files Browse the repository at this point in the history
  • Loading branch information
neindochoh committed Dec 8, 2023
1 parent f1c2f7f commit b3df609
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions src/components/ui/ColumnBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { ColumnDragData } from '../../systems/dnd/types';
import Draggable from '../../systems/dnd/Draggable';
import { useDataset } from '../../stores/dataset';
import { type CSSProp } from 'styled-components';
import Spinner from './Spinner';

interface InternalProps {
column: DataColumn;
computing: boolean;
className?: string;
css?: CSSProp;
}
Expand All @@ -20,13 +22,22 @@ interface Props {
css?: CSSProp;
}

const StaticColumnBadge = ({ column, className }: InternalProps): JSX.Element => {
const StaticColumnBadge = ({
column,
computing,
className,
}: InternalProps): JSX.Element => {
return (
<div
tw="flex flex-row truncate rounded border text-xs text-midnight-500 bg-gray-100 p-0.5 hover:border-gray-600 transition space-x-0.5"
className={className}
>
<DataTypeIcon type={column.type} />
<div tw="relative">
<DataTypeIcon type={column.type} />
{computing && (
<Spinner tw="h-2 w-2 bottom-0 right-0 absolute bg-gray-100 border-gray-100 text-gray-600 border" />
)}
</div>
{column.editable && <EditIcon />}
<span>{column.name}</span>
</div>
Expand All @@ -39,16 +50,25 @@ const ColumnBadge = ({
draggable = true,
}: Props): JSX.Element => {
const column = useDataset((state) => state.columnsByKey[columnKey]);
const computing = useDataset(
(state) =>
state.columnsByKey[columnKey].computed &&
state.columnData[columnKey] === undefined
);

const badge = (
<StaticColumnBadge
column={column}
computing={computing}
className={className}
/>
);

if (draggable) {
const dragData: ColumnDragData = { kind: 'column', column };
return (
<Draggable data={dragData}>
<StaticColumnBadge column={column} className={className} />
</Draggable>
);
return <Draggable data={dragData}>{badge}</Draggable>;
} else {
return <StaticColumnBadge column={column} className={className} />;
return badge;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tw from 'twin.macro';

const Svg = tw.svg`text-blue-400 w-full h-full animate-spin`;
const Svg = tw.svg`text-blue-400 w-full h-full animate-spin rounded-full`;
const Circle = tw.circle`opacity-50 stroke-current`;
const Path = tw.path`text-blue-600 stroke-current`;

Expand Down

0 comments on commit b3df609

Please sign in to comment.