mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-03-21 12:29:03 +01:00
(quality) status property :label is now :name for better coherence
This commit is contained in:
parent
96ddb40c59
commit
b9d86aecdc
@ -41,6 +41,6 @@ class API::StatusesController < ApplicationController
|
||||
end
|
||||
|
||||
def status_params
|
||||
params.require(:status).permit(:label)
|
||||
params.require(:status).permit(:name)
|
||||
end
|
||||
end
|
||||
|
@ -37,11 +37,16 @@ export const StatusFilter: React.FC<StatusFilterProps> = ({ 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<StatusFilterProps> = ({ currentStatusIndex,
|
||||
* Callback triggered when the admin selects a status in the dropdown list
|
||||
*/
|
||||
const handleStatusSelected = (option: SelectOption<number>): void => {
|
||||
onFilterChange({ id: option.value, label: option.label });
|
||||
onFilterChange({ id: option.value, name: option.label });
|
||||
setCurrentOption(option);
|
||||
};
|
||||
|
||||
|
@ -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<StatusSettingsProps> = ({ onError, onSuccess }) => {
|
||||
const { t } = useTranslation('admin');
|
||||
const [statusesOptions, setStatusesOptions] = useState([]);
|
||||
const [statusesOptions, setStatusesOptions] = useState<Array<Status>>([]);
|
||||
|
||||
// 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<StatusSettingsProps> = ({ 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<StatusSettingsProps> = ({ 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);
|
||||
};
|
||||
|
@ -93,7 +93,7 @@ class ProjectsController {
|
||||
$scope.statuses = data.map(function (d) {
|
||||
return ({
|
||||
id: d.id,
|
||||
label: d.label
|
||||
name: d.name
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,6 @@
|
||||
export interface Status {
|
||||
import { ProjectSettingOption } from './project-setting-option';
|
||||
|
||||
export interface Status extends ProjectSettingOption {
|
||||
id?: number,
|
||||
label: string,
|
||||
name: string,
|
||||
}
|
||||
|
@ -170,11 +170,11 @@
|
||||
<!-- TODO: be able to remove the selected option -->
|
||||
<ui-select ng-model="project.status_id">
|
||||
<ui-select-match>
|
||||
<span ng-bind="$select.selected.label"></span>
|
||||
<span ng-bind="$select.selected.name"></span>
|
||||
<input type="hidden" name="project[status_id]" value="{{$select.selected.id}}" />
|
||||
</ui-select-match>
|
||||
<ui-select-choices repeat="s.id as s in (statuses | filter: $select.search)">
|
||||
<span ng-bind-html="s.label | highlight: $select.search"></span>
|
||||
<span ng-bind-html="s.name | highlight: $select.search"></span>
|
||||
</ui-select-choices>
|
||||
</ui-select>
|
||||
</div>
|
||||
|
@ -76,7 +76,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2 m-b">
|
||||
<status-filter on-filter-change="onStatusChange" current-status-index="search.status_id"></status-filter>
|
||||
<status-filter on-filter-change="onStatusChange" current-status-index="search.status_id"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -111,7 +111,7 @@
|
||||
<h3 translate>{{ 'app.public.projects_show.status' }}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{{ project.status.label }}
|
||||
{{ project.status.name }}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.array!(@statuses) do |status|
|
||||
json.extract! status, :id, :label
|
||||
json.extract! status, :id, :name
|
||||
end
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Status } from '../../../app/frontend/src/javascript/models/status';
|
||||
|
||||
const statuses: Array<Status> = [
|
||||
{ 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;
|
||||
|
@ -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) => {
|
||||
|
@ -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 });
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user