Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates to editor and repl views #374

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions shared/common/components/dataGrid/dataGrid.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
width: 100%;
height: 100%;
overflow: auto;
overscroll-behavior: contain;
overscroll-behavior: contain auto;
font-family: "Roboto Mono Variable", monospace;

@include hideScrollbar;

&.noVerticalScroll {
overflow-y: hidden;
}
}

.innerWrapper {
Expand All @@ -28,7 +32,7 @@
top: 0;
min-width: max-content;
display: grid;
background: var(--panel_background);
background: var(--header_background);
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
color: var(--main_text_color);
font-weight: 450;
Expand Down Expand Up @@ -86,7 +90,7 @@
left: 0;
grid-row: 1 / -1;
display: grid;
background: var(--panel_background);
background: var(--header_background);
z-index: 2;
border-right: 1px solid var(--panel_border);

Expand Down Expand Up @@ -153,3 +157,14 @@
background: var(--Grey12) !important;
}
}

.scalar_str,
.scalar_uuid {
&:before,
&:after {
content: "";
}
}
.scalar_uuid {
color: #6f6f6f;
}
24 changes: 20 additions & 4 deletions shared/common/components/dataGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ import {useGlobalDragCursor} from "../../hooks/globalDragCursor";

export interface DataGridProps {
state: DataGridState;
className?: string;
style?: React.CSSProperties;
noVerticalScroll?: boolean;
}

export function DataGrid({state, children}: PropsWithChildren<DataGridProps>) {
export function DataGrid({
state,
className,
style,
noVerticalScroll,
children,
}: PropsWithChildren<DataGridProps>) {
const ref = useRef<HTMLDivElement | null>(null);

useResize(ref, ({width, height}) =>
Expand All @@ -40,9 +49,11 @@ export function DataGrid({state, children}: PropsWithChildren<DataGridProps>) {

return (
<CustomScrollbars
className={styles.scrollbarWrapper}
className={cn(styles.scrollbarWrapper, className)}
innerClass={styles.innerWrapper}
headerPadding={state.headerHeight}
style={style}
headerPadding={noVerticalScroll ? undefined : state.headerHeight}
hideVertical={noVerticalScroll}
>
<div
ref={(el) => {
Expand All @@ -53,7 +64,9 @@ export function DataGrid({state, children}: PropsWithChildren<DataGridProps>) {
el.scrollLeft = state.scrollPos.left;
}
}}
className={styles.dataGrid}
className={cn(styles.dataGrid, {
[styles.noVerticalScroll]: !!noVerticalScroll,
})}
>
<div className={styles.innerWrapper}>{children}</div>
</div>
Expand All @@ -66,11 +79,13 @@ export const GridHeaders = observer(function GridHeaders({
state,
pinnedHeaders,
headers,
style,
}: {
className?: string;
state: DataGridState;
pinnedHeaders: React.ReactNode;
headers: React.ReactNode;
style?: React.CSSProperties;
}) {
const ref = useRef<HTMLDivElement>(null);

Expand All @@ -81,6 +96,7 @@ export const GridHeaders = observer(function GridHeaders({
ref={ref}
className={cn(styles.headers, className)}
style={{
...style,
gridTemplateColumns: `${
state.pinnedColsWidth ? `${state.pinnedColsWidth}px ` : ""
}${state.colWidths.join("px ")}px minmax(100px, 1fr)`,
Expand Down
97 changes: 97 additions & 0 deletions shared/common/components/dataGrid/renderUtils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {Fragment} from "react";

import {ICodec} from "edgedb/dist/codecs/ifaces";
import {EnumCodec} from "edgedb/dist/codecs/enum";
import {NamedTupleCodec} from "edgedb/dist/codecs/namedtuple";
import {MultiRangeCodec, RangeCodec} from "edgedb/dist/codecs/range";

import {renderValue} from "@edgedb/inspector/buildScalar";

import styles from "./dataGrid.module.scss";

const inspectorOverrideStyles = {
uuid: styles.scalar_uuid,
str: styles.scalar_str,
};

export function renderCellValue(
value: any,
codec: ICodec,
nested = false
): JSX.Element {
switch (codec.getKind()) {
case "scalar":
case "range":
case "multirange":
return renderValue(
value,
codec.getKnownTypeName(),
codec instanceof EnumCodec,
codec instanceof RangeCodec || codec instanceof MultiRangeCodec
? codec.getSubcodecs()[0].getKnownTypeName()
: undefined,
false,
!nested ? inspectorOverrideStyles : undefined,
100
).body;
case "set":
return (
<>
{"{"}
{(value as any[]).map((item, i) => (
<Fragment key={i}>
{i !== 0 ? ", " : null}
{renderCellValue(item, codec.getSubcodecs()[0], true)}
</Fragment>
))}
{"}"}
</>
);
case "array":
return (
<>
[
{(value as any[]).map((item, i) => (
<Fragment key={i}>
{i !== 0 ? ", " : null}
{renderCellValue(item, codec.getSubcodecs()[0], true)}
</Fragment>
))}
]
</>
);
case "tuple":
return (
<>
(
{(value as any[]).map((item, i) => (
<Fragment key={i}>
{i !== 0 ? ", " : null}
{renderCellValue(item, codec.getSubcodecs()[i], true)}
</Fragment>
))}
)
</>
);
case "namedtuple": {
const fieldNames = (codec as NamedTupleCodec).getNames();
const subCodecs = codec.getSubcodecs();
return (
<>
(
{fieldNames.map((name, i) => (
<Fragment key={i}>
{i !== 0 ? ", " : null}
{name}
{" := "}
{renderCellValue(value[name], subCodecs[i], true)}
</Fragment>
))}
)
</>
);
}
default:
return <></>;
}
}
Loading
Loading