Skip to content

Commit

Permalink
fix: restrict history for local projects (#161)
Browse files Browse the repository at this point in the history
Local projects don't have an identifier that can keep churn between different repositories and branches.
  • Loading branch information
Zoramite committed Jul 30, 2021
1 parent 36dc4e6 commit adec8ec
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 63 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@types/lodash.merge": "^4.6.6",
"@types/marked": "^2.0.4",
"@types/mime-types": "^2.1.0",
"@types/node": "^16.4.3",
"@types/node": "^16.4.7",
"@types/nunjucks": "^3.1.5",
"@types/quill": "^2.0.9",
"@typescript-eslint/eslint-plugin": "^4.28.5",
Expand All @@ -86,7 +86,7 @@
"ts-node": "^10.1.0",
"typedoc": "^0.21.4",
"typescript": "^4.3.5",
"webpack": "^5.46.0",
"webpack": "^5.47.1",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "^5.8.0"
Expand Down
15 changes: 13 additions & 2 deletions src/ts/editor/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
PreviewRoutesMetaData,
PreviewSettings,
ProjectData,
ProjectSource,
PublishResult,
SiteData,
UserData,
Expand Down Expand Up @@ -488,7 +489,12 @@ export class EditorState extends ListenersMixin(Base) {
this.updateTitle();

// Add the file to the project history.
if (this.projectId) {
if (
this.projectId &&
// Local projects do not have a good unique identifier except the
// file path and do not want to use the file path as an identifier.
this.project?.source?.source !== ProjectSource.Local
) {
const projectHistory = this.history.getProject(this.projectId);
const fileHistory = {
path: file.path,
Expand Down Expand Up @@ -688,7 +694,12 @@ export class EditorState extends ListenersMixin(Base) {
this.updateTitle();

// Add the workspace to the project history.
if (this.projectId) {
if (
this.projectId &&
// Local projects do not have a good unique identifier except the
// file path and do not want to use the file path as an identifier.
this.project?.source?.source !== ProjectSource.Local
) {
const projectHistory = this.history.getProject(this.projectId);
projectHistory.addRecentWorkspace({
name: this.workspace.name,
Expand Down
8 changes: 7 additions & 1 deletion src/ts/editor/ui/parts/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {TemplateResult, classMap, html, repeat} from '@blinkk/selective-edit';

import {DataStorage} from '../../../utility/dataStorage';
import {EVENT_FILE_LOAD} from '../../events';
import {ProjectSource} from '../../api';
import TimeAgo from 'javascript-time-ago';

export const STORAGE_RECENT = 'live.dashboard.recent';
Expand Down Expand Up @@ -167,7 +168,12 @@ export class DashboardPart extends BasePart implements UiPartComponent {
const subParts: Array<TemplateResult> = [];
let recentWorkspaces: Array<RecentWorkspaceData> = [];

if (this.projectHistory && this.config.state.workspace) {
if (
// Local projects do not provide workspace support.
this.config.state.project?.source?.source !== ProjectSource.Local &&
this.projectHistory &&
this.config.state.workspace
) {
recentWorkspaces = this.projectHistory.getRecentWorkspaces();
}

Expand Down
22 changes: 13 additions & 9 deletions src/ts/editor/ui/parts/onboarding/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
);
}

return html`${this.templateHeader('Organizations')}
return html` ${this.templateHeader('Organizations')}
${this.templateSectionHeader('Select an organization')}
${this.templateHelp(html`Unable to find your organization? Install the
<a href=${APP_URL}>GitHub App</a>.`)}
Expand Down Expand Up @@ -350,20 +350,25 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
</div>`;
}

templateRecentProjects(): TemplateResult {
templateRecentRepositories(filter?: string, maxCount = 10): TemplateResult {
let recentProjects = this.config.state.history.recentProjects;

// Filter down all the recent to just ones that belong to the current
// organization.
recentProjects = recentProjects.filter(project =>
project.identifier.startsWith(`${this.api.organization}/`)
);
if (filter) {
recentProjects = recentProjects.filter(project =>
project.identifier.startsWith(filter)
);
}

// Adjust the number of recent projects to show.
recentProjects = recentProjects.slice(0, maxCount);

if (!recentProjects.length) {
return html``;
}

return html`${this.templateSectionHeader('Recent projects')}
return html`${this.templateSectionHeader('Recent repositories')}
<div class="le__part__onboarding__options">
<div
class=${classMap({
Expand Down Expand Up @@ -424,8 +429,7 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
}
)}
</div>
</div>
${this.templateSectionHeader('Available projects')}`;
</div>`;
}

templateRepositories(): TemplateResult {
Expand Down Expand Up @@ -459,14 +463,14 @@ export class GitHubOnboardingPart extends BasePart implements UiPartComponent {
return html`${this.templateHeader(
`Repositories in ${this.api.organization}`
)}
${this.templateRecentRepositories(`${this.api.organization}/`, 3)}
${this.templateSectionHeader('Select a repository')}
${this.templateHelp(html`Repository missing?
${this.installation
? html`Configure the
<a href=${this.installation?.url || APP_URL}>GitHub App</a>
repository access.`
: html`Install the <a href=${APP_URL}>GitHub App</a>.`}`)}
${this.templateRecentProjects()}
${this.repositories
? ''
: this.templateLoadingStatus(html`Finding ${this.api.organization}
Expand Down
85 changes: 36 additions & 49 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==

"@types/node@*", "@types/node@^16.4.3":
version "16.4.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.4.3.tgz#c01c1a215721f6dec71b47d88b4687463601ba48"
integrity sha512-GKM4FLMkWDc0sfx7tXqPWkM6NBow1kge0fgQh0bOnlqo4iT1kvTvMEKE0c1RtUGnbLlGRXiAA8SumE//90uKAg==
"@types/node@*", "@types/node@^16.4.7":
version "16.4.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.4.7.tgz#f7afa78769d4b477f5092d7c3468e2e8653d779c"
integrity sha512-aDDY54sst8sx47CWT6QQqIZp45yURq4dic0+HCYfYNcY5Ejlb/CLmFnRLfy3wQuYafOeh3lB/DAKaqRKBtcZmA==

"@types/normalize-package-data@^2.4.0":
version "2.4.1"
Expand Down Expand Up @@ -1280,9 +1280,9 @@ buffer-crc32@~0.2.3:
integrity sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
version "1.1.2"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==

buffer-indexof@^1.0.0:
version "1.1.1"
Expand Down Expand Up @@ -1383,9 +1383,9 @@ camelcase@^6.2.0:
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==

caniuse-lite@^1.0.30001219:
version "1.0.30001247"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001247.tgz#105be7a8fb30cdd303275e769a9dfb87d4b3577a"
integrity sha512-4rS7co+7+AoOSPRPOPUt5/GdaqZc0EsUpWk66ofE3HJTAajUK2Ss2VwoNzVN69ghg8lYYlh0an0Iy4LIHHo9UQ==
version "1.0.30001248"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001248.tgz#26ab45e340f155ea5da2920dadb76a533cb8ebce"
integrity sha512-NwlQbJkxUFJ8nMErnGtT0QTM2TJ33xgz4KXJSMIrjXIbDVdaYueGyjOrLKRtJC+rTiWfi6j5cnZN1NBiSBJGNw==

caseless@~0.12.0:
version "0.12.0"
Expand All @@ -1410,9 +1410,9 @@ chalk@^3.0.0:
supports-color "^7.1.0"

chalk@^4.0.0, chalk@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad"
integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"
Expand Down Expand Up @@ -2078,9 +2078,9 @@ ee-first@1.1.1:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.723:
version "1.3.787"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.787.tgz#0d814dcc374bb8a0ae7a17c0308c39fb18fcc7bb"
integrity sha512-zeM5AFwvTlSYvGpBaFZKVo7GQEWSk6hS3rQ7mdrr3qB7CiqVl84K6nIPznyKSu0b8ABiEeMEIqyBuzqMkxnjjg==
version "1.3.791"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.791.tgz#e38f325ff22470bdcff34409d58c0baf9c2e3e93"
integrity sha512-Tdx7w1fZpeWOOBluK+kXTAKCXyc79K65RB6Zp0+sPSZZhDjXlrxfGlXrlMGVVQUrKCyEZFQs1UBBLNz5IdbF0g==

emittery@^0.8.0:
version "0.8.1"
Expand Down Expand Up @@ -2662,9 +2662,9 @@ flat-cache@^3.0.4:
rimraf "^3.0.2"

flatted@^3.1.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.1.tgz#bbef080d95fca6709362c73044a1634f7c6e7d05"
integrity sha512-OMQjaErSFHmHqZe+PSidH5n8j3O0F2DdnVh8JB4j4eUQ2k6KvB0qGfrKIhapvez5JerBbmWkaLYUYWISaESoXg==
version "3.2.2"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.2.tgz#64bfed5cb68fe3ca78b3eb214ad97b63bedce561"
integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==

follow-redirects@^1.0.0:
version "1.14.1"
Expand Down Expand Up @@ -4060,22 +4060,17 @@ micromatch@^4.0.0, micromatch@^4.0.4:
braces "^3.0.1"
picomatch "^2.2.3"

mime-db@1.48.0:
version "1.48.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.48.0.tgz#e35b31045dd7eada3aaad537ed88a33afbef2d1d"
integrity sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ==

"mime-db@>= 1.43.0 < 2":
mime-db@1.49.0, "mime-db@>= 1.43.0 < 2":
version "1.49.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.49.0.tgz#f3dfde60c99e9cf3bc9701d687778f537001cbed"
integrity sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==

mime-types@^2.1.27, mime-types@~2.1.17, mime-types@~2.1.24:
version "2.1.31"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.31.tgz#a00d76b74317c61f9c2db2218b8e9f8e9c5c9e6b"
integrity sha512-XGZnNzm3QvgKxa8dpzyhFTHmpP3l5YNusmne07VUOXxou9CqUqYa/HBy124RqtVh/O2pECas/MOcsDgpilPOPg==
version "2.1.32"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.32.tgz#1d00e89e7de7fe02008db61001d9e02852670fd5"
integrity sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==
dependencies:
mime-db "1.48.0"
mime-db "1.49.0"

mime@1.6.0:
version "1.6.0"
Expand Down Expand Up @@ -5525,11 +5520,6 @@ sockjs@^0.3.21:
uuid "^3.4.0"
websocket-driver "^0.7.4"

source-list-map@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
integrity sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw==

source-map-resolve@^0.5.0:
version "0.5.3"
resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a"
Expand Down Expand Up @@ -6155,9 +6145,9 @@ typescript@^4.3.5:
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==

uglify-js@^3.1.4:
version "3.14.0"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.14.0.tgz#2d723a0afee81e0d08db9354a9c277006e942386"
integrity sha512-R/tiGB1ZXp2BC+TkRGLwj8xUZgdfT2f4UZEgX6aVjJ5uttPrr4fYmwTWDGqVnBCLbOXRMY6nr/BTbwCtVfps0g==
version "3.14.1"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.14.1.tgz#e2cb9fe34db9cb4cf7e35d1d26dfea28e09a7d06"
integrity sha512-JhS3hmcVaXlp/xSo3PKY5R0JqKs5M3IV+exdLHW99qKvKivPO4Z8qbej6mte17SOPqAOVMjt/XGgWacnFSzM3g==

unbzip2-stream@1.3.3:
version "1.3.3"
Expand Down Expand Up @@ -6445,18 +6435,15 @@ webpack-merge@^5.7.3, webpack-merge@^5.8.0:
clone-deep "^4.0.1"
wildcard "^2.0.0"

webpack-sources@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-2.3.1.tgz#570de0af163949fe272233c2cefe1b56f74511fd"
integrity sha512-y9EI9AO42JjEcrTJFOYmVywVZdKVUfOvDUPsJea5GIr1JOEGFVqwlY2K098fFoIjOkDzHn2AjRvM8dsBZu+gCA==
dependencies:
source-list-map "^2.0.1"
source-map "^0.6.1"
webpack-sources@^3.1.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.1.2.tgz#614c962ac45dfac7f0f482052db8324a6e0dc274"
integrity sha512-//DeuK5SzM6yFRXNOGK+4tX7QB8PghkL8kFBPyqSlN62oJOUkmby8ptV7+IBGH6BkIuIw5Rjd7OvvwZaoiF4ag==

webpack@^5.46.0:
version "5.46.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.46.0.tgz#105d20d96f79db59b316b0ae54316f0f630314b5"
integrity sha512-qxD0t/KTedJbpcXUmvMxY5PUvXDbF8LsThCzqomeGaDlCA6k998D8yYVwZMvO8sSM3BTEOaD4uzFniwpHaTIJw==
webpack@^5.47.1:
version "5.47.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.47.1.tgz#20fb7d76f68912a2249a6dd7ff16faa178049ad2"
integrity sha512-cW+Mzy9SCDapFV4OrkHuP6EFV2mAsiQd+gOa3PKtHNoKg6qPqQXZzBlHH+CnQG1osplBCqwsJZ8CfGO6XWah0g==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.50"
Expand All @@ -6480,7 +6467,7 @@ webpack@^5.46.0:
tapable "^2.1.1"
terser-webpack-plugin "^5.1.3"
watchpack "^2.2.0"
webpack-sources "^2.3.1"
webpack-sources "^3.1.1"

websocket-driver@>=0.5.1, websocket-driver@^0.7.4:
version "0.7.4"
Expand Down

0 comments on commit adec8ec

Please sign in to comment.