Repository navigation
[Remove Vuetify from Studio] Add StudioContentNodeIcon to channel details Total resources (#5933) #6385
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?
[Remove Vuetify from Studio] Add StudioContentNodeIcon to channel details Total resources (#5933) #6385
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,25 @@ | ||
| import { themePalette, themeTokens } from 'kolibri-design-system/lib/styles/theme'; | ||
| import { getContentKindColor } from '../colors'; | ||
|
|
||
| describe('getContentKindColor', () => { | ||
| const tokens = themeTokens(); | ||
| const palette = themePalette(); | ||
|
|
||
| it.each([ | ||
| ['video', tokens.watch], | ||
| ['audio', tokens.listen], | ||
| ['document', tokens.read], | ||
| ['slideshow', tokens.read], | ||
| ['exercise', tokens.practice], | ||
| ['html5', tokens.explore], | ||
| ['h5p', tokens.explore], | ||
| ['zim', tokens.explore], | ||
| ['topic', palette.grey.v_400], | ||
| ])('returns the KDS color for %s', (kind, expected) => { | ||
| expect(getContentKindColor(kind)).toBe(expected); | ||
| }); | ||
|
|
||
| it.each(['unsupported', undefined, null, ''])('falls back to grey for %s', kind => { | ||
| expect(getContentKindColor(kind)).toBe(palette.grey.v_400); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { getContentKindIcon } from '../icons'; | ||
|
|
||
| describe('getContentKindIcon', () => { | ||
| it.each([ | ||
| ['topic', 'topic'], | ||
| ['video', 'video'], | ||
| ['audio', 'audio'], | ||
| ['slideshow', 'slideshow'], | ||
| ['exercise', 'exercise'], | ||
| ['document', 'document'], | ||
| ['html5', 'html5'], | ||
| ['h5p', 'html5'], | ||
| ['zim', 'html5'], | ||
| ['unsupported', 'error'], | ||
| ])('maps %s to %s', (kind, icon) => { | ||
| expect(getContentKindIcon(kind)).toBe(icon); | ||
| }); | ||
|
|
||
| it('uses the empty-topic icon only when a topic is empty', () => { | ||
| expect(getContentKindIcon('topic', true)).toBe('emptyTopic'); | ||
| expect(getContentKindIcon('h5p', true)).toBe('html5'); | ||
| }); | ||
|
|
||
| it('throws when a kind has no mapping', () => { | ||
| expect(() => getContentKindIcon('missing')).toThrow('Icon not found for content kind: missing'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { themePalette, themeTokens } from 'kolibri-design-system/lib/styles/theme'; | ||
| import { ContentKindsNames } from 'shared/leUtils/ContentKinds'; | ||
|
|
||
| export function getContentKindColor(kind) { | ||
| const palette = themePalette(); | ||
| const tokens = themeTokens(); | ||
| const colors = { | ||
| [ContentKindsNames.TOPIC]: palette.grey.v_400, | ||
| [ContentKindsNames.VIDEO]: tokens.watch, | ||
| [ContentKindsNames.AUDIO]: tokens.listen, | ||
| [ContentKindsNames.DOCUMENT]: tokens.read, | ||
| [ContentKindsNames.SLIDESHOW]: tokens.read, | ||
| [ContentKindsNames.EXERCISE]: tokens.practice, | ||
| [ContentKindsNames.H5P]: tokens.explore, | ||
| [ContentKindsNames.HTML5]: tokens.explore, | ||
| [ContentKindsNames.ZIM]: tokens.explore, | ||
| }; | ||
| return colors[kind] || palette.grey.v_400; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <template> | ||
|
|
||
| <span | ||
| v-if="icon" | ||
| class="studio-content-node-icon" | ||
| :style="{ backgroundColor: backgroundColor }" | ||
| capture-as-image | ||
| > | ||
| <KIcon | ||
| :icon="icon" | ||
| :color="$themeTokens.textInverted" | ||
| v-bind="$attrs" | ||
| /> | ||
| </span> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| import ContentKinds from 'shared/leUtils/ContentKinds'; | ||
| import { getContentKindIcon } from 'shared/utils/icons'; | ||
| import { getContentKindColor } from 'shared/utils/colors'; | ||
|
|
||
| export default { | ||
| name: 'StudioContentNodeIcon', | ||
| inheritAttrs: false, | ||
| props: { | ||
| kind: { | ||
| type: String, | ||
| validator: value => { | ||
| return value === 'unsupported' || ContentKinds.has(value); | ||
| }, | ||
| default: 'unsupported', | ||
| }, | ||
| isEmpty: { | ||
| type: Boolean, | ||
| default: false, | ||
| }, | ||
| }, | ||
| computed: { | ||
| icon() { | ||
| return getContentKindIcon(this.kind, this.isEmpty); | ||
|
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: Any kind outside the map throws here and breaks the render. The |
||
| }, | ||
| backgroundColor() { | ||
| return getContentKindColor(this.kind); | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style lang="scss" scoped> | ||
|
|
||
| // Icon-only ContentNodeIcon: .v-chip__content is 22px with 0 5px padding, | ||
| // and the Vuetify icon is small (16px). KIcon's svg defaults to 1.125em. | ||
| .studio-content-node-icon { | ||
| box-sizing: border-box; | ||
| display: inline-flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: 22px; | ||
| padding: 0 5px; | ||
| line-height: 1; | ||
| vertical-align: middle; | ||
| border-radius: 4px; | ||
|
|
||
| svg { | ||
| top: 0; | ||
| width: 16px; | ||
| height: 16px; | ||
| } | ||
| } | ||
|
|
||
| </style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { render } from '@testing-library/vue'; | ||
| import Vue from 'vue'; | ||
| import VueRouter from 'vue-router'; | ||
| import KIcon from 'kolibri-design-system/lib/KIcon'; | ||
| import StudioContentNodeIcon from '../StudioContentNodeIcon.vue'; | ||
| import { getContentKindColor } from 'shared/utils/colors'; | ||
| import { getContentKindIcon } from 'shared/utils/icons'; | ||
|
|
||
| const renderComponent = (props = {}) => | ||
| render(StudioContentNodeIcon, { props, routes: new VueRouter() }); | ||
|
|
||
| const renderIcon = icon => render(KIcon, { props: { icon }, routes: new VueRouter() }); | ||
|
|
||
| function iconShape(container) { | ||
| const paths = [...container.querySelectorAll('svg path')].map(path => path.getAttribute('d')); | ||
| expect(paths.length).toBeGreaterThan(0); | ||
| return paths.join('|'); | ||
| } | ||
|
|
||
| describe('StudioContentNodeIcon', () => { | ||
| it.each(['topic', 'video', 'audio', 'exercise', 'document', 'slideshow', 'html5', 'h5p', 'zim'])( | ||
| 'renders the %s icon on its content-kind background', | ||
| kind => { | ||
| const { container } = renderComponent({ kind }); | ||
| const chip = container.querySelector('.studio-content-node-icon'); | ||
|
|
||
| expect(chip).toHaveStyle({ backgroundColor: getContentKindColor(kind) }); | ||
| expect(iconShape(container)).toBe(iconShape(renderIcon(getContentKindIcon(kind)).container)); | ||
| }, | ||
| ); | ||
|
|
||
| it('uses the html5 glyph for h5p', () => { | ||
| const h5p = iconShape(renderComponent({ kind: 'h5p' }).container); | ||
| const html5 = iconShape(renderComponent({ kind: 'html5' }).container); | ||
| const video = iconShape(renderComponent({ kind: 'video' }).container); | ||
|
|
||
| expect(h5p).toBe(html5); | ||
| expect(h5p).not.toBe(video); | ||
| }); | ||
|
|
||
| it('renders the error icon for an unsupported kind', () => { | ||
| const { container } = renderComponent({ kind: 'unsupported' }); | ||
| const chip = container.querySelector('.studio-content-node-icon'); | ||
|
|
||
| expect(chip).toHaveStyle({ backgroundColor: getContentKindColor('unsupported') }); | ||
| expect(iconShape(container)).toBe(iconShape(renderIcon('error').container)); | ||
| }); | ||
|
|
||
| it('does not swallow a missing icon mapping', () => { | ||
| const errorHandler = jest.fn(); | ||
| const previous = Vue.config.errorHandler; | ||
| Vue.config.errorHandler = errorHandler; | ||
|
|
||
| try { | ||
| renderComponent({ kind: 'missing' }); | ||
|
|
||
| expect(errorHandler).toHaveBeenCalled(); | ||
| expect(errorHandler.mock.calls[0][0]).toEqual( | ||
| expect.objectContaining({ message: 'Icon not found for content kind: missing' }), | ||
| ); | ||
| } finally { | ||
| Vue.config.errorHandler = previous; | ||
| } | ||
| }); | ||
|
|
||
| it('is marked to be captured as an image in PDF exports', () => { | ||
| const { container } = renderComponent({ kind: 'video' }); | ||
| expect(container.querySelector('[capture-as-image]')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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.
suggestion: The
unsupportedpseudo-kind sits in a map shared withThumbnail.vueandStudioThumbnail.vue. Only the new component uses it. Suggest keeping theh5pmapping here and handling theunsupportedfallback inStudioContentNodeIcon(see the comment there). If you keep the key, drop line 16: it restates thethrowbelow.