Skip to content

Commit

Permalink
Merge pull request #4117 from systeminit/jobelenus/last-chainsaw
Browse files Browse the repository at this point in the history
Last Chainsaw Cleanup
  • Loading branch information
vbustamante authored Jul 9, 2024
2 parents b755d0c + 26c8779 commit 0793887
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 81 deletions.
2 changes: 1 addition & 1 deletion app/web/src/api/sdf/dal/func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ export interface FuncSummary {
isLocked: boolean;
arguments: FuncArgument[];
bindings: FuncBinding[];
types?: string | null;
}

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

export interface AttributeArgumentBinding {
Expand Down
6 changes: 4 additions & 2 deletions app/web/src/components/AssetActionsDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ const bindings = computed(() => {
const actions = funcStore.actionBindings[funcId];
if (actions && actions.length > 0) {
actions.forEach((b) => {
const a = b as BindingWithDisplayName;
const a = _.cloneDeep(b) as BindingWithDisplayName;
a.displayName = summary?.displayName || "<Unknown>";
_bindings.push(a);
});
}
});
return _bindings;
return _bindings.sort((_a, _b) =>
_a.displayName.localeCompare(_b.displayName),
);
});
watch(
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 @@ -141,7 +141,7 @@ const unlock = async () => {
asset.value.schemaVariantId,
);
if (resp.result.success) {
assetStore.setSchemaVariantSelection(resp.result.data?.id);
assetStore.setSchemaVariantSelection(resp.result.data?.schemaVariantId);
}
}
};
Expand Down
11 changes: 9 additions & 2 deletions app/web/src/components/AssetFuncAttachModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@
<RequestStatusMessage :requestStatus="loadFuncDetailsReq.value" />
</div>
<CodeEditor
v-if="loadFuncDetailsReq && !loadFuncDetailsReq?.value.isPending"
:id="() => `display-${selectedExistingFuncId}`"
v-if="
loadFuncDetailsReq &&
loadFuncDetailsReq?.value.isSuccess &&
selectedFuncCode
"
:id="codeEditorId"
v-model="selectedFuncCode"
:recordId="selectedExistingFuncId"
disabled
Expand Down Expand Up @@ -201,6 +205,7 @@ const name = ref("");
const funcKind = ref(FuncKind.Action);
const selectedExistingFuncId = ref<FuncId | undefined>();
const codeEditorId = computed(() => `func-${selectedExistingFuncId.value}`);
const selectedExistingFuncSummary = computed(() => {
if (selectedExistingFuncId.value)
return funcStore.funcsById[selectedExistingFuncId.value];
Expand Down Expand Up @@ -418,6 +423,8 @@ const attachExistingFunc = async () => {
bindings,
);
if (response.result.success && props.schemaVariantId) {
const funcId = response.result.data.bindings.pop()?.funcId;
if (funcId) assetStore.setFuncSelection(funcId);
close();
}
}
Expand Down
9 changes: 5 additions & 4 deletions app/web/src/components/AssetFuncListPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ interface VariantsWithFunctionSummary extends SchemaVariantListEntry {
const variantSummaries = computed(() => {
if (!props.schemaVariantId) return null;
const variant = assetStore.variantFromListById[
props.schemaVariantId
] as VariantsWithFunctionSummary;
const variant = _.cloneDeep(
assetStore.variantFromListById[props.schemaVariantId],
) as VariantsWithFunctionSummary;
if (!variant) return null;
variant.funcSummaries = [];
variant.funcIds.forEach((fId) => {
// seeing duplicates, can prevent that from this end
[...new Set(variant.funcIds)].forEach((fId) => {
const func = funcStore.funcsById[fId];
if (func) variant.funcSummaries.push(func);
});
Expand Down
10 changes: 8 additions & 2 deletions app/web/src/components/AssetListPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
</template>
<template v-if="assetStore.variantList.length > 0">
<TreeNode
v-for="category in Object.keys(categorizedAssets)"
v-for="category in Object.keys(categorizedAssets).sort((a, b) =>
a.localeCompare(b),
)"
:key="category"
:color="categoryColor(category)"
:label="category"
Expand All @@ -87,7 +89,11 @@
/>
</template>
<AssetListItem
v-for="asset in categorizedAssets[category]"
v-for="asset in categorizedAssets[category]?.sort((a, b) =>
(a.displayName || a.schemaName)?.localeCompare(
b.displayName || b.schemaName,
),
)"
:key="asset.schemaVariantId"
:a="asset"
:c="categorizedAssets[category]"
Expand Down
2 changes: 1 addition & 1 deletion app/web/src/components/CodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ const mountEditor = async () => {
watch(
[
() => props.id,
() => props.typescript,
() => props.disabled,
() => props.json,
Expand All @@ -451,7 +452,6 @@ watch(
editorMount,
],
mountEditor,
{ once: true },
);
function onVimExit() {
Expand Down
25 changes: 13 additions & 12 deletions app/web/src/components/FuncEditor/FuncDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@
<script lang="ts" setup>
import * as _ from "lodash-es";
import { computed, ref, watch } from "vue";
import { storeToRefs } from "pinia";
import {
ErrorMessage,
Stack,
Expand Down Expand Up @@ -294,20 +293,19 @@ type DetachType =
const detachRef = ref<DetachType>();
const funcId = computed(() => props.funcId);
const updateFuncReqStatus = funcStore.getRequestStatus("UPDATE_FUNC", funcId);
const { selectedFuncSummary } = storeToRefs(funcStore);
watch(
() => funcStore.selectedFuncSummary,
() => {
resetEditingFunc();
},
);
const editingFunc = ref(_.cloneDeep(selectedFuncSummary.value));
const editingFunc = ref(_.cloneDeep(funcStore.selectedFuncSummary));
function resetEditingFunc() {
editingFunc.value = _.cloneDeep(selectedFuncSummary.value);
editingFunc.value = _.cloneDeep(funcStore.selectedFuncSummary);
}
// when the func details finish loading, we copy into our local draft
watch([updateFuncReqStatus], () => {
resetEditingFunc();
});
watch(
() => funcStore.selectedFuncId,
() => {
Expand All @@ -321,8 +319,11 @@ watch(
{ immediate: true },
);
const updateFunc = () => {
if (editingFunc.value) funcStore.UPDATE_FUNC(editingFunc.value);
const updateFunc = async () => {
if (editingFunc.value) {
await funcStore.UPDATE_FUNC(editingFunc.value);
resetEditingFunc();
}
};
const unlocking = ref(false);
Expand Down
14 changes: 5 additions & 9 deletions app/web/src/components/FuncEditor/FuncEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ScrollArea
v-else-if="
selectedAsset &&
selectedFuncCode &&
loadFuncDetailsReq.isSuccess &&
typeof editingFunc === 'string'
"
Expand All @@ -20,16 +21,11 @@
</template>

<CodeEditor
:id="
changeSetsStore.headChangeSetId !==
changeSetsStore.selectedChangeSetId && selectedFuncCode
? `func-${selectedFuncCode.funcId}`
: undefined
"
:id="`func-${selectedFuncCode.funcId}`"
v-model="editingFunc"
:disabled="selectedFuncSummary?.isLocked"
:recordId="selectedFuncSummary?.funcId || ''"
:typescript="selectedFuncCode?.types"
:typescript="selectedFuncSummary?.types || ''"
@change="updateFuncCode"
@close="emit('close')"
/>
Expand All @@ -43,7 +39,6 @@

<script lang="ts" setup>
import { PropType, computed, ref, watch } from "vue";
import { storeToRefs } from "pinia";
import {
LoadingMessage,
ErrorMessage,
Expand All @@ -65,7 +60,8 @@ const props = defineProps({
});
const funcStore = useFuncStore();
const { selectedFuncSummary, selectedFuncCode } = storeToRefs(funcStore);
const selectedFuncSummary = computed(() => funcStore.selectedFuncSummary);
const selectedFuncCode = computed(() => funcStore.selectedFuncCode);
const editingFunc = ref<string>(selectedFuncCode.value?.code ?? "");
Expand Down
4 changes: 3 additions & 1 deletion app/web/src/components/toasts/FiveHundredError.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div>
<div class="flex flex-row gap-sm items-center dark:bg-black bg-white">
<div
class="flex flex-row gap-sm items-center dark:bg-black bg-white max-h-[75vh] overflow-y-auto"
>
<Icon
name="alert-circle"
class="text-warning-600 content-center ml-md"
Expand Down
19 changes: 17 additions & 2 deletions app/web/src/store/asset.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,24 @@ export const useAssetStore = () => {

this.detachmentWarnings = [];

return new ApiRequest<{ id: string }>({
return new ApiRequest<SchemaVariant>({
method: "post",
url: "/variant/create_unlocked_copy",
keyRequestStatusBy: id,
params: {
...visibility,
id,
},
onSuccess: (variant) => {
const v = variant as SchemaVariantListEntry;
v.canContribute = false;
v.canUpdate = false;
const savedAssetIdx = this.variantList.findIndex(
(a) => a.schemaVariantId === variant.schemaVariantId,
);
if (savedAssetIdx === -1) this.variantList.push(v);
else this.variantList.splice(savedAssetIdx, 1, v);
},
});
},
},
Expand Down Expand Up @@ -492,7 +502,12 @@ export const useAssetStore = () => {
const v = variant as SchemaVariantListEntry;
v.canContribute = false;
v.canUpdate = false;
this.variantList.push(v);

const savedAssetIdx = this.variantList.findIndex(
(a) => a.schemaVariantId === variant.schemaVariantId,
);
if (savedAssetIdx === -1) this.variantList.push(v);
else this.variantList.splice(savedAssetIdx, 1, v);
},
},
{
Expand Down
13 changes: 9 additions & 4 deletions app/web/src/store/components.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,17 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
if (!variants) return null;
return {
displayName: category,
schemaVariants: variants.filter(
(v) => v.canCreateNewComponents,
),
schemaVariants: variants
.filter((v) => v.canCreateNewComponents)
.sort((a, b) =>
(a.displayName || a.schemaName)?.localeCompare(
b.displayName || b.schemaName,
),
),
};
})
.filter(nonNullable);
.filter(nonNullable)
.sort((a, b) => a.displayName.localeCompare(b.displayName));
},

changeStatsSummary(): Record<ChangeStatus | "total", number> {
Expand Down
3 changes: 1 addition & 2 deletions app/web/src/store/func/funcs.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ export const useFuncStore = () => {
if (changeSetsStore.headSelected)
changeSetsStore.creatingChangeSet = true;

// TODO: jobelenus, handle this WsEvent (no funcId on it?!)
return new ApiRequest<null>({
return new ApiRequest<{ bindings: FuncBinding[] }>({
method: "post",
url: `${API_PREFIX}/${funcId}/bindings/create`,
params: {
Expand Down
29 changes: 16 additions & 13 deletions lib/dal/src/func/binding/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ impl ActionBinding {
action_kind: ActionKind,
schema_variant_id: SchemaVariantId,
) -> FuncBindingResult<Vec<FuncBinding>> {
if action_kind != ActionKind::Manual {
// don't add binding if parent is locked
SchemaVariant::error_if_locked(ctx, schema_variant_id).await?;
// don't add binding if parent is locked
SchemaVariant::error_if_locked(ctx, schema_variant_id).await?;

// If not manual, don't create duplicate prototypes for variant AND actionKind
if action_kind != ActionKind::Manual {
let existing_action_prototypes_for_variant =
ActionPrototype::for_variant(ctx, schema_variant_id).await?;
if existing_action_prototypes_for_variant
Expand All @@ -101,17 +102,19 @@ impl ActionBinding {
schema_variant_id,
));
}
let func = Func::get_by_id_or_error(ctx, func_id).await?;
ActionPrototype::new(
ctx,
action_kind,
func.name.to_owned(),
func.description.to_owned(),
schema_variant_id,
func.id,
)
.await?;
}

let func = Func::get_by_id_or_error(ctx, func_id).await?;
ActionPrototype::new(
ctx,
action_kind,
func.name.to_owned(),
func.description.to_owned(),
schema_variant_id,
func.id,
)
.await?;

FuncBinding::for_func_id(ctx, func_id).await
}

Expand Down
1 change: 0 additions & 1 deletion lib/dal/src/schema/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ impl WsEvent {
schema_variant_id: SchemaVariant,
) -> WsEventResult<Self> {
let payload = schema_variant_id.into_frontend_type(ctx, schema_id).await?;
dbg!(&payload);
WsEvent::new(ctx, WsPayload::SchemaVariantUpdated(payload)).await
}
pub async fn schema_variant_deleted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,15 @@ pub async fn create_binding(
"func_kind": func.kind.clone(),
}),
);
let binding = Func::get_by_id_or_error(&ctx, func_id)
.await?
.into_frontend_type(&ctx)
.await?
.bindings;

let func_summary = Func::get_by_id_or_error(&ctx, func_id)
.await?
.into_frontend_type(&ctx)
.await?;
WsEvent::func_updated(&ctx, func_summary.clone())

let bindings = func_summary.clone().bindings;

WsEvent::func_updated(&ctx, func_summary)
.await?
.publish_on_commit(&ctx)
.await?;
Expand All @@ -306,5 +304,5 @@ pub async fn create_binding(
response = response.header("force_change_set_id", force_change_set_id.to_string());
}

Ok(response.body(serde_json::to_string(&binding)?)?)
Ok(response.body(serde_json::to_string(&bindings)?)?)
}
Loading

0 comments on commit 0793887

Please sign in to comment.