8000 allow creating updating ai-document, change source base node to objec… by mrfinch · Pull Request #7877 · codecombat/codecombat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

allow creating updating ai-document, change source base node to objec… #7877

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

Merged
merged 1 commit into from
Dec 18, 2024
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
6 changes: 5 additions & 1 deletion app/schemas/models/ai_document.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ _.extend(AIDocumentSchema.properties, {
format: 'document-by-type',
additionalProperties: true,
properties: {
type: { type: 'string', title: 'Type', description: 'The type of document' },
type: { type: 'string', title: 'Type', description: 'The type of document: html, link etc' },
text: { type: 'string', title: 'Text', description: 'The document text source' },
filePath: { type: 'string', title: 'File Path', description: 'The file path of the document' },
blob: { type: 'string', title: 'Blob', description: 'The blob source of the document' },
i18n: { type: 'object', format: 'i18n', props: ['text'], description: 'Help translate this property' },
url: { type: 'string', title: 'URL', description: 'The URL of the document' },
preText: { type: 'string', title: 'Pre Text', description: 'The pre text of the document' },
postText: { type: 'string', title: 'Post Text', description: 'The post text of the document' },
linkText: { type: 'string', title: 'Link Text', description: 'The text of the link' },
},
},
})
Expand Down
7 changes: 4 additions & 3 deletions app/templates/editor/modal/new-model-modal.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ block modal-header-content

block modal-body-content
form.form
.form-group
label.control-label(for="name", data-i18n="general.name") Name
input#name.form-control(name="name", type="text")
if !view.hasNoNameProperty
.form-group
label.control-label(for="name", data-i18n="general.name") Name
input#name.form-control(name="name", type="text")

block modal-footer
.modal-footer
Expand Down
5 changes: 3 additions & 2 deletions app/views/common/SearchView.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ module.exports = (SearchView = (function () {
super(options)
this.runSearch = this.runSearch.bind(this)
this.runSearch = _.debounce(this.runSearch, 500)
this.modelProperties = options.modelProperties || {}
this.modelProperties = options.modelProperties || this.modelProperties || {}
this.hasNoNameProperty = options.hasNoNameProperty || this.hasNoNameProperty
}

afterRender () {
Expand Down Expand Up @@ -141,7 +142,7 @@ module.exports = (SearchView = (function () {
}

newModel (e) {
const modal = new NewModelModal({ model: this.model, modelLabel: this.modelLabel, properties: this.modelProperties })
const modal = new NewModelModal({ model: this.model, modelLabel: this.modelLabel, properties: this.modelProperties, hasNoNameProperty: this.hasNoNameProperty })
modal.once('model-created', this.onNewModelSaved)
return this.openModalView(modal)
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/editor/ai-document/AIDocumentEditView.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module.exports = (AIDocumentEditView = (function () {
return AIDocumentEditView
})())

class DocumentByTypeNode extends TreemaNode.nodeMap.string {
class DocumentByTypeNode extends TreemaNode.nodeMap.object {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined 'TreemaNode': Ensure 'TreemaNode' is Imported or Defined

At line 138, 'TreemaNode' is not defined, which will result in a reference error. Please import or define 'TreemaNode' before using it.

Apply this diff to import 'TreemaNode':

+ const TreemaNode = require('path/to/treema');

Ensure the correct path is used for the import based on your project structure.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 eslint

[error] 138-138: 'TreemaNode' is not defined.

(no-undef)

buildValueForDisplay (valEl, data) {
super.buildValueForDisplay(valEl, data)

Expand Down
10 changes: 8 additions & 2 deletions app/views/editor/ai-document/AIDocumentSearchView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ module.exports = (AIDocumentSearchView = (function () {
AIDocumentSearchView = class AIDocumentSearchView extends SearchView {
static initClass () {
this.prototype.id = 'editor-ai-document-home-view'
this.prototype.modelLabel = 'Document'
this.prototype.modelLabel = 'AI Document'
this.prototype.model = require('models/AIDocument')
this.prototype.modelURL = '/db/ai_document'
this.prototype.tableTemplate = require('app/templates/editor/ai-document/table')
this.prototype.projection = ['type', 'source']
this.prototype.page = 'ai-document'
this.prototype.canMakeNew = false
this.prototype.canMakeNew = true
this.prototype.hasNoNameProperty = true
this.prototype.modelProperties = {
source: {
type: 'link',
},
}
Comment on lines +17 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace 'this' with Class Name in Static Method to Avoid Confusion

Using this inside a static method can be misleading since this refers to the class itself. It's clearer and more maintainable to use the class name directly when assigning prototype properties.

Apply this diff to replace this with the class name:

- this.prototype.id = 'editor-ai-document-home-view'
- this.prototype.modelLabel = 'AI Document'
- this.prototype.canMakeNew = true
- this.prototype.hasNoNameProperty = true
- this.prototype.modelProperties = {
+ AIDocumentSearchView.prototype.id = 'editor-ai-document-home-view'
+ AIDocumentSearchView.prototype.modelLabel = 'AI Document'
+ AIDocumentSearchView.prototype.canMakeNew = true
+ AIDocumentSearchView.prototype.hasNoNameProperty = true
+ AIDocumentSearchView.prototype.modelProperties = {
    source: {
      type: 'link',
    },
  }

This change will also resolve the linter errors reported by Biome regarding the use of this in a static context.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Biome (1.9.4)

[error] 17-17: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 18-18: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 19-19: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 20-20: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 21-21: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 22-22: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 23-23: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 24-24: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 25-25: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


this.prototype.events =
{ 'click #delete-button': 'deleteAIDocument' }
Expand Down
6 changes: 5 additions & 1 deletion app/views/editor/modal/NewModelModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ module.exports = (NewModelModal = (function () {
this.modelLabel = options.modelLabel
this.newModelTitle = `editor.new_${_.string.slugify(this.modelLabel)}_title`
this.properties = options.properties
this.hasNoNameProperty = options.hasNoNameProperty
}

makeNewModel () {
const model = new this.modelClass()
const name = this.$el.find('#name').val()
model.set('name', name)

if (!this.hasNoNameProperty) {
model.set('name', name)
}
if (this.modelClass.name === 'Level') {
model.set('tasks', this.modelClass.schema.default.tasks)
}
Expand Down
Loading
0