-
Notifications
You must be signed in to change notification settings - Fork 25
feat: render readme.md file at the top of folder #1708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
packages/web-app-files/src/components/FilesList/ListHeader.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <template> | ||
| <div> | ||
| <div | ||
| v-if="loadReadmeContentTask.isRunning || !loadReadmeContentTask.last" | ||
| class="flex justify-center" | ||
| > | ||
| <oc-spinner size="large" class="my-4" :aria-label="$gettext('Loading README content')" /> | ||
| </div> | ||
| <div | ||
| v-else | ||
| ref="markdownContainerRef" | ||
| class="markdown-container flex min-h-0 [&.collapsed]:max-h-[300px] [&.collapsed]:overflow-hidden" | ||
| :class="{ | ||
| collapsed: markdownCollapsed, | ||
| 'mask-linear-[180deg,black,80%,transparent]': markdownCollapsed && showMarkdownCollapse | ||
| }" | ||
| > | ||
| <text-editor class="w-full" is-read-only :current-content="markdownContent" /> | ||
| </div> | ||
| <div v-if="showMarkdownCollapse && markdownContent" class="markdown-collapse text-center mt-2"> | ||
| <oc-button appearance="raw" no-hover @click="toggleMarkdownCollapsed"> | ||
| <span>{{ toggleMarkdownCollapsedText }}</span> | ||
| </oc-button> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { computed, nextTick, onBeforeUnmount, onMounted, ref, unref, useTemplateRef } from 'vue' | ||
| import { Resource, SpaceResource } from '@opencloud-eu/web-client' | ||
| import { TextEditor, useClientService } from '@opencloud-eu/web-pkg' | ||
| import { useTask } from 'vue-concurrency' | ||
| import { useGettext } from 'vue3-gettext' | ||
| const { space, readmeFile } = defineProps<{ | ||
| space: SpaceResource | ||
| readmeFile: Resource | ||
| }>() | ||
| const { $gettext } = useGettext() | ||
| const clientService = useClientService() | ||
| const { getFileContents } = clientService.webdav | ||
| const markdownContainerRef = useTemplateRef('markdownContainerRef') | ||
| const markdownContent = ref('') | ||
| const markdownCollapsed = ref(true) | ||
| const showMarkdownCollapse = ref(false) | ||
| const toggleMarkdownCollapsedText = computed(() => { | ||
| return unref(markdownCollapsed) ? $gettext('Show more') : $gettext('Show less') | ||
| }) | ||
| const toggleMarkdownCollapsed = () => { | ||
| markdownCollapsed.value = !unref(markdownCollapsed) | ||
| } | ||
| const onMarkdownResize = () => { | ||
| if (!unref(markdownContainerRef)) { | ||
| return | ||
| } | ||
| unref(markdownContainerRef).classList.remove('collapsed') | ||
| const markdownContainerHeight = unref(markdownContainerRef).offsetHeight | ||
| if (markdownContainerHeight < 300) { | ||
| showMarkdownCollapse.value = false | ||
| return | ||
| } | ||
| showMarkdownCollapse.value = true | ||
| if (unref(markdownCollapsed)) { | ||
| unref(markdownContainerRef).classList.add('collapsed') | ||
| } | ||
| } | ||
| const markdownResizeObserver = new ResizeObserver(onMarkdownResize) | ||
| const observeMarkdownContainerResize = () => { | ||
| if (!markdownResizeObserver || !unref(markdownContainerRef)) { | ||
| return | ||
| } | ||
| markdownResizeObserver.unobserve(unref(markdownContainerRef)) | ||
| markdownResizeObserver.observe(unref(markdownContainerRef)) | ||
| } | ||
| const unobserveMarkdownContainerResize = () => { | ||
| if (!markdownResizeObserver || !unref(markdownContainerRef)) { | ||
| return | ||
| } | ||
| markdownResizeObserver.unobserve(unref(markdownContainerRef)) | ||
| } | ||
| const loadReadmeContentTask = useTask(function* (signal) { | ||
| try { | ||
| const { body } = yield getFileContents(space, { fileId: unref(readmeFile).id }, { signal }) | ||
| markdownContent.value = body || '' | ||
| } catch (e) { | ||
| console.error('failed to load README.md content', e) | ||
| } | ||
| }) | ||
| onMounted(async () => { | ||
| await loadReadmeContentTask.perform() | ||
| await nextTick() | ||
| observeMarkdownContainerResize() | ||
| }) | ||
| onBeforeUnmount(() => { | ||
| unobserveMarkdownContainerResize() | ||
| }) | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/web-app-files/tests/unit/components/FilesList/ListHeader.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import ListHeader from '../../../../src/components/FilesList/ListHeader.vue' | ||
| import { defaultComponentMocks, defaultPlugins, shallowMount } from '@opencloud-eu/web-test-helpers' | ||
| import { mock } from 'vitest-mock-extended' | ||
| import { Resource, SpaceResource } from '@opencloud-eu/web-client' | ||
| import { flushPromises } from '@vue/test-utils' | ||
|
|
||
| describe('ListHeader', () => { | ||
| it('renders a spinner when loading', () => { | ||
| const wrapper = getWrapper() | ||
| expect(wrapper.find('oc-spinner-stub').exists()).toBeTruthy() | ||
| }) | ||
| it('renders a markdown container when README content is loaded', async () => { | ||
| const wrapper = getWrapper() | ||
| await flushPromises() | ||
| expect(wrapper.find('.markdown-container').exists()).toBeTruthy() | ||
| }) | ||
| }) | ||
|
|
||
| function getWrapper() { | ||
| const mocks = { | ||
| ...defaultComponentMocks() | ||
| } | ||
|
|
||
| mocks.$clientService.webdav.getFileContents.mockResolvedValueOnce({ | ||
| body: 'Sample README content' | ||
| }) | ||
|
|
||
| return shallowMount(ListHeader, { | ||
| props: { | ||
| space: mock<SpaceResource>(), | ||
| readmeFile: mock<Resource>() | ||
| }, | ||
| global: { | ||
| mocks, | ||
| plugins: [...defaultPlugins()], | ||
| provide: mocks | ||
| } | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 300 appears twice (lines 12 and 63) for the collapse threshold. Extract this into a named constant to improve maintainability and ensure consistency.