Skip to content

Feat rename project #3955

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
May 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions packages/@vue/cli-ui/apollo-server/connectors/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ function setFavorite ({ id, favorite }, context) {
return findOne(id, context)
}

function rename ({ id, name }, context) {
context.db.get('projects').find({ id }).assign({ name }).write()
return findOne(id, context)
}

function getType (project, context) {
if (typeof project === 'string') {
project = findByPath(project, context)
Expand Down Expand Up @@ -483,6 +488,7 @@ module.exports = {
remove,
resetCwd,
setFavorite,
rename,
initCreator,
removeCreator,
getType,
Expand Down
2 changes: 2 additions & 0 deletions packages/@vue/cli-ui/apollo-server/schema/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extend type Mutation {
projectRemove (id: ID!): Boolean!
projectCwdReset: String
projectSetFavorite (id: ID!, favorite: Int!): Project!
projectRename (id: ID!, name: String!): Project!
presetApply (id: ID!): ProjectCreation
featureSetEnabled (id: ID!, enabled: Boolean): Feature
}
Expand Down Expand Up @@ -105,6 +106,7 @@ exports.resolvers = {
projectRemove: (root, { id }, context) => projects.remove(id, context),
projectCwdReset: (root, args, context) => projects.resetCwd(context),
projectSetFavorite: (root, args, context) => projects.setFavorite(args, context),
projectRename: (root, args, context) => projects.rename(args, context),
presetApply: (root, { id }, context) => projects.applyPreset(id, context),
featureSetEnabled: (root, args, context) => projects.setFeatureEnabled(args, context)
}
Expand Down
9 changes: 9 additions & 0 deletions packages/@vue/cli-ui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"vue": {
"common": {
"close": "Close",
"cancel": "Cancel",
"back": "Go back",
"more-info": "More info",
"show-more": "Show more",
Expand Down Expand Up @@ -111,6 +112,14 @@
"open-in-editor": "Open in editor"
}
},
"project-rename": {
"title": "Rename",
"name-field": {
"title": "Name",
"subtitle": "Enter the new name"
},
"submit": "Rename"
},
"project-plugin-item": {
"version": "version",
"latest": "latest",
Expand Down
157 changes: 92 additions & 65 deletions packages/@vue/cli-ui/src/components/app/ProjectQuickDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,84 +1,98 @@
<template>
<VueDropdown
v-if="$responsive.wide"
:label="projectCurrent ? projectCurrent.name : $t('org.vue.components.status-bar.project.empty')"
class="current-project project-quick-dropdown"
icon-right="arrow_drop_down"
button-class="round"
>
<!-- Current project options -->

<template v-if="projectCurrent">
<VueSwitch
:value="projectCurrent.favorite"
:icon="projectCurrent.favorite ? 'star' : 'star_border'"
class="extend-left"
@update="toggleCurrentFavorite()"
>
{{ $t('org.vue.components.project-select-list-item.tooltips.favorite') }}
</VueSwitch>
<div class="project-quick-dropdown">
<VueDropdown
v-if="$responsive.wide"
:label="projectCurrent ? projectCurrent.name : $t('org.vue.components.status-bar.project.empty')"
class="current-project"
icon-right="arrow_drop_down"
button-class="round"
>
<!-- Current project options -->

<template v-if="projectCurrent">
<VueSwitch
:value="projectCurrent.favorite"
:icon="projectCurrent.favorite ? 'star' : 'star_border'"
class="extend-left"
@update="toggleCurrentFavorite()"
>
{{ $t('org.vue.components.project-select-list-item.tooltips.favorite') }}
</VueSwitch>

<VueDropdownButton
:label="$t('org.vue.components.project-select-list-item.tooltips.open-in-editor')"
icon-left="open_in_browser"
@click="openInEditor(projectCurrent)"
/>

<VueDropdownButton
:label="$t('org.vue.components.project-rename.title')"
icon-left="local_offer"
@click="showRename = true"
/>

<VueDropdownButton
v-if="projectCurrent.homepage"
:href="projectCurrent.homepage"
:label="$t('org.vue.components.top-bar.homepage')"
target="_blank"
icon-left="open_in_new"
/>
</template>

<VueDropdownButton
:label="$t('org.vue.components.project-select-list-item.tooltips.open-in-editor')"
icon-left="open_in_browser"
@click="openInEditor(projectCurrent)"
/>
<div class="dropdown-separator"/>

<VueDropdownButton
v-if="projectCurrent.homepage"
:href="projectCurrent.homepage"
:label="$t('org.vue.components.top-bar.homepage')"
target="_blank"
icon-left="open_in_new"
/>
</template>
<!-- Favorites -->

<div class="dropdown-separator"/>
<div v-if="!favoriteProjects.length" class="vue-ui-empty">{{ $t('org.vue.components.top-bar.no-favorites') }}</div>

<!-- Favorites -->
<template v-else>
<div class="section-title">
{{ $t('org.vue.components.top-bar.favorite-projects') }}
</div>

<div v-if="!favoriteProjects.length" class="vue-ui-empty">{{ $t('org.vue.components.top-bar.no-favorites') }}</div>
<VueDropdownButton
v-for="project of favoriteProjects"
:key="project.id"
:label="project.name"
icon-left="star"
@click="openProject(project)"
/>
</template>

<template v-else>
<div class="section-title">
{{ $t('org.vue.components.top-bar.favorite-projects') }}
</div>
<!-- Recents -->

<VueDropdownButton
v-for="project of favoriteProjects"
:key="project.id"
:label="project.name"
icon-left="star"
@click="openProject(project)"
/>
</template>
<template v-if="recentProjects.length">
<div class="dropdown-separator"/>

<!-- Recents -->
<div class="section-title">
{{ $t('org.vue.components.top-bar.recent-projects') }}
</div>

<template v-if="recentProjects.length">
<div class="dropdown-separator"/>
<VueDropdownButton
v-for="project of recentProjects"
:key="project.id"
:label="project.name"
icon-left="restore"
@click="openProject(project)"
/>
</template>

<div class="section-title">
{{ $t('org.vue.components.top-bar.recent-projects') }}
</div>
<div class="dropdown-separator"/>

<VueDropdownButton
v-for="project of recentProjects"
:key="project.id"
:label="project.name"
icon-left="restore"
@click="openProject(project)"
:to="{ name: 'project-select' }"
:label="$t('org.vue.views.project-select.title')"
icon-left="home"
/>
</template>

<div class="dropdown-separator"/>
</VueDropdown>

<VueDropdownButton
:to="{ name: 'project-select' }"
:label="$t('org.vue.views.project-select.title')"
icon-left="home"
<ProjectRename
v-if="showRename"
:project="projectCurrent"
@close="showRename = false"
/>
</VueDropdown>
</div>
</template>

<script>
Expand All @@ -90,12 +104,24 @@ import PROJECT_OPEN from '@/graphql/project/projectOpen.gql'
import PROJECT_SET_FAVORITE from '@/graphql/project/projectSetFavorite.gql'
import OPEN_IN_EDITOR from '@/graphql/file/fileOpenInEditor.gql'

import ProjectRename from '../project-manager/ProjectRename.vue'

export default {
components: {
ProjectRename
},

apollo: {
projectCurrent: PROJECT_CURRENT,
projects: PROJECTS
},

data () {
return {
showRename: false
}
},

computed: {
favoriteProjects () {
if (!this.projects) return []
Expand Down Expand Up @@ -154,6 +180,7 @@ export default {

<style lang="stylus" scoped>
.current-project
width 100%
>>> .trigger
.vue-ui-button
.vue-ui-icon.right
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<VueModal
:title="$t('org.vue.components.project-rename.title')"
class="medium anchor"
@close="$emit('close')"
>
<div class="default-body">
<VueFormField
:title="$t('org.vue.components.project-rename.name-field.title')"
:subtitle="$t('org.vue.components.project-rename.name-field.subtitle')"
>
<VueInput
v-model="newName"
icon-left="folder"
v-focus
class="big"
@keyup.enter="rename()"
/>
</VueFormField>
</div>

<div slot="footer" class="actions">
<VueButton
:label="$t('org.vue.common.cancel')"
class="flat big close"
@click="$emit('close')"
/>

<VueButton
class="primary big"
:label="$t('org.vue.components.project-rename.submit')"
@click="rename()"
/>
</div>
</VueModal>
</template>

<script>
import gql from 'graphql-tag'

export default {
props: {
project: {
type: Object,
required: true
}
},

data () {
return {
newName: this.project.name,
loading: false
}
},

methods: {
async rename () {
this.loading = true

await this.$apollo.mutate({
mutation: gql`
mutation renameProject ($id: ID!, $name: String!) {
projectRename (id: $id, name: $name) {
id
name
}
}
`,
variables: {
id: this.project.id,
name: this.newName
}
})

this.$emit('close')
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
@click.stop
/>

<VueButton
class="icon-button"
icon-left="local_offer"
v-tooltip="$t('org.vue.components.project-rename.title')"
@click.stop="showRename = true"
/>

<VueButton
class="icon-button"
icon-left="close"
Expand All @@ -53,20 +60,39 @@
/>
</div>
</div>

<ProjectRename
v-if="showRename"
:project="project"
@close="showRename = false"
@click.native.stop
/>
</div>
</template>

<script>
import OPEN_IN_EDITOR from '@/graphql/file/fileOpenInEditor.gql'

import ProjectRename from './ProjectRename.vue'

export default {
components: {
ProjectRename
},

props: {
project: {
type: Object,
required: true
}
},

data () {
return {
showRename: false
}
},

methods: {
async openInEditor () {
await this.$apollo.mutate({
Expand Down
Loading