Skip to content

Commit

Permalink
Only add a fulltext when there are text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Jun 20, 2024
1 parent 2a33817 commit 672574c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
2 changes: 2 additions & 0 deletions components/ModelColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@

<div class="sm:col-span-2 relative">
<svg
data-action="addRow"
class="w-6 h-6 inline-block mt-1 cursor-pointer"
fill="currentColor"
viewBox="0 0 20 20"
Expand All @@ -105,6 +106,7 @@
</svg>

<svg
data-action="deleteRow"
class="w-6 h-6 inline-block mt-1 cursor-pointer"
fill="currentColor"
viewBox="0 0 20 20"
Expand Down
22 changes: 22 additions & 0 deletions cypress/e2e/file-output.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,26 @@ describe('Check that the generated output files are correct', () => {
cy.get('.code-contents').contains('implements BlogSearchResultsInterface')
cy.get('.code-contents').contains('extends SearchResults')
})

it('Does not include fulltext when no text fields are added', () => {
cy.enableAdminGrid()
cy.enableSearch()

cy.addField('title', 'Integer')

cy.openFileByPath('etc/db_schema.xml')

cy.get('.code-contents').should('not.contain', 'indexType="fulltext"')
})

it('Does include fulltext when a text field is added', () => {
cy.enableAdminGrid()
cy.enableSearch()

cy.addField('title', 'Text')

cy.openFileByPath('etc/db_schema.xml')

cy.get('.code-contents').should('contain', 'indexType="fulltext"')
})
})
2 changes: 2 additions & 0 deletions cypress/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ declare namespace Cypress {
disableDataModels(): Chainable<any>;
enableAdminGrid(): Chainable<any>;
disableAdminGrid(): Chainable<any>;
enableSearch(): Chainable<any>;
addField(fieldName: string, inputType: string): Chainable<any>;
openFileByPath(filename: string): Chainable<any>;
}
}
12 changes: 11 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ Cypress.Commands.add('disableAdminGrid', () => {
cy.get('[aria-labelledby=module-details] [name="enabled"]').uncheck()
})

Cypress.Commands.add('enableSearch', () => {
cy.get('[aria-labelledby=module-details] [name="search"]').check()
})

Cypress.Commands.add('addField', (fieldName: string, inputType: string) => {
cy.get('[data-action="addRow"]').last().click()
cy.get('[name="fieldname"]').last().type(fieldName)
cy.get('[name="input_type"]').last().select(inputType)
})

Cypress.Commands.add('openFileByPath', (fileName: string) => {
let selector = ''
const parts = fileName.split('/')
Expand All @@ -73,7 +83,7 @@ Cypress.Commands.add('openFileByPath', (fileName: string) => {
(part.includes('.') ? `> .is-file-${filename} a` : `.is-dir-${part} > ul`)
})

selector = selector.toLowerCase();
selector = selector.toLowerCase()

cy.log('Path', fileName)
cy.log('Selector', selector)
Expand Down
16 changes: 13 additions & 3 deletions output/listing/DbSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,23 @@ export default class DbSchema extends StateAware implements GeneratesFileInterfa
}

private addSearchField(xml: XMLDocument, table: HTMLTableElement) {
let textColumns = this.columns().filter((data: ColumnInterface) => {
return data.inputType === 'varchar' || data.inputType === 'text';
});

if (textColumns.length === 0) {
return;
}

const index = xml.createElement('index')
index.setAttribute('referenceId', this.getIndexField())
index.setAttribute('indexType', 'fulltext')
table.appendChild(index)

const column = xml.createElement('column')
column.setAttribute('name', this.indexField())
index.appendChild(column)
textColumns.forEach((data: ColumnInterface) => {
const column = xml.createElement('column')
column.setAttribute('name', data.fieldName)
index.appendChild(column)
})
}
}

0 comments on commit 672574c

Please sign in to comment.