diff --git a/.github/workflows/featureDeploy.yml b/.github/workflows/featureDeploy.yml index acd59b32..7e77d25c 100644 --- a/.github/workflows/featureDeploy.yml +++ b/.github/workflows/featureDeploy.yml @@ -30,10 +30,10 @@ jobs: strategy: matrix: environment: ${{ fromJSON(needs.detect-environments.outputs.environments) }} - if: ${{ matrix.environment != 'production' }} + if: ${{ inputs.environment != 'production' }} uses: ./.github/workflows/deploy.yml with: - environment: '${{ matrix.environment }}' + environment: '${{ inputs.environment }}' secrets: inherit diff --git a/src/assets/js/list-filter.js b/src/assets/js/list-filter.js index edc18066..02b0a2d9 100644 --- a/src/assets/js/list-filter.js +++ b/src/assets/js/list-filter.js @@ -5,6 +5,8 @@ /* eslint-disable no-var */ //= require govuk_publishing_components/vendor/polyfills/closest +const keyPauseTime = 20 + window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {}; @@ -34,7 +36,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; clearTimeout(this.filterTimeout) this.filterTimeout = setTimeout(function () { this.$module.filterList(searchTerm) - }.bind(this), 200) + }.bind(this), keyPauseTime) }.bind(this)) } diff --git a/src/controllers/OrganisationsController.js b/src/controllers/OrganisationsController.js index 5b65911c..c4d388fc 100644 --- a/src/controllers/OrganisationsController.js +++ b/src/controllers/OrganisationsController.js @@ -1,3 +1,4 @@ +import datasette from '../services/datasette.js' import performanceDbApi from '../services/performanceDbApi.js' // Assume you have an API service module import logger from '../utils/logger.js' import { dataSubjects } from '../utils/utils.js' @@ -70,85 +71,36 @@ const organisationsController = { } }, + /** + * Handles the GET /organisations request + * + * @param {Request} req + * @param {Response} res + * @param {NextFunction} next + */ async getOrganisations (req, res, next) { - const alphabetisedOrgs = { - A: [ - { - name: 'Aberdeen' - }, - { - name: 'Aylesbury' - }, - { - name: 'Ashford' - } - ], - B: [ - { - name: 'Bath' - }, - { - name: 'Birmingham' - }, - { - name: 'Brighton' - } - ], - C: [ - { - name: 'Cambridge' - }, - { - name: 'Cardiff' - }, - { - name: 'Cheltenham' - }, - { - name: 'Chester' - } - ], - D: [ - { - name: 'Derby' - }, - { - name: 'Dundee' - } - ], - E: [ - { - name: 'Edinburgh' - }, - { - name: 'Epsom' - } - ], - G: [ - { - name: 'Glasgow' - }, - { - name: 'Gloucester' - } - ], - H: [ - { - name: 'Hull' - } - ], - L: [ - { - name: 'Leeds' - }, - { - name: 'London' - } - ] - } + try { + const sql = 'select name, organisation from organisation' + const result = await datasette.runQuery(sql) + + const sortedResults = result.formattedData.sort((a, b) => { + return a.name.localeCompare(b.name) + }) - res.render('organisations/find.html', { alphabetisedOrgs }) + const alphabetisedOrgs = sortedResults.reduce((acc, current) => { + const firstLetter = current.name.charAt(0).toUpperCase() + acc[firstLetter] = acc[firstLetter] || [] + acc[firstLetter].push(current) + return acc + }, {}) + + res.render('organisations/find.html', { alphabetisedOrgs }) + } catch (err) { + logger.warn(err) + next(err) + } } + } export default organisationsController diff --git a/src/views/organisations/find.html b/src/views/organisations/find.html index 6db1c7ff..ffd58b8e 100644 --- a/src/views/organisations/find.html +++ b/src/views/organisations/find.html @@ -29,7 +29,6 @@