1
1
<script >
2
2
import { GlModal } from ' @gitlab/ui' ;
3
- import { pick } from ' lodash' ;
4
3
import { __ , s__ } from ' ~/locale' ;
5
4
import { deprecatedCreateFlash as Flash } from ' ~/flash' ;
6
- import { visitUrl } from ' ~/lib/utils/url_utility' ;
5
+ import { visitUrl , stripFinalUrlSegment } from ' ~/lib/utils/url_utility' ;
6
+ import { getIdFromGraphQLId , convertToGraphQLId } from ' ~/graphql_shared/utils' ;
7
7
import boardsStore from ' ~/boards/stores/boards_store' ;
8
- import { fullBoardId , getBoardsPath } from ' ../boards_util' ;
8
+ import { fullLabelId , fullBoardId } from ' ../boards_util' ;
9
9
10
10
import BoardConfigurationOptions from ' ./board_configuration_options.vue' ;
11
- import createBoardMutation from ' ../graphql/board.mutation.graphql' ;
11
+ import updateBoardMutation from ' ../graphql/board_update.mutation.graphql' ;
12
+ import createBoardMutation from ' ../graphql/board_create.mutation.graphql' ;
12
13
13
14
const boardDefaults = {
14
15
id: false ,
@@ -91,8 +92,8 @@ export default {
91
92
},
92
93
},
93
94
inject: {
94
- endpoints : {
95
- default: {} ,
95
+ fullPath : {
96
+ default: ' ' ,
96
97
},
97
98
},
98
99
data () {
@@ -155,14 +156,38 @@ export default {
155
156
text: this .$options .i18n .cancelButtonText ,
156
157
};
157
158
},
158
- boardPayload () {
159
- const { assignee , milestone , labels } = this .board ;
160
- return {
161
- ... this .board ,
162
- assignee_id: assignee? .id ,
163
- milestone_id: milestone? .id ,
164
- label_ids: labels .length ? labels .map (b => b .id ) : [' ' ],
159
+ currentMutation () {
160
+ return this .board .id ? updateBoardMutation : createBoardMutation;
161
+ },
162
+ mutationVariables () {
163
+ const { board } = this ;
164
+ /* eslint-disable @gitlab/require-i18n-strings */
165
+ const baseMutationVariables = {
166
+ name: board .name ,
167
+ weight: board .weight ,
168
+ assigneeId: board .assignee ? .id ? convertToGraphQLId (' User' , board .assignee .id ) : null ,
169
+ milestoneId:
170
+ board .milestone ? .id || board .milestone ? .id === 0
171
+ ? convertToGraphQLId (' Milestone' , board .milestone .id )
172
+ : null ,
173
+ labelIds: board .labels .map (fullLabelId),
174
+ hideBacklogList: board .hide_backlog_list ,
175
+ hideClosedList: board .hide_closed_list ,
176
+ iterationId: board .iteration_id
177
+ ? convertToGraphQLId (' Iteration' , board .iteration_id )
178
+ : null ,
165
179
};
180
+ /* eslint-enable @gitlab/require-i18n-strings */
181
+ return board .id
182
+ ? {
183
+ ... baseMutationVariables,
184
+ id: fullBoardId (board .id ),
185
+ }
186
+ : {
187
+ ... baseMutationVariables,
188
+ projectPath: this .projectId ? this .fullPath : null ,
189
+ groupPath: this .groupId ? this .fullPath : null ,
190
+ };
166
191
},
167
192
},
168
193
mounted () {
@@ -175,55 +200,39 @@ export default {
175
200
setIteration (iterationId ) {
176
201
this .board .iteration_id = iterationId;
177
202
},
178
- callBoardMutation (id ) {
179
- return this .$apollo .mutate ({
180
- mutation: createBoardMutation,
181
- variables: {
182
- ... pick (this .boardPayload , [' hideClosedList' , ' hideBacklogList' ]),
183
- id,
184
- },
203
+ async createOrUpdateBoard () {
204
+ const response = await this .$apollo .mutate ({
205
+ mutation: this .currentMutation ,
206
+ variables: { input: this .mutationVariables },
185
207
});
186
- },
187
- async updateBoard () {
188
- const responses = await Promise .all ([
189
- // Remove unnecessary REST API call when https://gitlab.com/gitlab-org/gitlab/-/issues/282299#note_462996301 is resolved
190
- getBoardsPath (this .endpoints .boardsEndpoint , this .boardPayload ),
191
- this .callBoardMutation (fullBoardId (this .boardPayload .id )),
192
- ]);
193
208
194
- return responses[0 ].data ;
209
+ return this .board .id
210
+ ? getIdFromGraphQLId (response .data .updateBoard .board .id )
211
+ : getIdFromGraphQLId (response .data .createBoard .board .id );
195
212
},
196
- async createBoard () {
197
- // TODO: change this to use `createBoard` mutation https://gitlab.com/gitlab-org/gitlab/-/issues/292466 is resolved
198
- const boardData = await getBoardsPath (this .endpoints .boardsEndpoint , this .boardPayload );
199
- this .callBoardMutation (fullBoardId (boardData .data .id ));
200
-
201
- return boardData .data || boardData;
202
- },
203
- submit () {
213
+ async submit () {
204
214
if (this .board .name .length === 0 ) return ;
205
215
this .isLoading = true ;
206
216
if (this .isDeleteForm ) {
207
- boardsStore
208
- .deleteBoard (this .currentBoard )
209
- .then (() => {
210
- this .isLoading = false ;
211
- visitUrl (boardsStore .rootPath );
212
- })
213
- .catch (() => {
214
- Flash (this .$options .i18n .deleteErrorMessage );
215
- this .isLoading = false ;
216
- });
217
+ try {
218
+ await boardsStore .deleteBoard (this .currentBoard );
219
+ visitUrl (boardsStore .rootPath );
220
+ } catch {
221
+ Flash (this .$options .i18n .deleteErrorMessage );
222
+ } finally {
223
+ this .isLoading = false ;
224
+ }
217
225
} else {
218
- const boardAction = this .boardPayload .id ? this .updateBoard : this .createBoard ;
219
- boardAction ()
220
- .then (data => {
221
- visitUrl (data .board_path );
222
- })
223
- .catch (() => {
224
- Flash (this .$options .i18n .saveErrorMessage );
225
- this .isLoading = false ;
226
- });
226
+ try {
227
+ const path = await this .createOrUpdateBoard ();
228
+ const strippedUrl = stripFinalUrlSegment (window .location .href );
229
+ const url = strippedUrl .includes (' boards' ) ? ` ${ path} ` : ` boards/${ path} ` ;
230
+ visitUrl (url);
231
+ } catch {
232
+ Flash (this .$options .i18n .saveErrorMessage );
233
+ } finally {
234
+ this .isLoading = false ;
235
+ }
227
236
}
228
237
},
229
238
cancel () {
@@ -277,9 +286,8 @@ export default {
277
286
</div >
278
287
279
288
<board-configuration-options
280
- :is-new-form =" isNewForm"
281
- :board =" board"
282
- :current-board =" currentBoard"
289
+ :hide-backlog-list.sync =" board.hide_backlog_list"
290
+ :hide-closed-list.sync =" board.hide_closed_list"
283
291
/>
284
292
285
293
<board-scope
0 commit comments