Skip to content

Commit d0e7cdb

Browse files
authored
Fix gitlab configuration flow for custom instance urls (#308)
* Fix gitlab configuration flow for custom instance urls * bring back divider
1 parent f44376f commit d0e7cdb

File tree

3 files changed

+73
-89
lines changed

3 files changed

+73
-89
lines changed

integrations/github/src/components.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ export const configBlock = createComponent<
435435
!element.state.repository ||
436436
!element.state.branch
437437
}
438-
label="Configure"
439-
tooltip="Save configuration"
438+
label="Sync"
439+
tooltip="Start the initial synchronization"
440440
onPress={{ action: 'save.config' }}
441441
/>
442442
}

integrations/gitlab/src/components.tsx

+70-84
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const configBlock = createComponent<
3030
componentId: 'configure',
3131
initialState: (props) => {
3232
return {
33-
withConnectGitLab: props.spaceInstallation.configuration?.accessToken !== undefined,
3433
accessToken: props.spaceInstallation.configuration?.accessToken,
3534
withCustomInstanceUrl: Boolean(
3635
props.spaceInstallation.configuration?.customInstanceUrl &&
@@ -55,15 +54,6 @@ export const configBlock = createComponent<
5554
},
5655
action: async (element, action, context) => {
5756
switch (action.action) {
58-
case 'connect.gitlab': {
59-
return {
60-
...element,
61-
state: {
62-
...element.state,
63-
withConnectGitLab: action.withConnectGitLab,
64-
},
65-
};
66-
}
6757
case 'save.token': {
6858
const spaceInstallation = context.environment.spaceInstallation;
6959
assertIsDefined(spaceInstallation, { label: 'spaceInstallation' });
@@ -72,6 +62,7 @@ export const configBlock = createComponent<
7262
...spaceInstallation.configuration,
7363
key: crypto.randomUUID(),
7464
accessToken: action.token,
65+
customInstanceUrl: action.customInstanceUrl,
7566
};
7667

7768
const glUser = await getCurrentUser(updatedConfig);
@@ -182,85 +173,80 @@ export const configBlock = createComponent<
182173

183174
return (
184175
<block>
185-
<input
186-
label="Connect your GitLab account"
187-
hint={
188-
<text>
189-
The access token requires the{' '}
190-
<text style="bold">api, read_repository, write_repository</text> scope
191-
for the integration to work. You can create one at{' '}
192-
<link
193-
target={{
194-
url: 'https://gitlab.com/-/profile/personal_access_tokens',
195-
}}
196-
>
197-
User Settings → Access Tokens.
198-
</link>
199-
</text>
200-
}
201-
element={
202-
<button
203-
label="Connect"
204-
icon={ContentKitIcon.Gitlab}
205-
disabled={element.state.withConnectGitLab}
206-
tooltip="Connect your GitLab account"
207-
onPress={{
208-
action: 'connect.gitlab',
209-
withConnectGitLab: true,
210-
}}
211-
/>
212-
}
213-
/>
214-
215-
{element.state.withConnectGitLab ? (
216-
<hstack>
176+
<card>
177+
<vstack>
217178
<box grow={1}>
218-
<textinput
219-
state="accessToken"
220-
placeholder="Enter your GitLab access token"
221-
/>
222-
</box>
223-
<button
224-
style="secondary"
225-
tooltip="Save access token"
226-
label="Save"
227-
onPress={{
228-
action: 'save.token',
229-
token: element.dynamicState('accessToken'),
230-
}}
231-
/>
232-
</hstack>
233-
) : null}
234-
235-
{accessToken ? (
236-
<>
237-
<divider size="medium" />
238-
239-
<vstack>
240179
<input
241-
label="Custom GitLab URL"
242-
hint="If your GitLab instance is self-hosted, enter its publicly accessible URL"
180+
label="GitLab access token"
181+
hint={
182+
<text>
183+
The access token requires the{' '}
184+
<text style="bold">
185+
api, read_repository, write_repository
186+
</text>{' '}
187+
scope for the integration to work. You can create one at{' '}
188+
<link
189+
target={{
190+
url: 'https://gitlab.com/-/profile/personal_access_tokens',
191+
}}
192+
>
193+
User Settings → Access Tokens.
194+
</link>
195+
</text>
196+
}
243197
element={
244-
<switch
245-
state="withCustomInstanceUrl"
246-
onValueChange={{
247-
action: 'toggle.customInstanceUrl',
248-
withCustomInstanceUrl:
249-
element.dynamicState('withCustomInstanceUrl'),
250-
}}
198+
<textinput
199+
state="accessToken"
200+
placeholder="xxxxxxxxxxxxxxxxxxxx"
251201
/>
252202
}
253203
/>
254-
{element.state.withCustomInstanceUrl ? (
255-
<box grow={1}>
256-
<textinput
257-
state="customInstanceUrl"
258-
placeholder="https://gitlab.mycompany.com"
259-
/>
260-
</box>
261-
) : null}
262-
</vstack>
204+
</box>
205+
206+
<input
207+
label="Custom GitLab URL"
208+
hint="If your GitLab instance is self-hosted, enter its publicly accessible URL"
209+
element={
210+
<switch
211+
state="withCustomInstanceUrl"
212+
onValueChange={{
213+
action: 'toggle.customInstanceUrl',
214+
withCustomInstanceUrl:
215+
element.dynamicState('withCustomInstanceUrl'),
216+
}}
217+
/>
218+
}
219+
/>
220+
{element.state.withCustomInstanceUrl ? (
221+
<box grow={1}>
222+
<textinput
223+
state="customInstanceUrl"
224+
placeholder="https://gitlab.mycompany.com"
225+
/>
226+
</box>
227+
) : null}
263228

229+
<box grow={1}>
230+
<hstack align="end">
231+
<button
232+
style="secondary"
233+
icon={ContentKitIcon.Gitlab}
234+
tooltip="Authenticate with GitLab"
235+
label="Authenticate"
236+
onPress={{
237+
action: 'save.token',
238+
token: element.dynamicState('accessToken'),
239+
customInstanceUrl:
240+
element.dynamicState('customInstanceUrl'),
241+
}}
242+
/>
243+
</hstack>
244+
</box>
245+
</vstack>
246+
</card>
247+
248+
{accessToken ? (
249+
<>
264250
<divider size="medium" />
265251

266252
<markdown content="### Project" />
@@ -472,8 +458,8 @@ export const configBlock = createComponent<
472458
!element.state.project ||
473459
!element.state.branch
474460
}
475-
label="Configure"
476-
tooltip="Save configuration"
461+
label="Sync"
462+
tooltip="Start the initial synchronization"
477463
onPress={{ action: 'save.configuration' }}
478464
/>
479465
}

integrations/gitlab/src/types.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export type GitLabRuntimeEnvironment = RuntimeEnvironment<{}, GitLabSpaceConfigu
1010
export type GitLabRuntimeContext = RuntimeContext<GitLabRuntimeEnvironment>;
1111

1212
export type GitlabConfigureAction =
13-
| { action: 'connect.gitlab'; withConnectGitLab: boolean }
14-
| { action: 'save.token'; token: string }
13+
| { action: 'save.token'; token: string; customInstanceUrl?: string }
1514
| { action: 'select.project'; project: string }
1615
| { action: 'select.branch'; branch: string }
1716
| { action: 'toggle.customTemplate'; withCustomTemplate: boolean }
@@ -70,7 +69,6 @@ export type GitlabConfigureProps = {
7069

7170
export type GitlabConfigureState = Omit<SpaceInstallationConfiguration, 'project'> & {
7271
project?: string;
73-
withConnectGitLab?: boolean;
7472
withCustomTemplate?: boolean;
7573
withCustomInstanceUrl?: boolean;
7674
commitMessagePreview?: string;

0 commit comments

Comments
 (0)