|
@@ -1,4 +1,4 @@
|
|
|
-import {useContext, useEffect} from 'react';
|
|
|
+import {useCallback, useContext, useEffect} from 'react';
|
|
|
import {InjectedRouter} from 'react-router';
|
|
|
import styled from '@emotion/styled';
|
|
|
import {Location} from 'history';
|
|
@@ -51,16 +51,74 @@ function CustomRepositories({
|
|
|
}: Props) {
|
|
|
const appStoreConnectContext = useContext(AppStoreConnectContext);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- openDebugFileSourceDialog();
|
|
|
- }, [location.query, appStoreConnectContext]);
|
|
|
-
|
|
|
const orgSlug = organization.slug;
|
|
|
const appStoreConnectSourcesQuantity = repositories.filter(
|
|
|
repository => repository.type === CustomRepoType.APP_STORE_CONNECT
|
|
|
).length;
|
|
|
|
|
|
- function openDebugFileSourceDialog() {
|
|
|
+ const persistData = useCallback(
|
|
|
+ ({
|
|
|
+ updatedItems,
|
|
|
+ updatedItem,
|
|
|
+ index,
|
|
|
+ refresh,
|
|
|
+ }: {
|
|
|
+ index?: number;
|
|
|
+ refresh?: boolean;
|
|
|
+ updatedItem?: CustomRepo;
|
|
|
+ updatedItems?: CustomRepo[];
|
|
|
+ }) => {
|
|
|
+ let items = updatedItems ?? [];
|
|
|
+
|
|
|
+ if (updatedItem && defined(index)) {
|
|
|
+ items = [...repositories];
|
|
|
+ items.splice(index, 1, updatedItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ const {successMessage, errorMessage} = getRequestMessages(
|
|
|
+ items.length,
|
|
|
+ repositories.length
|
|
|
+ );
|
|
|
+
|
|
|
+ const symbolSources = JSON.stringify(items.map(expandKeys));
|
|
|
+
|
|
|
+ const promise: Promise<any> = api.requestPromise(
|
|
|
+ `/projects/${orgSlug}/${project.slug}/`,
|
|
|
+ {
|
|
|
+ method: 'PUT',
|
|
|
+ data: {symbolSources},
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ promise.catch(() => {
|
|
|
+ addErrorMessage(errorMessage);
|
|
|
+ });
|
|
|
+
|
|
|
+ promise.then(result => {
|
|
|
+ ProjectsStore.onUpdateSuccess(result);
|
|
|
+ addSuccessMessage(successMessage);
|
|
|
+
|
|
|
+ if (refresh) {
|
|
|
+ window.location.reload();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return promise;
|
|
|
+ },
|
|
|
+ [api, orgSlug, project.slug, repositories]
|
|
|
+ );
|
|
|
+
|
|
|
+ const handleCloseModal = useCallback(() => {
|
|
|
+ router.push({
|
|
|
+ ...location,
|
|
|
+ query: {
|
|
|
+ ...location.query,
|
|
|
+ customRepository: undefined,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }, [location, router]);
|
|
|
+
|
|
|
+ const openDebugFileSourceDialog = useCallback(() => {
|
|
|
const {customRepository} = location.query;
|
|
|
|
|
|
if (!customRepository) {
|
|
@@ -87,66 +145,19 @@ function CustomRepositories({
|
|
|
persistData({updatedItem: updatedItem as CustomRepo, index: itemIndex}),
|
|
|
onClose: handleCloseModal,
|
|
|
});
|
|
|
- }
|
|
|
-
|
|
|
- function persistData({
|
|
|
- updatedItems,
|
|
|
- updatedItem,
|
|
|
- index,
|
|
|
- refresh,
|
|
|
- }: {
|
|
|
- index?: number;
|
|
|
- refresh?: boolean;
|
|
|
- updatedItem?: CustomRepo;
|
|
|
- updatedItems?: CustomRepo[];
|
|
|
- }) {
|
|
|
- let items = updatedItems ?? [];
|
|
|
-
|
|
|
- if (updatedItem && defined(index)) {
|
|
|
- items = [...repositories];
|
|
|
- items.splice(index, 1, updatedItem);
|
|
|
- }
|
|
|
-
|
|
|
- const {successMessage, errorMessage} = getRequestMessages(
|
|
|
- items.length,
|
|
|
- repositories.length
|
|
|
- );
|
|
|
-
|
|
|
- const symbolSources = JSON.stringify(items.map(expandKeys));
|
|
|
-
|
|
|
- const promise: Promise<any> = api.requestPromise(
|
|
|
- `/projects/${orgSlug}/${project.slug}/`,
|
|
|
- {
|
|
|
- method: 'PUT',
|
|
|
- data: {symbolSources},
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- promise.catch(() => {
|
|
|
- addErrorMessage(errorMessage);
|
|
|
- });
|
|
|
-
|
|
|
- promise.then(result => {
|
|
|
- ProjectsStore.onUpdateSuccess(result);
|
|
|
- addSuccessMessage(successMessage);
|
|
|
-
|
|
|
- if (refresh) {
|
|
|
- window.location.reload();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return promise;
|
|
|
- }
|
|
|
+ }, [
|
|
|
+ appStoreConnectContext,
|
|
|
+ appStoreConnectSourcesQuantity,
|
|
|
+ handleCloseModal,
|
|
|
+ location.query,
|
|
|
+ organization,
|
|
|
+ persistData,
|
|
|
+ repositories,
|
|
|
+ ]);
|
|
|
|
|
|
- function handleCloseModal() {
|
|
|
- router.push({
|
|
|
- ...location,
|
|
|
- query: {
|
|
|
- ...location.query,
|
|
|
- customRepository: undefined,
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
+ useEffect(() => {
|
|
|
+ openDebugFileSourceDialog();
|
|
|
+ }, [location.query, appStoreConnectContext, openDebugFileSourceDialog]);
|
|
|
|
|
|
function handleAddRepository(repoType: CustomRepoType) {
|
|
|
openDebugFileSourceModal({
|