Skip to content

Adds query param for version no #4270

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
merged 3 commits into from
Jun 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
const queryParams = new URLSearchParams(window.location.search);
const searchParam = queryParams.get('search');
const searchTerm = null !== searchParam ? searchParam : '';
const versionParam = queryParams.get('version');
const parseVersionParam = (version) => {
if (version === 'master') return 'master';
if (version.startsWith('v')) return version;
return `v${version}`;
};
const versionNumber = null !== versionParam ? parseVersionParam(versionParam) : 'master';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe checking for falsyness (!versionParam) is better, in case the param looks like ?version=

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, semantically the user has provided a version number, an empty string in this case. so the current way clearly separates version not provided case from provided but invalid case.
If its still necessary will use falsy then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but I think it's fair to assume the user didn't intend to specify a particular version since no valid version will be an empty string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, an empty string may not be a valid version but what about ?version=0.0 or ?version=0n.
do we also interpret them as having no intention to specify a version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC URLSearchParams will return strictly null in the absence of the query param, so I don't want to bikeshed too much on this one.

If anyone's interested in trying to handle the empty string version case then I'd suggest that be done in a follow up

new Vue({
el: '#app',
data: {
Expand All @@ -90,7 +97,7 @@
configurationDescriptions: [],
searchCondition: searchTerm,
shouldStable: false,
version: 'master',
version: versionNumber,
oldVersion: undefined,
versionOptions: ['master']
},
Expand All @@ -99,16 +106,20 @@
if (this.version !== this.oldVersion) {
const ConfigurationMdUrl =
`https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`;
const res = await axios.get(ConfigurationMdUrl);
const {
about,
configurationAbout,
configurationDescriptions
} = parseMarkdownAst(res.data);
this.aboutHtml = marked.parser(about);
this.configurationAboutHtml = marked.parser(configurationAbout);
this.configurationDescriptions = configurationDescriptions;
this.oldVersion = this.version;
try {
const res = await axios.get(ConfigurationMdUrl);
const {
about,
configurationAbout,
configurationDescriptions
} = parseMarkdownAst(res.data);
this.aboutHtml = marked.parser(about);
this.configurationAboutHtml = marked.parser(configurationAbout);
this.configurationDescriptions = configurationDescriptions;
this.oldVersion = this.version;
} catch(error) {
this.aboutHtml = "<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
}
}

const ast = this.configurationDescriptions
Expand Down