Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSurgisonGDS committed Aug 29, 2023
1 parent 10de331 commit 1d5968b
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const {
managePluginsPagePath,
getTemplateLink,
loadInstalledPluginsPage,
loadPluginsPage, manageInstalledPluginsPagePath
loadPluginsPage,
manageInstalledPluginsPagePath
} = require('../plugin-utils')
const { showHideAllLinkQuery, assertVisible, assertHidden } = require('../../step-by-step-utils')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Handle a plugin update', () => {

waitForApplication(pluginsPage)

cy.get('[data-plugin-group-status="available"]')
cy.get('[data-plugin-group-status="search"]')
.find(`[data-plugin-package-name="${dependencyPlugin}"]`)
.find('button')
.contains('Install')
Expand Down
4 changes: 2 additions & 2 deletions lib/assets/sass/manage-prototype.scss
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ body .govuk-prototype-kit-manage-prototype-govuk-tag {

@media(min-width: 40.0525em) {
.govuk-prototype-kit-manage-prototype-plugin-list-plugin-list__item-buttons {
.govuk-button {
margin: 0
.govuk-button, .govuk-link--no-visited-state {
margin: 0 15px 0 0;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const syncChanges = require('./sync-changes')
const {
lookupPackageInfo,
getInstalledPackages,
getAvailablePackages,
getAllPackages,
getDependentPackages,
getDependencyPackages,
waitForPackagesCache
Expand Down Expand Up @@ -419,18 +419,18 @@ function buildPluginData (pluginData) {
}

async function prepareForPluginPage (isInstalledPage, search) {
const availablePlugins = await getAvailablePackages()
const allPlugins = await getAllPackages()
const installedPlugins = await getInstalledPackages()

const plugins = isInstalledPage
? installedPlugins
: availablePlugins.filter(plugin => {
: allPlugins.filter(plugin => {
const pluginName = plugin.packageName?.toLowerCase()
return pluginName.indexOf(search.toLowerCase()) >= 0
})

return {
status: isInstalledPage ? 'installed' : 'available',
status: isInstalledPage ? 'installed' : 'search',
plugins: plugins.map(buildPluginData),
found: plugins.length,
updates: installedPlugins.filter(plugin => plugin.installedVersion !== plugin.latestVersion).length
Expand Down Expand Up @@ -510,7 +510,7 @@ async function getPluginsHandler (req, res) {
currentSection: pageName,
links: managementLinks,
isInstalledPage,
isAvailablePage: !isInstalledPage,
isSearchPage: !isInstalledPage,
search,
plugins,
updatesMessage,
Expand All @@ -521,7 +521,7 @@ async function getPluginsHandler (req, res) {
}

async function postPluginsHandler (req, res) {
const query = !req.query?.clear && req.body?.search?.trim() ? `?search=${req.body.search}` : ''
const query = req.body?.search?.trim() ? `?search=${req.body.search}` : ''
res.redirect(contextPath + req.route.path + query)
}

Expand Down
11 changes: 6 additions & 5 deletions lib/manage-prototype-handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const {
postPluginsStatusHandler,
postPluginsModeMiddleware,
getPluginsModeHandler,
postPluginsModeHandler, postPluginsHandler
postPluginsModeHandler,
postPluginsHandler
} = require('./manage-prototype-handlers')
const { projectDir } = require('./utils/paths')

Expand Down Expand Up @@ -108,7 +109,7 @@ jest.mock('./plugins/packages', () => {
}
}),
getInstalledPackages: jest.fn().mockResolvedValue([]),
getAvailablePackages: jest.fn().mockResolvedValue([availablePackage]),
getAllPackages: jest.fn().mockResolvedValue([availablePackage]),
getDependentPackages: jest.fn().mockResolvedValue([]),
getDependencyPackages: jest.fn().mockResolvedValue([])
}
Expand Down Expand Up @@ -442,7 +443,7 @@ describe('manage-prototype-handlers', () => {
'views/manage-prototype/plugins.njk',
expect.objectContaining({
currentSection: 'Plugins',
isAvailablePage: false,
isSearchPage: false,
isInstalledPage: true,
plugins: [],
status: 'installed'
Expand All @@ -457,10 +458,10 @@ describe('manage-prototype-handlers', () => {
'views/manage-prototype/plugins.njk',
expect.objectContaining({
currentSection: 'Plugins',
isAvailablePage: true,
isSearchPage: true,
isInstalledPage: false,
plugins: [availablePlugin],
status: 'available'
status: 'search'
})
)
})
Expand Down
86 changes: 47 additions & 39 deletions lib/nunjucks/views/manage-prototype/plugins.njk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-quarter">
{% if isAvailablePage %}
{% if isSearchPage %}
<div class="sub-nav govuk-!-margin-bottom-6 govuk-prototype-kit-manage-prototype-plugin-subnav--current">
<h2 class="govuk-heading-m">Find plugins</h2>
</div>
Expand All @@ -44,7 +44,7 @@
</div>

<div class="govuk-grid-column-three-quarters">
{% if isAvailablePage %}
{% if isSearchPage %}
<div class="govuk-!-margin-bottom-5">
<div id="search-container">
{{ govukLabel({
Expand All @@ -62,17 +62,15 @@
value: search
}) }}

{{ govukButton({
text: "Search",
classes: "govuk-button--secondary",
attributes: { id: "search-button", formaction: "#" }
}) }}
<div class="govuk-button-group">
{{ govukButton({
text: "Search",
classes: "govuk-button--secondary",
attributes: { id: "search-button", formaction: "#" }
}) }}

{{ govukButton({
text: "Clear search",
classes: "govuk-button--secondary",
attributes: { id: "clear-search-button", formaction: "?clear=true" }
}) }}
<a class="govuk-link govuk-link--no-visited-state" href="?">Clear search</a>
</div>
</div>
<h4 class="govuk-body govuk-!-font-weight-bold">
{{ foundMessage }}
Expand All @@ -95,45 +93,55 @@
By {{ plugin.scope }}
</div>
{% endif %}
{% if isInstalledPage %}
{% if plugin.installedVersion %}
<div class="govuk-!-margin-top-3">
v{{ plugin.installedVersion }}
</div>
{% endif %}
</div>
<div class="govuk-grid-column-two-thirds govuk-body">
{% if isSearchPage and plugin.installedVersion %}
<p>
{{ govukTag({
text: "Installed",
classes: "govuk-tag--grey"
}) }}
</p>
{% endif %}
{% if plugin.description %}
<div class="govuk-!-margin-bottom-3">
{{ plugin.description }}
</div>
{% endif %}
<div class="govuk-prototype-kit-manage-prototype-plugin-list-plugin-list__item-buttons">
{% if not plugin.installedVersion %}
{{ govukButton({
html: 'Install <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
classes: "govuk-button--secondary",
attributes: { id: "install-" + plugin.packageName, formaction: plugin.installLink }
}) }}
{% endif %}
{% if plugin.uninstallLink %}
{{ govukButton({
html: 'Uninstall <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
classes: "govuk-button--secondary",
attributes: { id: "uninstall-" + plugin.packageName, formaction: plugin.uninstallLink }
}) }}
{% endif %}
{% if plugin.updateLink %}
{{ govukButton({
html: 'Update <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
classes: "govuk-button--secondary",
attributes: { id: "update-" + plugin.packageName, formaction: plugin.updateLink }
}) }}
{% endif %}
{% if plugin.helpLink %}
<a class=""
href="{{ plugin.helpLink }}">Help<span
class="govuk-visually-hidden"> - {{ plugin.name }}</span></a>
{% endif %}
<div class="govuk-button-group">
{% if not plugin.installedVersion %}
{{ govukButton({
html: 'Install <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
attributes: { id: "install-" + plugin.packageName, formaction: plugin.installLink }
}) }}
{% endif %}
{% if isInstalledPage %}
{% if plugin.updateLink %}
{{ govukButton({
html: 'Update <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
attributes: { id: "update-" + plugin.packageName, formaction: plugin.updateLink }
}) }}
{% endif %}
{% if plugin.uninstallLink %}
{{ govukButton({
html: 'Uninstall <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
classes: "govuk-button--secondary",
attributes: { id: "uninstall-" + plugin.packageName, formaction: plugin.uninstallLink }
}) }}
{% endif %}
{% endif %}
{% if plugin.helpLink %}
<a class=""
href="{{ plugin.helpLink }}">Help<span
class="govuk-visually-hidden"> - {{ plugin.name }}</span></a>
{% endif %}
</div>
</div>
</div>
</li>
Expand Down
5 changes: 2 additions & 3 deletions lib/plugins/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,12 @@ async function getInstalledPackages () {
.reduce(emphasizeBasePlugins, [])
}

async function getAvailablePackages () {
async function getAllPackages () {
if (!Object.keys(packagesCache).length) {
await startPackageTracker()
}
await waitForPackagesCache()
return Object.values(packagesCache)
.filter(({ available, installed }) => available && !installed)
.sort(packageNameSort)
.reduce(emphasizeBasePlugins, [])
}
Expand Down Expand Up @@ -274,7 +273,7 @@ module.exports = {
waitForPackagesCache,
lookupPackageInfo,
getInstalledPackages,
getAvailablePackages,
getAllPackages,
getDependentPackages,
getDependencyPackages
}
14 changes: 9 additions & 5 deletions lib/plugins/packages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const requestHttps = require('../utils/requestHttps')
const {
getInstalledPackages,
setPackagesCache,
getAvailablePackages,
getAllPackages,
getDependentPackages,
getDependencyPackages
} = require('./packages')
Expand Down Expand Up @@ -84,10 +84,14 @@ describe('packages', () => {
})
})

describe('getAvailablePackages', () => {
describe('getAllPackages', () => {
it('', async () => {
const availablePackages = await getAvailablePackages()
expect(availablePackages).toEqual([availableUninstalledPackage])
const allPackages = await getAllPackages()
expect(allPackages).toEqual([
availableInstalledPackage,
availableUninstalledPackage,
unavailableInstalledPackage,
unavailableUninstalledPackage])
})
})

Expand Down Expand Up @@ -239,7 +243,7 @@ describe('packages', () => {
'/dist/jquery.js'
],
meta: {
description: 'Add the jQuery JavaScript library to your prototype'
description: 'jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.'
}
},
versions: [
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/plugin-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ function getProxyPluginConfig (packageName) {
scripts: ['/dist/jquery.js'],
assets: ['/dist'],
meta: {
description: 'Add the jQuery JavaScript library to your prototype'
description: 'jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.'
}
},
'notifications-node-client': {
meta: {
description: 'Send emails and SMS from GOV.UK Notify'
description: 'GOV.UK Notify makes it easy for public sector service teams to send emails, text messages and letters.'
}
}
}
Expand Down

0 comments on commit 1d5968b

Please sign in to comment.