Repository navigation
Add organization storage sizes and stop counting organization channels in user storage #6291
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
base: unstable
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { ref, onMounted } from 'vue'; | ||
| import { Organization } from 'shared/data/resources'; | ||
|
|
||
| /** | ||
| * Composable for fetching an organization's channels with their sizes. | ||
| */ | ||
| export function useOrganizationChannels(organizationId) { | ||
| const loading = ref(true); | ||
| const channels = ref([]); | ||
| const size = ref(0); | ||
| const error = ref(false); | ||
|
|
||
| onMounted(() => { | ||
| Organization.fetchChannels(organizationId) | ||
| .then(data => { | ||
| channels.value = data.channels; | ||
| size.value = data.size; | ||
| }) | ||
| .catch(() => { | ||
| error.value = true; | ||
| }) | ||
| .finally(() => { | ||
| loading.value = false; | ||
| }); | ||
| }); | ||
|
|
||
| return { | ||
| loading, | ||
| channels, | ||
| size, | ||
| error, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| <template> | ||
|
|
||
| <div class="organization-channels-tab"> | ||
| <div | ||
| v-if="show('loader', loading, 500)" | ||
| class="loader" | ||
| > | ||
| <KCircularLoader /> | ||
| </div> | ||
|
|
||
| <p | ||
| v-else-if="error" | ||
| :style="{ color: $themeTokens.error }" | ||
| > | ||
| {{ organizationStrings.loadChannelsError$() }} | ||
| </p> | ||
|
|
||
| <p v-else-if="!channels.length"> | ||
| {{ organizationStrings.noChannels$() }} | ||
| </p> | ||
|
|
||
| <template v-else> | ||
| <KTable | ||
| :caption="organizationStrings.channelsTab$()" | ||
| :headers="headers" | ||
| :rows="rows" | ||
| > | ||
| <template #cell="{ content, colIndex }"> | ||
| <KExternalLink | ||
|
rtibblesbot marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Long channel names aren't truncated. In QA, a 275-char name wrapped to 8 lines at 1280px. It wrapped to about 16 lines at 400px. |
||
| v-if="colIndex === 0" | ||
| class="notranslate" | ||
| dir="auto" | ||
| :text="content.name" | ||
| :href="channelUrl(content.id)" | ||
| openInNewTab | ||
| /> | ||
| <KTextTruncator | ||
|
rtibblesbot marked this conversation as resolved.
|
||
| v-else-if="colIndex === 1" | ||
| class="notranslate" | ||
| dir="auto" | ||
| :text="content" | ||
| :maxLines="2" | ||
| /> | ||
| <span | ||
| v-else | ||
| class="size" | ||
| > | ||
| {{ content }} | ||
| </span> | ||
| </template> | ||
| </KTable> | ||
|
|
||
| <p | ||
| class="total-size" | ||
| data-testid="total-size" | ||
| :style="{ color: $themeTokens.annotation }" | ||
| > | ||
| {{ organizationStrings.totalSize$({ size: formatSize(size) }) }} | ||
| </p> | ||
| </template> | ||
| </div> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| import { computed } from 'vue'; | ||
| import useKShow from 'kolibri-design-system/lib/composables/useKShow'; | ||
| import { useOrganizationChannels } from '../../composables/useOrganizationChannels'; | ||
| import { organizationStrings } from 'shared/strings/organizationStrings'; | ||
| import bytesForHumans from 'shared/mixins'; | ||
|
|
||
| export default { | ||
| name: 'OrganizationChannelsTab', | ||
| setup(props) { | ||
| const { show } = useKShow(); | ||
| const { loading, channels, size, error } = useOrganizationChannels(props.organizationId); | ||
|
|
||
| const headers = [ | ||
| { | ||
| label: organizationStrings.channelNameHeader$(), | ||
| dataType: 'undefined', | ||
| columnId: 'name', | ||
| minWidth: '200px', | ||
| }, | ||
| { | ||
| label: organizationStrings.channelDescriptionHeader$(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: At 480px or less, descriptions show only about three words ( |
||
| dataType: 'string', | ||
| columnId: 'description', | ||
| }, | ||
| { | ||
| label: organizationStrings.channelSizeHeader$(), | ||
| dataType: 'number', | ||
| columnId: 'size', | ||
| minWidth: '100px', | ||
| }, | ||
| ]; | ||
|
|
||
| const rows = computed(() => | ||
| channels.value.map(channel => [channel, channel.description, bytesForHumans(channel.size)]), | ||
| ); | ||
|
|
||
| function channelUrl(channelId) { | ||
| return window.Urls.channel(channelId); | ||
| } | ||
|
|
||
| return { | ||
| show, | ||
| loading, | ||
| channels, | ||
| size, | ||
| error, | ||
| headers, | ||
| rows, | ||
| channelUrl, | ||
| formatSize: bytesForHumans, | ||
| organizationStrings, | ||
| }; | ||
| }, | ||
| props: { | ||
| organizationId: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style lang="scss" scoped> | ||
|
|
||
| .loader { | ||
| margin: 48px auto; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .size { | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .total-size { | ||
| margin-top: 8px; | ||
| text-align: right; | ||
| } | ||
|
|
||
| </style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { render, screen, within } from '@testing-library/vue'; | ||
| import { createLocalVue } from '@vue/test-utils'; | ||
| import VueRouter from 'vue-router'; | ||
| import OrganizationChannelsTab from '../OrganizationChannelsTab.vue'; | ||
| import { Organization } from 'shared/data/resources'; | ||
| import { organizationStrings } from 'shared/strings/organizationStrings'; | ||
|
|
||
| const localVue = createLocalVue(); | ||
| localVue.use(VueRouter); | ||
|
|
||
| const ONE_MB = 1000 * 1000; | ||
|
|
||
| const renderTab = () => | ||
| render(OrganizationChannelsTab, { | ||
| localVue, | ||
| router: new VueRouter(), | ||
| props: { organizationId: 'org-1' }, | ||
| }); | ||
|
|
||
| describe('OrganizationChannelsTab', () => { | ||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it("lists the organization's channels with their sizes and the total size", async () => { | ||
| jest.spyOn(Organization, 'fetchChannels').mockResolvedValue({ | ||
| channels: [ | ||
| { id: 'channel-1', name: 'Alpha', description: 'First channel', size: 10 * ONE_MB }, | ||
| { id: 'channel-2', name: 'Beta', description: 'Second channel', size: 560 * ONE_MB }, | ||
| ], | ||
| size: 570 * ONE_MB, | ||
| }); | ||
|
|
||
| renderTab(); | ||
|
|
||
| const table = await screen.findByRole('grid', { name: organizationStrings.channelsTab$() }); | ||
| const rows = within(table).getAllByRole('row'); | ||
| expect(within(rows[1]).getByRole('link', { name: /Alpha/ })).toBeInTheDocument(); | ||
| expect(within(rows[1]).getByText('First channel')).toBeInTheDocument(); | ||
| expect(within(rows[1]).getByText('10 MB')).toBeInTheDocument(); | ||
| expect(within(rows[2]).getByText('560 MB')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('total-size')).toHaveTextContent( | ||
| organizationStrings.totalSize$({ size: '570 MB' }), | ||
| ); | ||
| expect(Organization.fetchChannels).toHaveBeenCalledWith('org-1'); | ||
| }); | ||
|
|
||
| it('opens a channel in a new tab', async () => { | ||
| const urls = window.Urls; | ||
| window.Urls = { channel: channelId => `/channels/${channelId}/` }; | ||
| jest.spyOn(Organization, 'fetchChannels').mockResolvedValue({ | ||
| channels: [{ id: 'channel-1', name: 'Alpha', description: '', size: 0 }], | ||
| size: 0, | ||
| }); | ||
|
|
||
| try { | ||
| renderTab(); | ||
|
|
||
| const link = await screen.findByRole('link', { name: /Alpha/ }); | ||
| expect(link).toHaveAttribute('href', '/channels/channel-1/'); | ||
| expect(link).toHaveAttribute('target', '_blank'); | ||
| } finally { | ||
| window.Urls = urls; | ||
| } | ||
| }); | ||
|
|
||
| it('shows a message when the organization has no channels', async () => { | ||
| jest.spyOn(Organization, 'fetchChannels').mockResolvedValue({ channels: [], size: 0 }); | ||
|
|
||
| renderTab(); | ||
|
|
||
| expect(await screen.findByText(organizationStrings.noChannels$())).toBeInTheDocument(); | ||
| expect(screen.queryByRole('grid')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows an error instead of an empty list when the channels fail to load', async () => { | ||
| jest.spyOn(Organization, 'fetchChannels').mockRejectedValue(new Error('Not found')); | ||
|
|
||
| renderTab(); | ||
|
|
||
| expect(await screen.findByText(organizationStrings.loadChannelsError$())).toBeInTheDocument(); | ||
| expect(screen.queryByText(organizationStrings.noChannels$())).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.