@@ -6,18 +6,14 @@ import { action } from "@ember/object";
66import didInsert from " @ember/render-modifiers/modifiers/did-insert" ;
77import didUpdate from " @ember/render-modifiers/modifiers/did-update" ;
88import { service } from " @ember/service" ;
9- import { isEmpty } from " @ember/utils" ;
109import AceEditor from " discourse/components/ace-editor" ;
1110import BackButton from " discourse/components/back-button" ;
1211import DButton from " discourse/components/d-button" ;
1312import DTooltip from " discourse/components/d-tooltip" ;
14- import InputTip from " discourse/components/input-tip" ;
1513import withEventValue from " discourse/helpers/with-event-value" ;
1614import { popupAjaxError } from " discourse/lib/ajax-error" ;
17- import discourseDebounce from " discourse-common/lib/debounce" ;
1815import I18n from " discourse-i18n" ;
1916import ComboBox from " select-kit/components/combo-box" ;
20- import AiTool from " ../admin/models/ai-tool" ;
2117import AiToolParameterEditor from " ./ai-tool-parameter-editor" ;
2218import AiToolTestModal from " ./modal/ai-tool-test-modal" ;
2319import RagOptions from " ./rag-options" ;
@@ -34,15 +30,11 @@ export default class AiToolEditor extends Component {
3430 @service store;
3531 @service siteSettings;
3632
37- @tracked toolName = null ;
3833 @tracked isSaving = false ;
3934 @tracked editingModel = null ;
4035 @tracked showDelete = false ;
4136 @tracked selectedPreset = null ;
4237
43- @tracked disableSave = null ;
44- @tracked nameValidation = null ;
45-
4638 get presets () {
4739 return this .args .presets .map ((preset ) => {
4840 return {
@@ -60,7 +52,6 @@ export default class AiToolEditor extends Component {
6052 updateModel () {
6153 this .editingModel = this .args .model .workingCopy ();
6254 this .showDelete = ! this .args .model .isNew ;
63- this .toolName = this .editingModel .tool_name ;
6455 }
6556
6657 @action
@@ -69,7 +60,6 @@ export default class AiToolEditor extends Component {
6960 this .editingModel = this .store
7061 .createRecord (" ai-tool" , this .selectedPreset )
7162 .workingCopy ();
72-
7363 this .showDelete = false ;
7464 }
7565
@@ -86,34 +76,6 @@ export default class AiToolEditor extends Component {
8676 }
8777 }
8878
89- @action
90- validateAndUpdateToolName (value ) {
91- // Skip validation if name hasn't changed
92- if (value === this .jobName ) {
93- this ._failedInputValidation (" " );
94- this .disableSave = false ;
95- return ;
96- }
97-
98- this .editingModel .tool_name = value;
99-
100- if (value === undefined ) {
101- return this ._failedInputValidation ();
102- }
103-
104- if (isEmpty (value)) {
105- return this ._failedInputValidation (
106- I18n .t (" discourse_ai.tools.new.tool_name.blank" )
107- );
108- }
109-
110- this ._checkToolNameDebounced ();
111-
112- return this ._failedInputValidation (
113- I18n .t (" discourse_ai.tools.new.tool_name.checking" )
114- );
115- }
116-
11779 _checkToolNameDebounced () {
11880 discourseDebounce (this , this ._checkToolName , 500 );
11981 }
@@ -200,20 +162,6 @@ export default class AiToolEditor extends Component {
200162 });
201163 }
202164
203- get disableSaveButton () {
204- return this .disableSave || this .isSaving ;
205- }
206-
207- _failedInputValidation (reason ) {
208- this .disableSave = true ;
209- const options = { failed: true };
210- if (reason) {
211- options .reason = reason;
212- }
213- this .nameValidation = options;
214- return options;
215- }
216-
217165 <template >
218166 <BackButton
219167 @ route =" adminPlugins.show.discourse-ai-tools"
@@ -260,7 +208,10 @@ export default class AiToolEditor extends Component {
260208 <div class =" control-group" >
261209 <label >{{I18n.t " discourse_ai.tools.tool_name" }} </label >
262210 <input
263- {{on " input" ( withEventValue this . validateAndUpdateToolName) }}
211+ {{on
212+ " input"
213+ ( withEventValue ( fn ( mut this . editingModel.tool_name) ) )
214+ }}
264215 value ={{this .editingModel.tool_name }}
265216 type =" text"
266217 class =" ai-tool-editor__tool_name"
@@ -269,7 +220,6 @@ export default class AiToolEditor extends Component {
269220 @ icon =" question-circle"
270221 @ content ={{I18n.t " discourse_ai.tools.tool_name_help" }}
271222 />
272- <InputTip @ validation ={{this .nameValidation }} />
273223 </div >
274224
275225 <div class =" control-group" >
@@ -335,7 +285,7 @@ export default class AiToolEditor extends Component {
335285 <DButton
336286 @ action ={{this .save }}
337287 @ label =" discourse_ai.tools.save"
338- @ disabled ={{this .disableSaveButton }}
288+ @ disabled ={{this .isSaving }}
339289 class =" btn-primary ai-tool-editor__save"
340290 />
341291
0 commit comments