Skip to content
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

Allow editing connection nicknames #3352

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions mathesar_ui/src/api/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ interface ConnectionWithPassword extends Connection {
password: string;
}

export type UpdatableConnectionProperties = Omit<
ConnectionWithPassword,
'id' | 'nickname'
>;
export type UpdatableConnectionProperties = Omit<ConnectionWithPassword, 'id'>;

function list() {
return getAPI<PaginatedResponse<Connection>>(
Expand Down
30 changes: 16 additions & 14 deletions mathesar_ui/src/systems/connections/EditConnectionModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import {
ControlledModal,
type ModalController,
TextInput,
PasswordInput,
} from '@mathesar-component-library';
import { connectionsStore } from '@mathesar/stores/databases';
Expand All @@ -18,6 +17,7 @@
optionalField,
Field,
FieldLayout,
uniqueWith,
} from '@mathesar/components/form';
import DocsLink from '@mathesar/components/DocsLink.svelte';
import { toast } from '@mathesar/stores/toast';
Expand All @@ -26,21 +26,26 @@
export let controller: ModalController;
export let connection: Connection;

$: connectionName = requiredField(connection?.nickname ?? '');
$: databaseName = requiredField(connection?.database ?? '');
$: host = requiredField(connection?.host ?? '');
$: port = requiredField(connection?.port ?? 5432, [isInPortRange()]);
$: username = requiredField(connection?.username ?? '');
$: ({ connections } = connectionsStore);
$: otherNicknames = new Set(
$connections.filter((c) => c.id !== connection.id).map((c) => c.nickname),
);
$: connectionName = requiredField(connection.nickname, [
uniqueWith(otherNicknames),
]);
$: databaseName = requiredField(connection.database);
$: host = requiredField(connection.host);
$: port = requiredField(connection.port ?? 5432, [isInPortRange()]);
$: username = requiredField(connection.username);
$: password = optionalField('');

$: formFields = {
$: form = makeForm({
connectionName,
databaseName,
host,
port,
username,
password,
};
$: form = makeForm(formFields);
});

async function save() {
const formValues = $form.values;
Expand All @@ -53,6 +58,7 @@
port: formValues.port,
username: formValues.username,
password: passwordValue,
nickname: formValues.connectionName,
});
toast.success($_('connection_updated_successfully'));
controller.close();
Expand Down Expand Up @@ -80,10 +86,6 @@
<Field
label={$_('connection_name')}
field={connectionName}
input={{
component: TextInput,
props: { disabled: true },
}}
layout="stacked"
/>
<hr />
Expand Down
Loading