Skip to content
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

Editor: Rework update frequency dropdown #1097

Merged
merged 9 commits into from
Feb 5, 2025
7 changes: 2 additions & 5 deletions apps/metadata-editor-e2e/src/e2e/edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,6 @@ describe('editor form', () => {
describe('when the regularity switch is on', () => {
it('should allow to select a frequency', () => {
cy.editor_wrapPreviousDraft()
cy.get('gn-ui-form-field-update-frequency')
.find('gn-ui-check-toggle label')
.click()
cy.get('gn-ui-form-field-update-frequency')
.find('gn-ui-dropdown-selector')
.openDropdown()
Expand All @@ -324,7 +321,7 @@ describe('editor form', () => {
.getActiveDropdownOption()
.find('span')
.invoke('text')
.should('eq', ' 2 times per week ')
.should('eq', ' Data is updated each day ')
})
})
describe('when the regularity switch is off', () => {
Expand All @@ -340,7 +337,7 @@ describe('editor form', () => {
.find('button')
.find('div')
.invoke('text')
.should('eq', ' Once per day ')
.should('eq', ' Data is repeatedly and frequently updated ')
})
})
})
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1657,10 +1657,7 @@ describe('Gn4Converter', () => {
topics: ['Installations de suivi environnemental', 'Océans'],
title: 'Surval - Données par paramètre',
uniqueIdentifier: 'cf5048f6-5bbf-4e44-ba74-e6f429af51ea',
updateFrequency: {
per: 'day',
updatedTimes: 1,
},
updateFrequency: 'daily',
spatialExtents: [
{
description: 'Hauts-de-France (Région)',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,67 +1,14 @@
import { UpdateFrequency } from '@geonetwork-ui/common/domain/model/record'
import {
UpdateFrequency,
UpdateFrequencyCode,
updateFrequencyCodeValues,
} from '@geonetwork-ui/common/domain/model/record'

export function getUpdateFrequencyFromFrequencyCode(
frequencyCode: string
): UpdateFrequency {
switch (frequencyCode) {
case 'asNeeded':
return 'asNeeded'
case 'unknown':
return 'unknown'
case 'irregular':
return 'irregular'
case 'notPlanned':
return 'notPlanned'
case 'continual':
return 'continual'
case 'periodic':
return 'periodic'
case 'daily':
return {
updatedTimes: 1,
per: 'day',
}
case 'weekly':
return {
updatedTimes: 1,
per: 'week',
}
case 'fortnightly':
return {
updatedTimes: 0.5,
per: 'week',
}
case 'semimonthly':
return {
updatedTimes: 2,
per: 'month',
}
case 'monthly':
return {
updatedTimes: 1,
per: 'month',
}
case 'quarterly':
return {
updatedTimes: 4,
per: 'year',
}
case 'biannually':
return {
updatedTimes: 2,
per: 'year',
}
case 'annually':
return {
updatedTimes: 1,
per: 'year',
}
case 'biennially':
return {
updatedTimes: 0.5,
per: 'year',
}
default:
return null
}
return frequencyCode &&
updateFrequencyCodeValues.includes(frequencyCode as UpdateFrequencyCode)
? (frequencyCode as UpdateFrequencyCode)
: null
}
18 changes: 18 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19139/write-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ export function getMaintenanceFrequencyCode(
return 'continual'
case 'periodic':
return 'periodic'
case 'daily':
return 'daily'
case 'weekly':
return 'weekly'
case 'fortnightly':
return 'fortnightly'
case 'monthly':
return 'monthly'
case 'quarterly':
return 'quarterly'
case 'biannually':
return 'biannually'
case 'annually':
return 'annually'
case 'semimonthly':
return 'semimonthly'
case 'biennially':
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe i am missing something but i don't really understand the purpose of this function, is it only to output the frequency as a string? + it is missing the default case returning null.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it seems useless now, maybe because you changed the way frequency code is handled. Dunno

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't change anything regarding the frequency code handling, i have just allowed 2 more options to be displayed in the dropdown list.

return 'biennially'
}
}

Expand Down
36 changes: 29 additions & 7 deletions libs/common/domain/src/lib/model/record/metadata.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,41 @@ marker('domain.record.updateFrequency.irregular')
marker('domain.record.updateFrequency.continual')
marker('domain.record.updateFrequency.periodic')

export type UpdateFrequencyCode =
| 'unknown'
| 'notPlanned'
| 'asNeeded'
| 'irregular'
| 'continual'
| 'periodic'
export const updateFrequencyCodeValues = [
'unknown',
'notPlanned',
'asNeeded',
'irregular',
'continual',
'periodic',
'daily',
'weekly',
'fortnightly',
'semimonthly',
'monthly',
'quarterly',
'biannually',
'annually',
'biennially',
] as const

export type UpdateFrequencyCode = (typeof updateFrequencyCodeValues)[number]

marker('domain.record.updateFrequency.day')
marker('domain.record.updateFrequency.week')
marker('domain.record.updateFrequency.month')
marker('domain.record.updateFrequency.year')

marker('domain.record.updateFrequency.daily')
marker('domain.record.updateFrequency.weekly')
marker('domain.record.updateFrequency.fortnightly')
marker('domain.record.updateFrequency.monthly')
marker('domain.record.updateFrequency.quarterly')
marker('domain.record.updateFrequency.biannually')
marker('domain.record.updateFrequency.annually')
marker('domain.record.updateFrequency.semimonthly')
marker('domain.record.updateFrequency.biennially')

export type UpdateFrequencyCustom = {
updatedTimes: number // this should be an integer
per: 'day' | 'week' | 'month' | 'year'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('FormFieldUpdateFrequencyComponent', () => {
})

it('should offer a set of initial choices', () => {
expect(component['choices']).toHaveLength(10)
expect(component['choices']).toHaveLength(13)
expect(component['choices']).toContainEqual({
label: 'domain.record.updateFrequency.week',
value: 'week.3',
Expand Down Expand Up @@ -77,10 +77,7 @@ describe('FormFieldUpdateFrequencyComponent', () => {
it('should emit once per day on toggle', () => {
const spy = jest.spyOn(component.valueChange, 'emit')
component.onPlannedToggled()
expect(spy).toHaveBeenCalledWith({
updatedTimes: 1,
per: 'day',
})
expect(spy).toHaveBeenCalledWith('continual')
})
})
})
Loading
Loading