Skip to content

Commit

Permalink
Merge pull request #4170 from systeminit/nick/eng-2602
Browse files Browse the repository at this point in the history
Add ability to update assets (upgrade modules)
  • Loading branch information
nickgerace authored Jul 17, 2024
2 parents 7f712e1 + da94e40 commit 3e1c032
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
26 changes: 25 additions & 1 deletion app/web/src/components/AssetCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
tooltip="Update"
tooltipPlacement="top"
variant="simple"
@click="updateAsset"
/>

<IconButton
Expand Down Expand Up @@ -87,9 +88,11 @@ import { computed, PropType, ref } from "vue";
import tinycolor from "tinycolor2";
import clsx from "clsx";
import { useTheme, Stack, Icon, ErrorMessage } from "@si/vue-lib/design-system";
import { useRouter } from "vue-router";
import { useAssetStore } from "@/store/asset.store";
import { SchemaVariantId, SchemaVariant } from "@/api/sdf/dal/schema";
import { getAssetIcon } from "@/store/components.store";
import { useModuleStore } from "@/store/module.store";
import IconButton from "./IconButton.vue";
import EditingPill from "./EditingPill.vue";
Expand All @@ -98,6 +101,9 @@ const props = defineProps({
assetId: { type: String as PropType<SchemaVariantId>, required: true },
});
const assetStore = useAssetStore();
const moduleStore = useModuleStore();
const router = useRouter();
const { theme } = useTheme();
const editingVersionDoesNotExist = computed<boolean>(
Expand All @@ -106,7 +112,6 @@ const editingVersionDoesNotExist = computed<boolean>(
undefined,
);
const assetStore = useAssetStore();
const asset = computed(
(): SchemaVariant | undefined =>
assetStore.variantFromListById[props.assetId],
Expand All @@ -116,6 +121,25 @@ const canUpdate = computed(
() => !!assetStore.upgradeableModules[props.assetId],
);
const updateAsset = () => {
const schemaVariantId = asset.value?.schemaVariantId;
if (!schemaVariantId) {
throw new Error("cannot update asset: no asset selected");
}
const module = assetStore.upgradeableModules[schemaVariantId];
if (!module) {
throw new Error("cannot update asset: no upgradeable module for asset");
}
moduleStore.INSTALL_REMOTE_MODULE(module.id);
router.replace({
name: "workspace-lab-assets",
});
return;
};
const primaryColor = tinycolor(asset.value?.color ?? "000000");
// body bg
Expand Down
15 changes: 15 additions & 0 deletions app/web/src/components/AssetListPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
tooltip="Update All"
tooltipPlacement="top"
variant="simple"
@click="updateAllAssets"
/>
</div>
<AssetNameModal
Expand Down Expand Up @@ -146,17 +147,22 @@ import {
TreeNode,
PillCounter,
} from "@si/vue-lib/design-system";
import { useRouter } from "vue-router";
import SiSearch, { Filter } from "@/components/SiSearch.vue";
import { useAssetStore } from "@/store/asset.store";
import { SchemaVariant } from "@/api/sdf/dal/schema";
import { getAssetIcon } from "@/store/components.store";
import { useModuleStore } from "@/store/module.store";
import AssetNameModal from "./AssetNameModal.vue";
import AssetListItem from "./AssetListItem.vue";
import ModuleExportModal from "./modules/ModuleExportModal.vue";
import SidebarSubpanelTitle from "./SidebarSubpanelTitle.vue";
import IconButton from "./IconButton.vue";
const assetStore = useAssetStore();
const moduleStore = useModuleStore();
const router = useRouter();
const { variantList: assetList } = storeToRefs(assetStore);
const createAssetReqStatus = assetStore.getRequestStatus("CREATE_VARIANT");
Expand Down Expand Up @@ -270,6 +276,15 @@ const newAsset = async (newAssetName: string) => {
newAssetModalRef.value?.reset();
};
const updateAllAssets = () => {
Object.values(assetStore.upgradeableModules).forEach((module) => {
moduleStore.INSTALL_REMOTE_MODULE(module.id);
});
router.replace({
name: "workspace-lab-assets",
});
};
const contributeAsset = () => contributeAssetModalRef.value?.open();
const onExport = () => exportSuccessModalRef.value?.open();
Expand Down
4 changes: 2 additions & 2 deletions lib/dal/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ impl Module {
local_hashes.get(&schema_id),
) {
(Some(latest_module), Some(local_hash)) => {
trace!(?latest_module, %local_hash, "comparing hashes");
if &latest_module.latest_hash != local_hash {
debug!(?latest_module, %local_hash, schema_variant.is_locked, "comparing hashes");
if &latest_module.latest_hash != local_hash && schema_variant.is_locked {
synced_modules
.upgradeable
.insert(schema_variant.schema_variant_id, latest_module.to_owned());
Expand Down

0 comments on commit 3e1c032

Please sign in to comment.