Skip to content

Commit

Permalink
Merge pull request #4079 from systeminit/jobelenus/chainsaw-for-funcs2
Browse files Browse the repository at this point in the history
Func Chainsaw
  • Loading branch information
jobelenus authored Jul 2, 2024
2 parents 79fa447 + e4d31e8 commit edca0f6
Show file tree
Hide file tree
Showing 46 changed files with 1,400 additions and 2,073 deletions.
30 changes: 30 additions & 0 deletions app/web/src/api/sdf/dal/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export type ActionPrototypeId = string;
export type ActionId = string;

export enum ActionState {
Dispatched = "Dispatched",
Failed = "Failed",
OnHold = "OnHold",
Queued = "Queued",
Running = "Running",
}

export enum ActionKind {
Create = "Create",
Destroy = "Destroy",
Refresh = "Refresh",
Manual = "Manual",
Update = "Update",
}

export interface ActionPrototype {
id: ActionPrototypeId;
name: string;
displayName: string;
}

export enum ActionResultState {
Success = "Success",
Failure = "Failure",
Unknown = "Unknown",
}
123 changes: 114 additions & 9 deletions app/web/src/api/sdf/dal/func.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { ActionKind, ActionPrototypeId } from "@/api/sdf/dal/action";
import { InputSocketId, OutputSocketId, SchemaVariantId } from "./schema";
import { ComponentId } from "./component";
import { PropId } from "./prop";

export type FuncArgumentId = string;
export type FuncId = string;
export type AttributePrototypeArgumentId = string;
export type AttributePrototypeId = string;

export enum FuncKind {
Action = "Action",
Expand All @@ -9,7 +16,7 @@ export enum FuncKind {
Intrinsic = "Intrinsic",
Qualification = "Qualification",
SchemaVariantDefinition = "SchemaVariantDefinition",
Unknwon = "Unknown",
Unknown = "Unknown",
}

export enum CustomizableFuncKind {
Expand Down Expand Up @@ -69,19 +76,117 @@ export const isCustomizableFuncKind = (f: FuncKind) =>
f in CUSTOMIZABLE_FUNC_TYPES;

export enum FuncArgumentKind {
Array = "Array",
Boolean = "Boolean",
Integer = "Integer",
Json = "Json",
Object = "Object",
String = "String",
Map = "Map",
Any = "Any",
Array = "array",
Boolean = "boolean",
Integer = "integer",
Json = "json",
Object = "object",
String = "string",
Map = "map",
Any = "any",
}

export interface FuncArgument {
id: string;
name: string;
kind: FuncArgumentKind;
elementKind?: FuncArgumentKind;
created_at: IsoDateString;
updated_at: IsoDateString;
}

export interface FuncSummary {
funcId: FuncId;
kind: FuncKind;
name: string;
displayName: string | null;
description: string | null;
isLocked: boolean;
arguments: FuncArgument[];
bindings: FuncBinding[];
}

export interface FuncCode {
funcId: FuncId;
code: string;
types: string;
}

export interface AttributeArgumentBinding {
funcArgumentId: FuncArgumentId;
attributePrototypeArgumentId: AttributePrototypeArgumentId | null;
propId: PropId | null;
inputSocketId: InputSocketId | null;
}

export enum FuncBindingKind {
Action = "action",
Attribute = "attribute",
Authentication = "authentication",
CodeGeneration = "codeGeneration",
Qualification = "qualification",
}

export interface Action {
bindingKind: FuncBindingKind.Action;
// uneditable
funcId: FuncId | null;
schemaVariantId: SchemaVariantId | null;
actionPrototypeId: ActionPrototypeId | null;
// editable
kind: ActionKind | null;
}

export interface Attribute {
bindingKind: FuncBindingKind.Attribute;
// uneditable
funcId: FuncId | null;
attributePrototypeId: AttributePrototypeId | null;
// needed on create
schemaVariantId: SchemaVariantId | null;
componentId: ComponentId | null;
// editable
propId: PropId | null;
outputSocketId: OutputSocketId | null;
argumentBindings: AttributeArgumentBinding[];
}

export interface Authentication {
bindingKind: FuncBindingKind.Authentication;
funcId: FuncId;
schemaVariantId: SchemaVariantId;
}

export interface CodeGeneration {
bindingKind: FuncBindingKind.CodeGeneration;
funcId: FuncId | null;
schemaVariantId: SchemaVariantId | null;
attributePrototypeId: AttributePrototypeId | null;
componentId: ComponentId | null;
// editable
inputs: LeafInputLocation[];
}

export interface Qualification {
bindingKind: FuncBindingKind.Qualification;
funcId: FuncId | null;
schemaVariantId: SchemaVariantId | null;
attributePrototypeId: AttributePrototypeId | null;
componentId: ComponentId | null;
// editable
inputs: LeafInputLocation[];
}

export type FuncBinding =
| Action
| Attribute
| Authentication
| CodeGeneration
| Qualification;

export type LeafInputLocation =
| "code"
| "deletedAt"
| "domain"
| "resource"
| "secrets";
11 changes: 11 additions & 0 deletions app/web/src/api/sdf/dal/prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ export enum PropKind {
String = "string",
Map = "map",
}

export interface Prop {
id: PropId;
kind: PropKind;
name: string;
path: string;
// this is for output sources
eligibleToReceiveData: boolean;
// this is for input sources
eligibleToSendData: boolean;
}
54 changes: 54 additions & 0 deletions app/web/src/api/sdf/dal/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StandardModel } from "@/api/sdf/dal/standard_model";
import { FuncId } from "@/api/sdf/dal/func";
import { Prop, PropId } from "@/api/sdf/dal/prop";

export enum SchemaKind {
Concept = "concept",
Expand Down Expand Up @@ -30,13 +31,15 @@ export type OutputSocketId = string;
export interface OutputSocket {
id: OutputSocketId;
name: string;
eligibleToReceiveData: boolean;
}

export type InputSocketId = string;

export interface InputSocket {
id: InputSocketId;
name: string;
eligibleToSendData: boolean;
}

export interface SchemaVariant {
Expand All @@ -61,4 +64,55 @@ export interface SchemaVariant {

inputSockets: InputSocket[];
outputSockets: OutputSocket[];
props: Prop[];
}

export const outputSocketsAndPropsFor = (schemaVariant: SchemaVariant) => {
const socketOptions = schemaVariant.outputSockets.map((socket) => ({
label: `Output Socket: ${socket.name}`,
value: `s_${socket.id}`,
}));

// output
const propOptions = schemaVariant.props
.filter((p) => p.eligibleToReceiveData)
.map((p) => ({
label: `Attribute: ${p.path}`,
value: `p_${p.id}`,
}));
return { socketOptions, propOptions };
};

export const inputSocketsAndPropsFor = (schemaVariant: SchemaVariant) => {
const socketOptions = schemaVariant.inputSockets.map((socket) => ({
label: `Input Socket: ${socket.name}`,
value: `s_${socket.id}`,
}));

const propOptions = schemaVariant.props
.filter((p) => p.eligibleToSendData)
.map((p) => ({
label: `Attribute: ${p.path}`,
value: `p_${p.id}`,
}));

return { socketOptions, propOptions };
};

export const findSchemaVariantForPropOrSocketId = (
schemaVariants: SchemaVariant[],
propId: PropId | null | undefined,
outputSocketId: OutputSocketId | null | undefined,
) => {
if (propId && outputSocketId) throw new Error("Either prop or output socket");

return schemaVariants.find((sv) => {
if (propId && sv.props.map((p) => p.id).includes(propId)) return sv;
if (
outputSocketId &&
sv.outputSockets.map((o) => o.id).includes(outputSocketId)
)
return sv;
return undefined;
});
};
4 changes: 1 addition & 3 deletions app/web/src/components/Actions/ActionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,10 @@ import {
} from "@si/vue-lib/design-system";
import clsx from "clsx";
import { FullComponent, useComponentsStore } from "@/store/components.store";
import { ActionKind, ActionState, ActionId } from "@/api/sdf/dal/action";
import {
ActionKind,
ActionState,
ActionView,
useActionsStore,
ActionId,
ActionProposedView,
ActionHistoryView,
} from "@/store/actions.store";
Expand Down
3 changes: 2 additions & 1 deletion app/web/src/components/Actions/ActionWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import * as _ from "lodash-es";
import clsx from "clsx";
import { PropType, computed } from "vue";
import { Icon, themeClasses } from "@si/vue-lib/design-system";
import { ActionPrototypeId, useActionsStore } from "@/store/actions.store";
import { useActionsStore } from "@/store/actions.store";
import { ActionPrototypeId } from "@/api/sdf/dal/action";
import { ComponentId } from "@/api/sdf/dal/component";
import StatusIndicatorIcon from "../StatusIndicatorIcon.vue";
import Toggle from "./Toggle.vue";
Expand Down
2 changes: 1 addition & 1 deletion app/web/src/components/AssetCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const unlock = async () => {
asset.value.schemaVariantId,
);
if (resp.result.success) {
assetStore.setSchemaVariantSelection(resp.result.data?.id);
assetStore.setSchemaVariantSelection(resp.result.data?.id, true);
}
}
};
Expand Down
14 changes: 6 additions & 8 deletions app/web/src/components/AssetDetailsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ import * as _ from "lodash-es";
import { FuncKind, FuncId } from "@/api/sdf/dal/func";
import { useAssetStore } from "@/store/asset.store";
import { useFeatureFlagsStore } from "@/store/feature_flags.store";
import { useFuncStore } from "@/store/func/funcs.store";
import { ComponentType } from "@/api/sdf/dal/schema";
import ColorPicker from "./ColorPicker.vue";
import AssetFuncAttachModal from "./AssetFuncAttachModal.vue";
Expand All @@ -193,7 +192,6 @@ const props = defineProps<{
const ffStore = useFeatureFlagsStore();
const assetStore = useAssetStore();
const funcStore = useFuncStore();
const loadAssetReqStatus = assetStore.getRequestStatus(
"LOAD_SCHEMA_VARIANT",
props.assetId,
Expand Down Expand Up @@ -238,13 +236,13 @@ const updateAsset = async () => {
editingAsset.value &&
!_.isEqual(editingAsset.value, assetStore.selectedSchemaVariant)
) {
const code =
funcStore.funcDetailsById[editingAsset.value.assetFuncId]?.code;
if (code) await assetStore.SAVE_SCHEMA_VARIANT(editingAsset.value);
else
// const code = funcStore.funcCodeById[editingAsset.value.assetFuncId]?.code;
// if (code)
await assetStore.SAVE_SCHEMA_VARIANT(editingAsset.value);
/* else
throw new Error(
`${editingAsset.value.assetFuncId} Func not found on Variant ${editingAsset.value.schemaVariantId}. This should not happen.`,
);
); */
}
};
Expand Down Expand Up @@ -274,7 +272,7 @@ const cloneAsset = async (name: string) => {
);
if (result.result.success) {
cloneAssetModalRef.value?.modal?.close();
await assetStore.setSchemaVariantSelection(result.result.data.id);
await assetStore.setSchemaVariantSelection(result.result.data.id, true);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion app/web/src/components/AssetEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const selectedAsset = computed(() =>
const selectedAssetFuncCode = computed(() => {
const fId = selectedAsset.value?.assetFuncId;
if (!fId) return null;
return funcStore.funcDetailsById[fId]?.code;
return funcStore.funcCodeById[fId]?.code;
});
const isReadOnly = computed(() => {
Expand Down
Loading

0 comments on commit edca0f6

Please sign in to comment.