Skip to content

Commit

Permalink
don't allow create or update connection with duplicate name (#486)
Browse files Browse the repository at this point in the history
* don't allow create or update connection with duplicate name

* update toast message

Co-authored-by: kunzheng <58841788+kunzms@users.noreply.github.com>
  • Loading branch information
yongbing-chen and kunzms authored Aug 17, 2020
1 parent f54d098 commit a8ef8fa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/common/localization/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export const english: IAppStrings = {
messages: {
saveSuccess: "Successfully saved ${connection.name}",
deleteSuccess: "Successfully deleted ${connection.name}",
doNotAllowDuplicateNames: "Connection with name \"${connection.name}\" already exists. Please, use another name"
},
imageCorsWarning: "Warning: When using VoTT in a Web browser, some assets from Bing Image \
Search may not export correctly due to CORS (Cross Origin Resource Sharing) restrictions.",
Expand Down
1 change: 1 addition & 0 deletions src/common/localization/es-cl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export const spanish: IAppStrings = {
messages: {
saveSuccess: "${connection.name} guardado correctamente",
deleteSuccess: "${connection.name} eliminado correctamente",
doNotAllowDuplicateNames: "La conexión con el nombre \"${connection.name}\" ya existe. Por favor, use otro nombre"
},
imageCorsWarning: "Advertencia: Cuando se usa VoTT en un navegador web, es posible que algunos activos de este \
Búsqueda de Imágenes Bing no se exporten correctamente debido a las restricciones de CORS \
Expand Down
1 change: 1 addition & 0 deletions src/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export interface IAppStrings {
messages: {
saveSuccess: string;
deleteSuccess: string;
doNotAllowDuplicateNames:string;
},
imageCorsWarning: string;
blobCorsWarning: string;
Expand Down
15 changes: 12 additions & 3 deletions src/react/components/pages/connections/connectionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,19 @@ export default class ConnectionPage extends React.Component<IConnectionPageProps
if (connection.providerType === "azureBlobStorage") {
connection.providerOptions["sas"] = connection.providerOptions["sas"].trim();
}
await this.props.actions.saveConnection(connection);
toast.success(interpolate(strings.connections.messages.saveSuccess, { connection }));

this.props.history.push("/connections");
// don't allow use the same name create the duplicate connections.
// don't allow update the connection name same as other connections.
if ((!connection.id && this.props.connections.find(a => a.name === connection.name))
|| (connection.id && this.props.connections.find(a => a.name === connection.name && a.id !== connection.id))) {
toast.error(interpolate(strings.connections.messages.doNotAllowDuplicateNames, { connection }), { autoClose: 10000 });
} else {
await this.props.actions.saveConnection(connection);
toast.success(interpolate(strings.connections.messages.saveSuccess, { connection }));

this.props.history.push("/connections");
}

} catch (error) {
alert(error);
}
Expand Down

0 comments on commit a8ef8fa

Please sign in to comment.