Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
c883b526
Commit
c883b526
authored
Aug 29, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renames file when template type is changed
parent
c0923cbd
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
162 additions
and
36 deletions
+162
-36
app/assets/javascripts/ide/components/file_templates/bar.vue
app/assets/javascripts/ide/components/file_templates/bar.vue
+10
-14
app/assets/javascripts/ide/components/new_dropdown/modal.vue
app/assets/javascripts/ide/components/new_dropdown/modal.vue
+1
-0
app/assets/javascripts/ide/stores/modules/file_templates/actions.js
.../javascripts/ide/stores/modules/file_templates/actions.js
+19
-1
app/assets/javascripts/ide/stores/modules/file_templates/getters.js
.../javascripts/ide/stores/modules/file_templates/getters.js
+5
-2
app/assets/javascripts/ide/stores/mutations.js
app/assets/javascripts/ide/stores/mutations.js
+4
-0
spec/javascripts/ide/stores/modules/file_templates/actions_spec.js
...scripts/ide/stores/modules/file_templates/actions_spec.js
+75
-8
spec/javascripts/ide/stores/modules/file_templates/getters_spec.js
...scripts/ide/stores/modules/file_templates/getters_spec.js
+40
-11
spec/javascripts/ide/stores/mutations_spec.js
spec/javascripts/ide/stores/mutations_spec.js
+8
-0
No files found.
app/assets/javascripts/ide/components/file_templates/bar.vue
View file @
c883b526
...
...
@@ -47,7 +47,7 @@ export default {
<
template
>
<div
class=
"d-flex align-items-center ide-file-templates"
>
<strong
class=
"
mr-2
"
>
<strong
class=
"
append-right-default
"
>
{{
__
(
'
File templates
'
)
}}
</strong>
<dropdown
...
...
@@ -58,7 +58,7 @@ export default {
/>
<dropdown
v-if=
"showTemplatesDropdown"
:label=
"__('Choose a t
yp
e...')"
:label=
"__('Choose a t
emplat
e...')"
:async=
"true"
:searchable=
"true"
:title=
"__('File templates')"
...
...
@@ -66,18 +66,14 @@ export default {
@
click=
"selecteTemplate"
/>
<transition
name=
"fade"
>
<div
v-show=
"updateSuccess"
>
<strong
class=
"text-success mr-2"
>
{{
__
(
'
Template applied
'
)
}}
</strong>
<button
type=
"button"
class=
"btn btn-default"
@
click=
"undoFileTemplate"
>
{{
__
(
'
Undo
'
)
}}
</button>
</div>
<button
v-show=
"updateSuccess"
type=
"button"
class=
"btn btn-default"
@
click=
"undoFileTemplate"
>
{{
__
(
'
Undo
'
)
}}
</button>
</transition>
</div>
</
template
>
...
...
app/assets/javascripts/ide/components/new_dropdown/modal.vue
View file @
c883b526
...
...
@@ -91,6 +91,7 @@ export default {
:header-title-text=
"modalTitle"
:footer-primary-button-text=
"buttonLabel"
footer-primary-button-variant=
"success"
modal-size=
"lg"
@
submit=
"submitForm"
@
open=
"focusInput"
@
closed=
"closedModal"
...
...
app/assets/javascripts/ide/stores/modules/file_templates/actions.js
View file @
c883b526
...
...
@@ -32,9 +32,23 @@ export const fetchTemplateTypes = ({ dispatch, state }) => {
.
catch
(()
=>
dispatch
(
'
receiveTemplateTypesError
'
));
};
export
const
setSelectedTemplateType
=
({
commit
},
type
)
=>
export
const
setSelectedTemplateType
=
({
commit
,
dispatch
,
rootGetters
},
type
)
=>
{
commit
(
types
.
SET_SELECTED_TEMPLATE_TYPE
,
type
);
if
(
rootGetters
.
activeFile
.
prevPath
===
type
.
name
)
{
dispatch
(
'
discardFileChanges
'
,
rootGetters
.
activeFile
.
path
,
{
root
:
true
});
}
else
if
(
rootGetters
.
activeFile
.
name
!==
type
.
name
)
{
dispatch
(
'
renameEntry
'
,
{
path
:
rootGetters
.
activeFile
.
path
,
name
:
type
.
name
,
},
{
root
:
true
},
);
}
};
export
const
receiveTemplateError
=
({
dispatch
},
template
)
=>
{
dispatch
(
'
setErrorMessage
'
,
...
...
@@ -80,6 +94,10 @@ export const undoFileTemplate = ({ dispatch, commit, rootGetters }) => {
commit
(
types
.
SET_UPDATE_SUCCESS
,
false
);
eventHub
.
$emit
(
`editor.update.model.new.content.
${
file
.
key
}
`
,
file
.
raw
);
if
(
file
.
prevPath
)
{
dispatch
(
'
discardFileChanges
'
,
file
.
path
,
{
root
:
true
});
}
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
...
...
app/assets/javascripts/ide/stores/modules/file_templates/getters.js
View file @
c883b526
import
{
activityBarViews
}
from
'
../../../constants
'
;
export
const
templateTypes
=
()
=>
[
{
name
:
'
.gitlab-ci.yml
'
,
...
...
@@ -17,7 +19,8 @@ export const templateTypes = () => [
},
];
export
const
showFileTemplatesBar
=
(
_
,
getters
)
=>
name
=>
getters
.
templateTypes
.
find
(
t
=>
t
.
name
===
name
);
export
const
showFileTemplatesBar
=
(
_
,
getters
,
rootState
)
=>
name
=>
getters
.
templateTypes
.
find
(
t
=>
t
.
name
===
name
)
&&
rootState
.
currentActivityView
===
activityBarViews
.
edit
;
export
default
()
=>
{};
app/assets/javascripts/ide/stores/mutations.js
View file @
c883b526
...
...
@@ -245,6 +245,10 @@ export default {
if
(
newEntry
.
type
===
'
blob
'
)
{
state
.
changedFiles
=
state
.
changedFiles
.
concat
(
newEntry
);
}
if
(
state
.
entries
[
newPath
].
opened
)
{
state
.
openFiles
.
push
(
state
.
entries
[
newPath
]);
}
},
...
projectMutations
,
...
mergeRequestMutation
,
...
...
spec/javascripts/ide/stores/modules/file_templates/actions_spec.js
View file @
c883b526
...
...
@@ -148,14 +148,66 @@ describe('IDE file templates actions', () => {
});
describe
(
'
setSelectedTemplateType
'
,
()
=>
{
it
(
'
commits SET_SELECTED_TEMPLATE_TYPE
'
,
done
=>
{
testAction
(
actions
.
setSelectedTemplateType
,
'
test
'
,
state
,
[{
type
:
types
.
SET_SELECTED_TEMPLATE_TYPE
,
payload
:
'
test
'
}],
[],
done
,
it
(
'
commits SET_SELECTED_TEMPLATE_TYPE
'
,
()
=>
{
const
commit
=
jasmine
.
createSpy
(
'
commit
'
);
const
options
=
{
commit
,
dispatch
()
{},
rootGetters
:
{
activeFile
:
{
name
:
'
test
'
,
prevPath
:
''
,
},
},
};
actions
.
setSelectedTemplateType
(
options
,
{
name
:
'
test
'
});
expect
(
commit
).
toHaveBeenCalledWith
(
types
.
SET_SELECTED_TEMPLATE_TYPE
,
{
name
:
'
test
'
});
});
it
(
'
dispatches discardFileChanges if prevPath matches templates name
'
,
()
=>
{
const
dispatch
=
jasmine
.
createSpy
(
'
dispatch
'
);
const
options
=
{
commit
()
{},
dispatch
,
rootGetters
:
{
activeFile
:
{
name
:
'
test
'
,
path
:
'
test
'
,
prevPath
:
'
test
'
,
},
},
};
actions
.
setSelectedTemplateType
(
options
,
{
name
:
'
test
'
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
discardFileChanges
'
,
'
test
'
,
{
root
:
true
});
});
it
(
'
dispatches renameEntry if file name doesnt match
'
,
()
=>
{
const
dispatch
=
jasmine
.
createSpy
(
'
dispatch
'
);
const
options
=
{
commit
()
{},
dispatch
,
rootGetters
:
{
activeFile
:
{
name
:
'
oldtest
'
,
path
:
'
oldtest
'
,
prevPath
:
''
,
},
},
};
actions
.
setSelectedTemplateType
(
options
,
{
name
:
'
test
'
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
renameEntry
'
,
{
path
:
'
oldtest
'
,
name
:
'
test
'
,
},
{
root
:
true
},
);
});
});
...
...
@@ -332,5 +384,20 @@ describe('IDE file templates actions', () => {
expect
(
commit
).
toHaveBeenCalledWith
(
'
SET_UPDATE_SUCCESS
'
,
false
);
});
it
(
'
dispatches discardFileChanges if file has prevPath
'
,
()
=>
{
const
dispatch
=
jasmine
.
createSpy
(
'
dispatch
'
);
const
rootGetters
=
{
activeFile
:
{
path
:
'
test
'
,
prevPath
:
'
newtest
'
,
raw
:
'
raw content
'
},
};
actions
.
undoFileTemplate
({
dispatch
,
commit
()
{},
rootGetters
});
expect
(
dispatch
.
calls
.
mostRecent
().
args
).
toEqual
([
'
discardFileChanges
'
,
'
test
'
,
{
root
:
true
},
]);
});
});
});
spec/javascripts/ide/stores/modules/file_templates/getters_spec.js
View file @
c883b526
import
createState
from
'
~/ide/stores/state
'
;
import
{
activityBarViews
}
from
'
~/ide/constants
'
;
import
*
as
getters
from
'
~/ide/stores/modules/file_templates/getters
'
;
describe
(
'
IDE file templates getters
'
,
()
=>
{
...
...
@@ -8,22 +10,49 @@ describe('IDE file templates getters', () => {
});
describe
(
'
showFileTemplatesBar
'
,
()
=>
{
it
(
'
finds template type by name
'
,
()
=>
{
let
rootState
;
beforeEach
(()
=>
{
rootState
=
createState
();
});
it
(
'
returns true if template is found and currentActivityView is edit
'
,
()
=>
{
rootState
.
currentActivityView
=
activityBarViews
.
edit
;
expect
(
getters
.
showFileTemplatesBar
(
null
,
{
templateTypes
:
getters
.
templateTypes
(),
},
rootState
,
)(
'
LICENSE
'
),
).
toBe
(
true
);
});
it
(
'
returns false if template is found and currentActivityView is not edit
'
,
()
=>
{
rootState
.
currentActivityView
=
activityBarViews
.
commit
;
expect
(
getters
.
showFileTemplatesBar
(
null
,
{
templateTypes
:
getters
.
templateTypes
(),
})(
'
LICENSE
'
),
).
toEqual
({
name
:
'
LICENSE
'
,
key
:
'
licenses
'
,
});
getters
.
showFileTemplatesBar
(
null
,
{
templateTypes
:
getters
.
templateTypes
(),
},
rootState
,
)(
'
LICENSE
'
),
).
toBe
(
false
);
});
it
(
'
returns undefined if not found
'
,
()
=>
{
expect
(
getters
.
showFileTemplatesBar
(
null
,
{
templateTypes
:
getters
.
templateTypes
(),
})(
'
test
'
),
getters
.
showFileTemplatesBar
(
null
,
{
templateTypes
:
getters
.
templateTypes
(),
},
rootState
,
)(
'
test
'
),
).
toBe
(
undefined
);
});
});
...
...
spec/javascripts/ide/stores/mutations_spec.js
View file @
c883b526
...
...
@@ -339,5 +339,13 @@ describe('Multi-file store mutations', () => {
expect
(
localState
.
entries
.
parentPath
.
tree
.
length
).
toBe
(
1
);
});
it
(
'
adds to openFiles if previously opened
'
,
()
=>
{
localState
.
entries
.
oldPath
.
opened
=
true
;
mutations
.
RENAME_ENTRY
(
localState
,
{
path
:
'
oldPath
'
,
name
:
'
newPath
'
});
expect
(
localState
.
openFiles
).
toEqual
([
localState
.
entries
.
newPath
]);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment