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

7/n Read-only mode: Prompt Menu (Left side triple dots) #961

Merged
merged 2 commits into from
Jan 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
} from "@mantine/core";
import { IconTrash, IconPlus } from "@tabler/icons-react";
import { debounce, uniqueId } from "lodash";
import { useState, useCallback, memo, useMemo } from "react";
import { useState, useCallback, memo, useMemo, useContext } from "react";
import { JSONValue, JSONObject } from "aiconfig";
import AIConfigContext from "../contexts/AIConfigContext";

type Parameter = { parameterName: string; parameterValue: JSONValue };

Expand All @@ -36,7 +37,7 @@ const ParameterInput = memo(function ParameterInput(props: {
}) {
const { initialItemValue, removeParameter, onUpdateParameter } = props;
// TODO: saqadri - update this once we have a readonly mode
const { isReadonly } = { isReadonly: false };
const { readOnly } = useContext(AIConfigContext);

const [parameterName, setParameterName] = useState(
initialItemValue?.parameterName ?? ""
Expand Down Expand Up @@ -79,7 +80,7 @@ const ParameterInput = memo(function ParameterInput(props: {
<Stack p="xs" spacing="xs" style={{ flexGrow: 1, borderBottom: border }}>
<TextInput
placeholder="Enter parameter name"
disabled={isReadonly}
disabled={readOnly}
error={
parameterName && !isValidParameterName(parameterName)
? "Name must contain only letters, numbers, and underscores"
Expand All @@ -100,7 +101,7 @@ const ParameterInput = memo(function ParameterInput(props: {
/>
<Textarea
placeholder="Enter parameter value"
disabled={isReadonly}
disabled={readOnly}
radius="md"
value={parameterValueString}
autosize
Expand All @@ -111,12 +112,12 @@ const ParameterInput = memo(function ParameterInput(props: {
debouncedCellParameterUpdate(parameterName, event.target.value);
}}
/>
<ActionIcon
{ !readOnly && <ActionIcon
onClick={() => removeParameter(parameterName)}
disabled={isReadonly}
>
<IconTrash size={16} color={isReadonly ? "grey" : "red"} />
<IconTrash size={16} color={"red"} />
</ActionIcon>
}
</Stack>
</Group>
);
Expand Down Expand Up @@ -149,8 +150,7 @@ export default memo(function ParametersRenderer(props: {
maxHeight?: string | number;
}) {
const { initialValue, onUpdateParameters } = props;
// TODO: saqadri - update this when we have a readonly mode
const { isReadonly } = { isReadonly: false }; //useContext(WorkbookContext);
const { readOnly } = useContext(AIConfigContext);

const [parameters, setParameters] = useState<ParametersArray>(
initialValue && Object.keys(initialValue).length > 0
Expand Down Expand Up @@ -244,7 +244,7 @@ export default memo(function ParametersRenderer(props: {
);
})}
</Stack>
{isReadonly ? null : (
{readOnly ? null : (
<Tooltip label="Add parameter">
<ActionIcon onClick={addParameter} className="addParameterButton">
<IconPlus size={16} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export default memo(function PromptsContainer(props: Props) {
return (
<Stack key={prompt._ui.id}>
<Flex mt="md">
<PromptMenuButton
{!readOnly && <PromptMenuButton
promptId={prompt._ui.id}
onDeletePrompt={() => props.onDeletePrompt(prompt._ui.id)}
/>
/>}
<PromptContainer
prompt={prompt}
getModels={props.getModels}
Expand Down