-
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
Merged
hqhhuang
merged 27 commits into
swiftlang:navigator-index-store
from
hqhhuang:index-store
Sep 16, 2024
Merged
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d2bd931
Create `IndexStore`
hqhhuang 6fce256
fetch index data in `view/DocumentationTopic`
hqhhuang 642f741
Get Quick Nav data from `IndexStore`
hqhhuang c9899cb
update items in `indexStore`
hqhhuang 00131f7
add `technologyUrl` prop
hqhhuang 73db182
fix issues with accessing null items
hqhhuang 328591c
move data fetching logic to `indexProvider.js`
hqhhuang 0addf8a
add `errorFetching` to store
hqhhuang 235fd8e
simplify index data path computation logic
hqhhuang caeb397
add technology prop to store
hqhhuang cf0ba56
add tests for `indexProvider`
hqhhuang 5e2815a
Merge branch 'main' into index-store
hqhhuang 6491aa9
resets store before fetching new indexData
hqhhuang 9942643
do not set `includedArchiveIdentifiers` in Navigator Provider
hqhhuang 9f7fc45
rename state to `indexState`
hqhhuang 801593a
simplify logic to find technology index data
hqhhuang a1fd338
remove url related computed properties
hqhhuang 1b8ee36
move fetching logic to `view/DocumentationTopic`
hqhhuang 835ad6b
display index data for correct language variant
hqhhuang cbb7f50
save flattened data for all language variants to store
hqhhuang 3dfcb67
Merge branch 'index-store' of github.com:hqhhuang/swift-docc-render i…
hqhhuang 6fa85b6
Revert "Merge branch 'index-store' of github.com:hqhhuang/swift-docc-…
hqhhuang 0e92cc1
update flatChildren default format
hqhhuang b8cec41
make sure data defaults to swift variant & add tests
hqhhuang 24519c6
rename and clean up node logic
hqhhuang 8aa6337
Merge branch 'main' into index-store
hqhhuang 5026c9e
Improve tests and test description
hqhhuang 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /** | ||
| * 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 { getAbsoluteUrl } from 'docc-render/utils/url-helper'; | ||
| import { flattenNestedData } from 'docc-render/utils/navigatorData'; | ||
| import Language from 'docc-render/constants/Language'; | ||
| import IndexStore from 'docc-render/stores/IndexStore'; | ||
|
|
||
| export default { | ||
| computed: { | ||
| technologyUrl: ({ technology }) => (technology ? technology.url : ''), | ||
| /** | ||
| * Recomputes the list of flat children. | ||
| * @return NavigatorFlatItem[] | ||
| */ | ||
| flatChildren: ({ | ||
| technologyWithChildren = {}, | ||
| }) => ( | ||
| flattenNestedData( | ||
| technologyWithChildren.children || [], null, 0, technologyWithChildren.beta, | ||
| ) | ||
| ), | ||
| technologyPath: ({ technologyUrl }) => { | ||
| // regex should match only the first section, no slash - `/documentation/:technology` | ||
| const matches = /(\/documentation\/(?:[^/]+))\/?/.exec(technologyUrl); | ||
| return matches ? matches[1] : ''; | ||
| }, | ||
| /** | ||
| * Extracts the technology data, for the currently chosen language | ||
| * @return {Object} | ||
| */ | ||
| technologyWithChildren({ | ||
| navigationIndex, | ||
| topicProps: { interfaceLanguage } = { interfaceLanguage: Language.swift.key.url }, | ||
| technologyPath, | ||
| }) { | ||
| // get the technologies for the current language | ||
| let currentLangTechnologies = navigationIndex[interfaceLanguage] || []; | ||
| // if no such items, we use the default swift one | ||
| if (!currentLangTechnologies.length) { | ||
| currentLangTechnologies = navigationIndex[Language.swift.key.url] || []; | ||
| } | ||
| // find the current technology | ||
| const currentTechnology = currentLangTechnologies.find(t => ( | ||
| technologyPath.toLowerCase() === t.path.toLowerCase() | ||
| )); | ||
| return currentTechnology ?? currentLangTechnologies[0]; | ||
| }, | ||
| indexDataPath() { | ||
| const slug = this.$route?.params?.locale || ''; | ||
| return pathJoin(['/index/', slug, 'index.json']); | ||
| }, | ||
| technologyProps: ({ technologyWithChildren }) => ( | ||
hqhhuang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| !technologyWithChildren ? null : { | ||
| technology: technologyWithChildren.title, | ||
| technologyPath: technologyWithChildren.path || technologyWithChildren.url, | ||
| isTechnologyBeta: technologyWithChildren.beta, | ||
| } | ||
| ), | ||
| }, | ||
| methods: { | ||
| async fetchIndexPathsData() { | ||
| const path = getAbsoluteUrl(this.indexDataPath); | ||
| return fetchData(path); | ||
| }, | ||
| async fetchIndexData() { | ||
hqhhuang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| const { | ||
| includedArchiveIdentifiers = [], | ||
| interfaceLanguages, | ||
| references = {}, | ||
| } = await this.fetchIndexPathsData(); | ||
| this.navigationIndex = Object.freeze(interfaceLanguages); | ||
| IndexStore.setReferences(references); | ||
| IndexStore.setIncludedArchiveIdentifiers(includedArchiveIdentifiers); | ||
| IndexStore.setFlatChildren(this.flatChildren); | ||
| IndexStore.setTechnologyProps(this.technologyProps); | ||
| } catch (e) { | ||
| IndexStore.setErrorFetching(true); | ||
| } | ||
| }, | ||
| }, | ||
| watch: { | ||
| indexDataPath: { | ||
| handler: 'fetchIndexData', | ||
| immediate: true, | ||
| }, | ||
| }, | ||
| }; | ||
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
| 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; | ||
| }, | ||
| }; |
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.