Skip to content

Commit

Permalink
fix: make name change backwards compat in the ui (#3147)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick authored Dec 12, 2024
1 parent 0e99bed commit 2367332
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions frontend/src/components/editor/actions/name-cell-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Tooltip } from "@/components/ui/tooltip";
import { getCellNames, useCellActions } from "@/core/cells/cells";
import type { CellId } from "@/core/cells/ids";
import {
DEFAULT_CELL_NAME,
normalizeName,
getValidName,
isInternalCellName,
} from "@/core/cells/names";
import { useOnMount } from "@/hooks/useLifecycle";
import { cn } from "@/utils/cn";
Expand Down Expand Up @@ -69,7 +69,7 @@ export const NameCellContentEditable: React.FC<{
);

// If the name is the default, don't render the content editable
if (value === DEFAULT_CELL_NAME) {
if (isInternalCellName(value)) {
return null;
}

Expand Down Expand Up @@ -106,7 +106,7 @@ function useCellNameInput(value: string, onChange: (newName: string) => void) {
}

// Empty
if (!newValue || newValue === DEFAULT_CELL_NAME) {
if (!newValue || isInternalCellName(newValue)) {
onChange(newValue);
return;
}
Expand All @@ -117,7 +117,7 @@ function useCellNameInput(value: string, onChange: (newName: string) => void) {
};

return {
value: internalValue === DEFAULT_CELL_NAME ? "" : internalValue,
value: isInternalCellName(internalValue) ? "" : internalValue,
onChange: (evt: React.ChangeEvent<HTMLInputElement>) => {
const newValue = evt.target.value;
const normalized = normalizeName(newValue);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/editor/output/ConsoleOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useLayoutEffect } from "react";
import type { OutputMessage } from "@/core/kernel/messages";
import { OutputRenderer } from "../Output";
import { cn } from "@/utils/cn";
import { DEFAULT_CELL_NAME } from "@/core/cells/names";
import { isInternalCellName } from "@/core/cells/names";
import { NameCellContentEditable } from "../actions/name-cell-input";
import type { CellId } from "@/core/cells/ids";
import { Input } from "@/components/ui/input";
Expand Down Expand Up @@ -71,7 +71,7 @@ export const ConsoleOutput = (props: Props): React.ReactNode => {
}
});

if (!hasOutputs && cellName === DEFAULT_CELL_NAME) {
if (!hasOutputs && isInternalCellName(cellName)) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/variables/variables-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { goToVariableDefinition } from "@/core/codemirror/go-to-definition/comma
import { SearchInput } from "../ui/input";
import { CellLinkList } from "../editor/links/cell-link-list";
import { VariableName } from "./common";
import { DEFAULT_CELL_NAME } from "@/core/cells/names";
import { isInternalCellName } from "@/core/cells/names";

interface Props {
className?: string;
Expand Down Expand Up @@ -233,7 +233,7 @@ export const VariableTable: React.FC<Props> = memo(
const resolvedVariables: ResolvedVariable[] = useMemo(() => {
const getName = (id: CellId) => {
const name = cellNames[id];
if (name === DEFAULT_CELL_NAME) {
if (isInternalCellName(name)) {
return `cell-${cellIds.indexOf(id)}`;
}
return name ?? `cell-${cellIds.indexOf(id)}`;
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/core/cells/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export function displayCellName(name: string, cellIndex: number): string {
}

// Default cell names are "_" and "__" (for backwards compatibility)
function isInternalCellName(name: string): boolean {
export function isInternalCellName(name: string | undefined): boolean {
if (!name) {
return true;
}
return name === DEFAULT_CELL_NAME || name === "__";
}

0 comments on commit 2367332

Please sign in to comment.