mirror of https://github.com/portainer/portainer
feat(k8s/config): disable edit used config keys (#4754)
* feat(k8s/config): tag used data keys * feat(k8s/config): disabled edit of used data keyspull/4889/head
parent
c84da11a91
commit
20f8d03366
|
@ -45,8 +45,9 @@
|
|||
id="configuration_data_key_{{ index }}"
|
||||
name="configuration_data_key_{{ index }}"
|
||||
ng-model="$ctrl.formValues.Data[index].Key"
|
||||
ng-disabled="entry.Used"
|
||||
required
|
||||
ng-change="$ctrl.onChangeKey()"
|
||||
ng-change="$ctrl.onChangeKey(entry)"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
|
@ -90,9 +91,13 @@
|
|||
<div class="form-group" ng-if="$ctrl.formValues.IsSimple">
|
||||
<div class="col-sm-1"></div>
|
||||
<div class="col-sm-11">
|
||||
<button type="button" class="btn btn-sm btn-danger" style="margin-left: 0;" ng-click="$ctrl.removeEntry(index)">
|
||||
<button type="button" class="btn btn-sm btn-danger space-right" style="margin-left: 0;" ng-disabled="entry.Used" ng-click="$ctrl.removeEntry(index, entry)">
|
||||
<i class="fa fa-trash-alt" aria-hidden="true"></i> Remove entry
|
||||
</button>
|
||||
<span class="small text-muted" ng-if="entry.Used">
|
||||
<i class="fa fa-info-circle blue-icon space-right" aria-hidden="true"></i>
|
||||
This key is currently used by one or more applications
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -19,7 +19,11 @@ class KubernetesConfigurationDataController {
|
|||
this.showAdvancedMode = this.showAdvancedMode.bind(this);
|
||||
}
|
||||
|
||||
onChangeKey() {
|
||||
onChangeKey(entry) {
|
||||
if (entry.Used) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.state.duplicateKeys = KubernetesFormValidationHelper.getDuplicates(_.map(this.formValues.Data, (data) => data.Key));
|
||||
this.isValid = Object.keys(this.state.duplicateKeys).length === 0;
|
||||
}
|
||||
|
@ -28,7 +32,11 @@ class KubernetesConfigurationDataController {
|
|||
this.formValues.Data.push(new KubernetesConfigurationFormValuesEntry());
|
||||
}
|
||||
|
||||
removeEntry(index) {
|
||||
removeEntry(index, entry) {
|
||||
if (entry.Used) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.formValues.Data.splice(index, 1);
|
||||
this.onChangeKey();
|
||||
}
|
||||
|
|
|
@ -204,6 +204,23 @@ class KubernetesConfigurationController {
|
|||
return this.$async(this.getConfigurationsAsync);
|
||||
}
|
||||
|
||||
tagUsedDataKeys() {
|
||||
const configName = this.$transition$.params().name;
|
||||
const usedDataKeys = _.uniq(
|
||||
this.configuration.Applications.flatMap((app) =>
|
||||
app.Env.filter((e) => e.valueFrom && e.valueFrom.configMapKeyRef && e.valueFrom.configMapKeyRef.name === configName).map((e) => e.name)
|
||||
)
|
||||
);
|
||||
|
||||
this.formValues.Data = this.formValues.Data.map((variable) => {
|
||||
if (!usedDataKeys.includes(variable.Key)) {
|
||||
return variable;
|
||||
}
|
||||
|
||||
return { ...variable, Used: true };
|
||||
});
|
||||
}
|
||||
|
||||
async onInit() {
|
||||
try {
|
||||
this.state = {
|
||||
|
@ -228,6 +245,8 @@ class KubernetesConfigurationController {
|
|||
await this.getApplications(this.configuration.Namespace);
|
||||
await this.getEvents(this.configuration.Namespace);
|
||||
await this.getConfigurations();
|
||||
|
||||
this.tagUsedDataKeys();
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to load view data');
|
||||
} finally {
|
||||
|
|
Loading…
Reference in New Issue