diff --git a/app/controllers/api/statuses_controller.rb b/app/controllers/api/statuses_controller.rb index ba24d7b4e..8ef1f1d9c 100644 --- a/app/controllers/api/statuses_controller.rb +++ b/app/controllers/api/statuses_controller.rb @@ -41,6 +41,6 @@ class API::StatusesController < ApplicationController end def status_params - params.require(:status).permit(:label) + params.require(:status).permit(:name) end end diff --git a/app/frontend/src/javascript/components/projects/status/status-filter.tsx b/app/frontend/src/javascript/components/projects/status/status-filter.tsx index 74bc0119c..6398d0ed7 100644 --- a/app/frontend/src/javascript/components/projects/status/status-filter.tsx +++ b/app/frontend/src/javascript/components/projects/status/status-filter.tsx @@ -37,11 +37,16 @@ export const StatusFilter: React.FC = ({ currentStatusIndex, /** * On component mount, asynchronously load the full list of statuses + * Converts name property into label property, since a SelectOption needs a label */ useEffect(() => { StatusAPI.index() - .then(setStatusesList) - .catch(onError); + .then((data) => { + const options = data.map(status => { + return { id: status.id, label: status.name }; + }); + setStatusesList(options); + }).catch(onError); }, []); // If currentStatusIndex is provided, set currentOption accordingly @@ -54,7 +59,7 @@ export const StatusFilter: React.FC = ({ currentStatusIndex, * Callback triggered when the admin selects a status in the dropdown list */ const handleStatusSelected = (option: SelectOption): void => { - onFilterChange({ id: option.value, label: option.label }); + onFilterChange({ id: option.value, name: option.label }); setCurrentOption(option); }; diff --git a/app/frontend/src/javascript/components/projects/status/status-settings.tsx b/app/frontend/src/javascript/components/projects/status/status-settings.tsx index 7324b80e8..50928fed5 100644 --- a/app/frontend/src/javascript/components/projects/status/status-settings.tsx +++ b/app/frontend/src/javascript/components/projects/status/status-settings.tsx @@ -6,6 +6,7 @@ import { Loader } from '../../base/loader'; import { ProjectsSetting } from './../projects-setting'; import { ProjectSettingOption } from '../../../models/project-setting-option'; import { useTranslation } from 'react-i18next'; +import { Status } from '../../../models/status'; declare const Application: IApplication; @@ -19,11 +20,11 @@ interface StatusSettingsProps { */ export const StatusSettings: React.FC = ({ onError, onSuccess }) => { const { t } = useTranslation('admin'); - const [statusesOptions, setStatusesOptions] = useState([]); + const [statusesOptions, setStatusesOptions] = useState>([]); // Async function : post new status to API, then refresh status list const addOption = async (option: ProjectSettingOption) => { - await StatusAPI.create({ label: option.name }).catch(onError); + await StatusAPI.create({ name: option.name }).catch(onError); onSuccess(t('app.admin.status_settings.option_create_success')); fetchStatus(); }; @@ -37,7 +38,7 @@ export const StatusSettings: React.FC = ({ onError, onSucce // Async function : send updated status to API, then refresh status list const updateOption = async (option: ProjectSettingOption) => { - await StatusAPI.update({ id: option.id, label: option.name }).catch(onError); + await StatusAPI.update({ id: option.id, name: option.name }).catch(onError); onSuccess(t('app.admin.status_settings.option_update_success')); fetchStatus(); }; @@ -46,10 +47,7 @@ export const StatusSettings: React.FC = ({ onError, onSucce const fetchStatus = () => { StatusAPI.index() .then(data => { - const options = data.map(status => { - return { id: status.id, name: status.label }; - }); - setStatusesOptions(options.sort((a, b) => a.id - b.id)); + setStatusesOptions(data.sort((a, b) => a.id - b.id)); }) .catch(onError); }; diff --git a/app/frontend/src/javascript/controllers/projects.js b/app/frontend/src/javascript/controllers/projects.js index 07ff4ffff..6aa7d8112 100644 --- a/app/frontend/src/javascript/controllers/projects.js +++ b/app/frontend/src/javascript/controllers/projects.js @@ -93,7 +93,7 @@ class ProjectsController { $scope.statuses = data.map(function (d) { return ({ id: d.id, - label: d.label + name: d.name }); }); }); diff --git a/app/frontend/src/javascript/models/status.ts b/app/frontend/src/javascript/models/status.ts index 27df14e62..180023777 100644 --- a/app/frontend/src/javascript/models/status.ts +++ b/app/frontend/src/javascript/models/status.ts @@ -1,4 +1,6 @@ -export interface Status { +import { ProjectSettingOption } from './project-setting-option'; + +export interface Status extends ProjectSettingOption { id?: number, - label: string, + name: string, } diff --git a/app/frontend/templates/projects/_form.html b/app/frontend/templates/projects/_form.html index eadf6f2b7..fb4a9ff69 100644 --- a/app/frontend/templates/projects/_form.html +++ b/app/frontend/templates/projects/_form.html @@ -170,11 +170,11 @@ - + - + diff --git a/app/frontend/templates/projects/index.html b/app/frontend/templates/projects/index.html index 4080482fc..b8703a10c 100644 --- a/app/frontend/templates/projects/index.html +++ b/app/frontend/templates/projects/index.html @@ -76,7 +76,7 @@
- +
diff --git a/app/frontend/templates/projects/show.html b/app/frontend/templates/projects/show.html index 37ce6a28d..5c0aa93ab 100644 --- a/app/frontend/templates/projects/show.html +++ b/app/frontend/templates/projects/show.html @@ -111,7 +111,7 @@

{{ 'app.public.projects_show.status' }}

- {{ project.status.label }} + {{ project.status.name }}
diff --git a/app/models/status.rb b/app/models/status.rb index b62365636..51e24c989 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -2,6 +2,6 @@ # Set statuses for projects (new, pending, done...) class Status < ApplicationRecord - validates :label, presence: true + validates :name, presence: true has_many :projects, dependent: :nullify end diff --git a/app/views/api/statuses/index.json.jbuilder b/app/views/api/statuses/index.json.jbuilder index d1ff40e78..2432efcf6 100644 --- a/app/views/api/statuses/index.json.jbuilder +++ b/app/views/api/statuses/index.json.jbuilder @@ -1,5 +1,5 @@ # frozen_string_literal: true json.array!(@statuses) do |status| - json.extract! status, :id, :label + json.extract! status, :id, :name end diff --git a/config/locales/en.yml b/config/locales/en.yml index 278dcb472..629a16d17 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -664,3 +664,9 @@ en: external_id: "external identifier" prevent_invoices_zero: "prevent building invoices at 0" invoice_VAT-name: "VAT name" + #statuses of projects + statuses: + new: "New" + pending: "Pending" + done: "Done" + abandoned: "Abandoned" diff --git a/db/migrate/20230116142738_create_statuses.rb b/db/migrate/20230116142738_create_statuses.rb index 33d39fc8b..897b906bd 100644 --- a/db/migrate/20230116142738_create_statuses.rb +++ b/db/migrate/20230116142738_create_statuses.rb @@ -4,7 +4,7 @@ class CreateStatuses < ActiveRecord::Migration[5.2] def change create_table :statuses do |t| - t.string :label + t.string :name t.timestamps end diff --git a/db/seeds.rb b/db/seeds.rb index 372e421da..2bb482f58 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -103,10 +103,10 @@ end if Status.count.zero? Status.create!([ - { label: 'Nouveau' }, - { label: 'En cours' }, - { label: 'Terminé' }, - { label: 'Arrêté' } + { name: I18n.t('statuses.new') }, + { name: I18n.t('statuses.pending') }, + { name: I18n.t('statuses.done') }, + { name: I18n.t('statuses.abandoned') } ]) end diff --git a/test/frontend/__fixtures__/statuses.ts b/test/frontend/__fixtures__/statuses.ts index 14ae96e04..bb997b95e 100644 --- a/test/frontend/__fixtures__/statuses.ts +++ b/test/frontend/__fixtures__/statuses.ts @@ -1,8 +1,8 @@ import { Status } from '../../../app/frontend/src/javascript/models/status'; const statuses: Array = [ - { id: 1, label: 'Mocked Status 1' }, - { id: 2, label: 'Mocked Status 2' } + { id: 1, name: 'Mocked Status 1' }, + { id: 2, name: 'Mocked Status 2' } ]; export default statuses; diff --git a/test/frontend/__setup__/server.js b/test/frontend/__setup__/server.js index c2fef9193..bd2748ac9 100644 --- a/test/frontend/__setup__/server.js +++ b/test/frontend/__setup__/server.js @@ -102,7 +102,7 @@ export const server = setupServer( const id = parseInt(req.params.id); const reqBody = await req.json(); const status = fixtures.statuses.find((status) => status.id === id); - status.label = reqBody.status.label; + status.name = reqBody.status.name; return res(ctx.json(status)); }), rest.post('/api/statuses', async (req, res, ctx) => { diff --git a/test/frontend/components/projects/status-filter.test.tsx b/test/frontend/components/projects/status-filter.test.tsx index 97726ed6f..7f712c931 100644 --- a/test/frontend/components/projects/status-filter.test.tsx +++ b/test/frontend/components/projects/status-filter.test.tsx @@ -16,13 +16,13 @@ describe('Status Filter', () => { await waitFor(() => screen.getByText('Mocked Status 1')); fireEvent.click(screen.getByText('Mocked Status 1')); - expect(onFilterChange).toHaveBeenCalledWith({ label: 'Mocked Status 1', id: 1 }); + expect(onFilterChange).toHaveBeenCalledWith({ name: 'Mocked Status 1', id: 1 }); fireEvent.keyDown(screen.getByLabelText(/app.public.status_filter.select_status/), { key: 'ArrowDown' }); await waitFor(() => screen.getByText('Mocked Status 2')); fireEvent.click(screen.getByText('Mocked Status 2')); expect(onFilterChange).toHaveBeenCalledTimes(2); - expect(onFilterChange).toHaveBeenCalledWith({ label: 'Mocked Status 2', id: 2 }); + expect(onFilterChange).toHaveBeenCalledWith({ name: 'Mocked Status 2', id: 2 }); }); });