Repository navigation
[Remove Vuetify from Studio] Add StudioContentNodeIcon to channel details Total resources (#5933) #6379
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
Closed
vtushar06
wants to merge
2
commits into
learningequality:unstable
from
vtushar06:remove-vuetify-5933
+251
−4
Closed
[Remove Vuetify from Studio] Add StudioContentNodeIcon to channel details Total resources (#5933) #6379
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions
25
contentcuration/contentcuration/frontend/shared/utils/__tests__/colors.spec.js
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,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); | ||
| }); | ||
| }); |
27 changes: 27 additions & 0 deletions
27
contentcuration/contentcuration/frontend/shared/utils/__tests__/icons.spec.js
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,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'); | ||
| }); | ||
| }); |
19 changes: 19 additions & 0 deletions
19
contentcuration/contentcuration/frontend/shared/utils/colors.js
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,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; | ||
| } |
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
76 changes: 76 additions & 0 deletions
76
contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.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,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); | ||
| }, | ||
| 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> | ||
70 changes: 70 additions & 0 deletions
70
...entcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js
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,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(); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.