Skip to content

Commit

Permalink
Fix input focus loss
Browse files Browse the repository at this point in the history
  • Loading branch information
dzsak committed Mar 25, 2024
1 parent 120b73a commit b45de7a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions pkg/dashboard/worker/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,10 +1269,12 @@ func imagepullSecretTemplate(
encryptedConfigString = encryptedConfig.(string)
}

secretName := fmt.Sprintf("%s-pullsecret", strings.ToLower(registryString))
return sync.GenerateImagePullSecret(
manifest.Env,
manifest.App,
manifest.Namespace,
secretName,
encryptedConfigString,
repoPerEnv,
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gitops/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func GenerateKustomizationForApp(
}

func GenerateImagePullSecret(
env, app, namespace string,
env, app, namespace, name string,
encryptedDockerconfigjson string,
singleEnv bool,
) (*manifestgen.Manifest, error) {
Expand All @@ -279,7 +279,7 @@ func GenerateImagePullSecret(
APIVersion: "bitnami.com/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "regcred",
Name: name,
Namespace: namespace,
Annotations: map[string]string{
"sealedsecrets.bitnami.com/cluster-wide": "true",
Expand Down
13 changes: 11 additions & 2 deletions web/dashboard/src/views/envConfig/envConfig.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class EnvConfig extends Component {

this.setValues = this.setValues.bind(this);
this.resetNotificationStateAfterThreeSeconds = this.resetNotificationStateAfterThreeSeconds.bind(this);
this.imageWidget = this.imageWidget.bind(this);
this.setImagePullSecret = this.setImagePullSecret.bind(this);
}

Expand Down Expand Up @@ -465,12 +466,16 @@ class EnvConfig extends Component {
}

setImagePullSecret(secret) {
let secretArray = [secret];
if (secret === "") {
secretArray = []
}
this.setState(prevState => ({
configFile: {
...prevState.configFile,
values: {
...prevState.configFile.values,
imagePullSecrets: [secret]
imagePullSecrets: secretArray
}
}
}));
Expand Down Expand Up @@ -545,6 +550,10 @@ class EnvConfig extends Component {
// });
// };

imageWidget(props) {
return <ImageWidget {...props} setImagePullSecret={this.setImagePullSecret} registry={filterRegistry(this.state.stackConfig, this.state.stackDefinition)} />
}

render() {
const { owner, repo, env, config, action } = this.props.match.params;
const repoName = `${owner}/${repo}`
Expand All @@ -564,7 +573,7 @@ class EnvConfig extends Component {
}

const customFields = {
imageWidget: (props) => <ImageWidget {...props} setImagePullSecret={this.setImagePullSecret} registry={filterRegistry(this.state.stackConfig, this.state.stackDefinition)} />,
imageWidget: this.imageWidget,
sealedSecretWidget: (props) => <SealedSecretWidget {...props} gimletClient={this.props.gimletClient} store={this.props.store} env={env} />,
}

Expand Down
19 changes: 8 additions & 11 deletions web/dashboard/src/views/envConfig/imageWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class ImageWidget extends Component {
};
}

// TODO bug input field loses focus on writing
componentDidMount() {
this.props.setImagePullSecret("regcred")
}

defaults(strategy) {
let repository = ""
let tag = ""
Expand Down Expand Up @@ -68,24 +63,26 @@ class ImageWidget extends Component {
return (event) => {
const { registry } = this.props;
const login = registry[event.target.value].login ?? "your-company"
let repository = "";

switch (event.target.value) {
case 'dockerhubRegistry':
repository = `${login}/{{ .APP }}`
this.setState({ repository: `${login}/{{ .APP }}` })
this.props.setImagePullSecret("dockerhubregistry-pullsecret")
break;
case 'ghcrRegistry':
repository = `ghcr.io/${login}/{{ .APP }}`
this.setState({ repository: `ghcr.io/${login}/{{ .APP }}` })
this.props.setImagePullSecret("ghcrregistry-pullsecret")
break;
default:
repository = "127.0.0.1:32447/{{ .APP }}"
this.setState({ repository: "127.0.0.1:32447/{{ .APP }}" })
this.props.setImagePullSecret("")
}

this.setState(
{
[name]: event.target.value,
},
() => this.props.onChange({"repository": repository, "tag": this.state.tag, "dockerfile": this.state.dockerfile, "strategy": this.state.strategy, "registry": this.state.registry })
() => this.props.onChange({"repository": this.state.repository, "tag": this.state.tag, "dockerfile": this.state.dockerfile, "strategy": this.state.strategy, "registry": this.state.registry })
);
};
}
Expand Down Expand Up @@ -185,7 +182,7 @@ class ImageWidget extends Component {
>
{
Object.keys(registry).map((item, idx) => {
if (!registry[item].hasOwnProperty("enabled")) {
if (!registry[item]?.hasOwnProperty("enabled")) {
return null
}

Expand Down

0 comments on commit b45de7a

Please sign in to comment.