Skip to content

Commit d9556b9

Browse files
committed
up
1 parent 8af76e4 commit d9556b9

File tree

5 files changed

+49
-16
lines changed

5 files changed

+49
-16
lines changed

src/app/src/components/panel/base/PanelBaseBodyTree.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { documentTree, mediaTree, context } = useStudio()
77
88
const treeApi = computed(() => context.feature.value === StudioFeature.Content ? documentTree : mediaTree)
99
10-
defineProps({
10+
const props = defineProps({
1111
type: {
1212
type: String as PropType<'directory' | 'file'>,
1313
required: true,
@@ -16,11 +16,17 @@ defineProps({
1616
type: Array as PropType<TreeItem[]>,
1717
default: () => [],
1818
},
19-
showCreationForm: {
19+
showForm: {
2020
type: Boolean,
2121
default: false,
2222
},
2323
})
24+
25+
const filteredTree = computed(() => {
26+
if (!context.actionInProgress.value?.item) return props.tree
27+
28+
return props.tree.filter(item => item.id !== context.actionInProgress.value!.item?.id)
29+
})
2430
</script>
2531

2632
<template>
@@ -29,14 +35,15 @@ defineProps({
2935
ref="container"
3036
class="grid grid-cols-1 @sm:grid-cols-2 @xl:grid-cols-3 @4xl:grid-cols-4 @7xl:grid-cols-6 gap-4"
3137
>
32-
<li v-if="showCreationForm">
38+
<li v-if="showForm">
3339
<ItemCardForm
3440
:parent-item="treeApi.currentItem.value"
35-
:action-id="context.actionInProgress.value!"
41+
:action-id="context.actionInProgress.value!.id"
42+
:renamed-item="context.actionInProgress.value!.item"
3643
/>
3744
</li>
3845
<li
39-
v-for="(item, index) in tree"
46+
v-for="(item, index) in filteredTree"
4047
:key="`${item.id}-${index}`"
4148
>
4249
<ItemCard

src/app/src/components/shared/item/ItemCardForm.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ const props = defineProps({
2121
type: Object as PropType<TreeItem>,
2222
required: true,
2323
},
24+
renamedItem: {
25+
type: Object as PropType<TreeItem>,
26+
default: null,
27+
},
2428
})
2529
30+
const originalName = computed(() => props.renamedItem?.name || '')
31+
const originalExtension = computed(() => props.renamedItem?.id.split('.').pop() as ContentFileExtension || ContentFileExtension.Markdown)
32+
2633
const schema = z.object({
2734
name: z.string()
2835
.min(1, 'Name cannot be empty')
@@ -33,8 +40,8 @@ const schema = z.object({
3340
3441
type Schema = z.output<typeof schema>
3542
const state = reactive<Schema>({
36-
name: '',
37-
extension: ContentFileExtension.Markdown,
43+
name: originalName.value,
44+
extension: originalExtension.value,
3845
})
3946
4047
const action = computed<StudioAction>(() => {

src/app/src/composables/useContext.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { createSharedComposable } from '@vueuse/core'
22
import { computed, ref } from 'vue'
33
import type { useUi } from './useUi'
4-
import { type UploadMediaParams, type CreateFileParams, type StudioHost, type StudioAction, type TreeItem, StudioItemActionId, type ActionHandlerParams, StudioFeature } from '../types'
4+
import {
5+
type StudioActionInProgress,
6+
type UploadMediaParams,
7+
type CreateFileParams,
8+
type StudioHost,
9+
type StudioAction,
10+
type ActionHandlerParams,
11+
StudioItemActionId,
12+
StudioFeature,
13+
} from '../types'
514
import { oneStepActions, STUDIO_ITEM_ACTION_DEFINITIONS, twoStepActions } from '../utils/context'
615
import type { useDraftDocuments } from './useDraftDocuments'
716
import { useModal } from './useModal'
@@ -18,7 +27,7 @@ export const useContext = createSharedComposable((
1827
) => {
1928
const modal = useModal()
2029

21-
const actionInProgress = ref<StudioItemActionId | null>(null)
30+
const actionInProgress = ref<StudioActionInProgress | null>(null)
2231
const currentFeature = computed<keyof typeof ui.panels | null>(() =>
2332
Object.keys(ui.panels).find(key => ui.panels[key as keyof typeof ui.panels]) as keyof typeof ui.panels,
2433
)
@@ -28,7 +37,7 @@ export const useContext = createSharedComposable((
2837
return STUDIO_ITEM_ACTION_DEFINITIONS.map(action => ({
2938
...action,
3039
handler: async (args) => {
31-
if (actionInProgress.value === action.id) {
40+
if (actionInProgress.value?.id === action.id) {
3241
// Two steps actions need to be already in progress to be executed
3342
if (twoStepActions.includes(action.id)) {
3443
await itemActionHandler[action.id](args as never)
@@ -41,7 +50,7 @@ export const useContext = createSharedComposable((
4150
}
4251
}
4352

44-
actionInProgress.value = action.id
53+
actionInProgress.value = { id: action.id, item: args.item }
4554

4655
// One step actions can be executed immediately
4756
if (oneStepActions.includes(action.id)) {
@@ -71,8 +80,8 @@ export const useContext = createSharedComposable((
7180
await draft.value.revert(id)
7281
})
7382
},
74-
[StudioItemActionId.RenameItem]: async ({ path, file }: { path: string, file: TreeItem }) => {
75-
alert(`rename file ${path} ${file.name}`)
83+
[StudioItemActionId.RenameItem]: async ({ id, newNameWithExtension }: { id: string, newNameWithExtension: string }) => {
84+
alert(`rename file ${id} ${newNameWithExtension}`)
7685
},
7786
[StudioItemActionId.DeleteItem]: async (id: string) => {
7887
modal.openConfirmActionModal(id, StudioItemActionId.DeleteItem, async () => {

src/app/src/types/context.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export enum StudioItemActionId {
1515
DuplicateItem = 'duplicate-item',
1616
}
1717

18+
export interface StudioActionInProgress {
19+
id: StudioItemActionId
20+
item?: TreeItem
21+
}
22+
1823
export interface StudioAction {
1924
id: StudioItemActionId
2025
label: string
@@ -30,8 +35,8 @@ export interface CreateFileParams {
3035
}
3136

3237
export interface RenameFileParams {
33-
path: string
34-
file: TreeItem
38+
id: string
39+
newNameWithExtension: string
3540
}
3641

3742
export interface UploadMediaParams {

src/app/src/utils/context.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ export function computeActionParams(action: StudioItemActionId, { item }: { item
9696
case StudioItemActionId.DeleteItem:
9797
case StudioItemActionId.DuplicateItem:
9898
return item.id
99+
case StudioItemActionId.RenameItem:
100+
return {
101+
id: item.id,
102+
item
103+
}
99104
default:
100-
return {}
105+
return item.id
101106
}
102107
}

0 commit comments

Comments
 (0)