Deal with already modeled methods in the modeling panel (#2933)

This commit is contained in:
Charis Kyriakou
2023-10-10 14:35:21 +01:00
committed by GitHub
parent 4ee86c15ad
commit f4d74c7d3f
5 changed files with 47 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
import { ResolvableLocationValue } from "../common/bqrs-cli-types";
import { ModeledMethodType } from "./modeled-method";
import { ModeledMethod, ModeledMethodType } from "./modeled-method";
export type Call = {
label: string;
@@ -65,3 +65,15 @@ export function getArgumentsList(methodParameters: string): string[] {
return methodParameters.substring(1, methodParameters.length - 1).split(",");
}
export function canMethodBeModeled(
method: Method,
modeledMethod: ModeledMethod | undefined,
methodIsUnsaved: boolean,
): boolean {
return (
!method.supported ||
(modeledMethod && modeledMethod?.type !== "none") ||
methodIsUnsaved
);
}

View File

@@ -0,0 +1,16 @@
import * as React from "react";
import { Meta, StoryFn } from "@storybook/react";
import { MethodAlreadyModeled as MethodAlreadyModeledComponent } from "../../view/method-modeling/MethodAlreadyModeled";
export default {
title: "Method Modeling/Method Already Modeled",
component: MethodAlreadyModeledComponent,
} as Meta<typeof MethodAlreadyModeledComponent>;
const Template: StoryFn<typeof MethodAlreadyModeledComponent> = () => (
<MethodAlreadyModeledComponent />
);
export const MethodAlreadyModeled = Template.bind({});

View File

@@ -0,0 +1,6 @@
import * as React from "react";
import { ResponsiveContainer } from "../common/ResponsiveContainer";
export const MethodAlreadyModeled = () => {
return <ResponsiveContainer>Method already modeled</ResponsiveContainer>;
};

View File

@@ -2,7 +2,7 @@ import * as React from "react";
import { useEffect, useMemo, useState } from "react";
import { MethodModeling } from "./MethodModeling";
import { getModelingStatus } from "../../model-editor/shared/modeling-status";
import { Method } from "../../model-editor/method";
import { Method, canMethodBeModeled } from "../../model-editor/method";
import { ToMethodModelingMessage } from "../../common/interface-types";
import { assertNever } from "../../common/helpers-pure";
import { ModeledMethod } from "../../model-editor/modeled-method";
@@ -10,6 +10,7 @@ import { vscode } from "../vscode-api";
import { NotInModelingMode } from "./NotInModelingMode";
import { NoMethodSelected } from "./NoMethodSelected";
import { MethodModelingPanelViewState } from "../../model-editor/shared/view-state";
import { MethodAlreadyModeled } from "./MethodAlreadyModeled";
type Props = {
initialViewState?: MethodModelingPanelViewState;
@@ -84,6 +85,10 @@ export function MethodModelingView({ initialViewState }: Props): JSX.Element {
return <NoMethodSelected />;
}
if (!canMethodBeModeled(method, modeledMethod, isMethodModified)) {
return <MethodAlreadyModeled />;
}
const onChange = (modeledMethod: ModeledMethod) => {
vscode.postMessage({
t: "setModeledMethod",

View File

@@ -5,7 +5,7 @@ import {
VSCodeDataGridRow,
} from "@vscode/webview-ui-toolkit/react";
import { MethodRow } from "./MethodRow";
import { Method } from "../../model-editor/method";
import { Method, canMethodBeModeled } from "../../model-editor/method";
import { ModeledMethod } from "../../model-editor/modeled-method";
import { useMemo } from "react";
import { sortMethods } from "../../model-editor/shared/sorting";
@@ -47,10 +47,11 @@ export const ModeledMethodDataGrid = ({
for (const method of sortMethods(methods)) {
const modeledMethod = modeledMethods[method.signature];
const methodIsUnsaved = modifiedSignatures.has(method.signature);
const methodCanBeModeled =
!method.supported ||
(modeledMethod && modeledMethod?.type !== "none") ||
methodIsUnsaved;
const methodCanBeModeled = canMethodBeModeled(
method,
modeledMethod,
methodIsUnsaved,
);
if (methodCanBeModeled || !hideModeledMethods) {
methodsWithModelability.push({ method, methodCanBeModeled });