-
Notifications
You must be signed in to change notification settings - Fork 66
Creating an IndexStore for Quick Navigation
#889
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
Changes from all commits
d2bd931
6fce256
642f741
c9899cb
00131f7
73db182
328591c
0addf8a
235fd8e
caeb397
cf0ba56
5e2815a
6491aa9
9942643
9f7fc45
801593a
a1fd338
1b8ee36
835ad6b
cbb7f50
3dfcb67
6fa85b6
0e92cc1
b8cec41
24519c6
8aa6337
5026c9e
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,49 @@ | ||
| /** | ||
| * This source file is part of the Swift.org open source project | ||
| * | ||
| * Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
| * Licensed under Apache License v2.0 with Runtime Library Exception | ||
| * | ||
| * See https://swift.org/LICENSE.txt for license information | ||
| * See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
| */ | ||
| import { fetchData } from 'docc-render/utils/data'; | ||
| import { pathJoin } from 'docc-render/utils/assets'; | ||
| import { flattenNavigationIndex, extractTechnologyProps } from 'docc-render/utils/navigatorData'; | ||
| import IndexStore from 'docc-render/stores/IndexStore'; | ||
|
|
||
| export default { | ||
| computed: { | ||
| indexDataPath() { | ||
| const slug = this.$route?.params?.locale || ''; | ||
| return pathJoin(['/index/', slug, 'index.json']); | ||
| }, | ||
| }, | ||
| methods: { | ||
| async fetchIndexPathsData() { | ||
| return fetchData(this.indexDataPath); | ||
| }, | ||
| async fetchIndexData() { | ||
| try { | ||
| IndexStore.reset(); | ||
| const { | ||
| includedArchiveIdentifiers = [], | ||
| interfaceLanguages, | ||
| references = {}, | ||
| } = await this.fetchIndexPathsData(); | ||
| IndexStore.setFlatChildren(flattenNavigationIndex(interfaceLanguages)); | ||
| IndexStore.setTechnologyProps(extractTechnologyProps(interfaceLanguages)); | ||
| IndexStore.setReferences(references); | ||
| IndexStore.setIncludedArchiveIdentifiers(includedArchiveIdentifiers); | ||
| } catch (e) { | ||
| IndexStore.setErrorFetching(true); | ||
| } | ||
| }, | ||
| }, | ||
| watch: { | ||
| indexDataPath: { | ||
| handler: 'fetchIndexData', | ||
| immediate: true, | ||
| }, | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * This source file is part of the Swift.org open source project | ||
| * | ||
| * Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
| * Licensed under Apache License v2.0 with Runtime Library Exception | ||
| * | ||
| * See https://swift.org/LICENSE.txt for license information | ||
| * See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
| */ | ||
|
|
||
| export default { | ||
| state: { | ||
| flatChildren: {}, | ||
| references: {}, | ||
| apiChanges: null, | ||
| includedArchiveIdentifiers: [], | ||
| errorFetching: false, | ||
| technologyProps: {}, | ||
| }, | ||
| reset() { | ||
| this.state.flatChildren = {}; | ||
| this.state.references = {}; | ||
| this.state.apiChanges = null; | ||
| this.state.includedArchiveIdentifiers = []; | ||
| this.state.errorFetching = false; | ||
| this.state.technologyProps = {}; | ||
| }, | ||
| setFlatChildren(children) { | ||
| this.state.flatChildren = children; | ||
| }, | ||
| setReferences(references) { | ||
| this.state.references = references; | ||
| }, | ||
| setApiChanges(diff) { | ||
| this.state.apiChanges = diff; | ||
| }, | ||
| setIncludedArchiveIdentifiers(includedArchiveIdentifiers) { | ||
| this.state.includedArchiveIdentifiers = includedArchiveIdentifiers; | ||
| }, | ||
| setErrorFetching(state) { | ||
| this.state.errorFetching = state; | ||
| }, | ||
| setTechnologyProps(technology) { | ||
| this.state.technologyProps = technology; | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,20 @@ jest.mock('docc-render/utils/scroll-lock'); | |
| jest.mock('docc-render/utils/storage'); | ||
| jest.mock('docc-render/utils/theme-settings'); | ||
|
|
||
| const swiftChildren = [ | ||
| 'swiftChildrenMock', | ||
| ]; | ||
| const objcChildren = [ | ||
| 'objcChildrenMock', | ||
| ]; | ||
| jest.mock('docc-render/stores/IndexStore', () => ({ | ||
| state: { | ||
| flatChildren: { | ||
| swift: swiftChildren, | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| storage.get.mockImplementation((key, value) => value); | ||
|
|
||
| const TechnologyWithChildren = { | ||
|
|
@@ -273,6 +287,64 @@ describe('DocumentationLayout', () => { | |
| expect(quickNavigationModalComponent.exists()).toBe(false); | ||
| }); | ||
|
|
||
| it('QuickNavigation renders Swift items', async () => { | ||
| getSetting.mockReturnValueOnce(true); | ||
| wrapper = createWrapper({ | ||
| stubs: { | ||
| ...stubs, | ||
| Nav: DocumentationNav, | ||
| NavBase, | ||
| }, | ||
| }); | ||
| wrapper.setProps({ | ||
| enableNavigator: true, | ||
| }); | ||
| await wrapper.vm.$nextTick(); | ||
| expect(wrapper.find(QuickNavigationModal).props('children')).toEqual(swiftChildren); | ||
| }); | ||
|
|
||
| it('QuickNavigation falls back to swift items, if no objc items', async () => { | ||
|
Member
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. Why do we fallback to swift items? just curious about this
Contributor
Author
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. See this issue, DocC defaults to swift when the archive is article only. If this issue is addressed, we can make the update here as well. |
||
| getSetting.mockReturnValueOnce(true); | ||
| wrapper = createWrapper({ | ||
| stubs: { | ||
| ...stubs, | ||
| Nav: DocumentationNav, | ||
| NavBase, | ||
| }, | ||
| }); | ||
| wrapper.setProps({ | ||
| enableNavigator: true, | ||
| interfaceLanguage: Language.objectiveC.key.url, | ||
| }); | ||
| await wrapper.vm.$nextTick(); | ||
| expect(wrapper.find(QuickNavigationModal).props('children')).toEqual(swiftChildren); | ||
| }); | ||
|
|
||
| it('QuickNavigation renders objc items', async () => { | ||
| getSetting.mockReturnValueOnce(true); | ||
| wrapper = createWrapper({ | ||
| stubs: { | ||
| ...stubs, | ||
| Nav: DocumentationNav, | ||
| NavBase, | ||
| }, | ||
| }); | ||
| wrapper.setProps({ | ||
| enableNavigator: true, | ||
| interfaceLanguage: Language.objectiveC.key.url, | ||
| }); | ||
| wrapper.setData({ | ||
| indexState: { | ||
| flatChildren: { | ||
| [Language.swift.key.url]: swiftChildren, | ||
| [Language.objectiveC.key.url]: objcChildren, | ||
| }, | ||
| }, | ||
| }); | ||
| await wrapper.vm.$nextTick(); | ||
| expect(wrapper.find(QuickNavigationModal).props('children')).toEqual(objcChildren); | ||
| }); | ||
|
|
||
| describe('if breakpoint is small', () => { | ||
| beforeEach(() => { | ||
| wrapper = createWrapper({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.