Skip to content

Commit

Permalink
Merge pull request #31 from govpf/feature/refactor_table_row_selector…
Browse files Browse the repository at this point in the history
…_to_referentiel_de_polynesie

Feature/refactor table row selector to referentiel de polynesie
  • Loading branch information
yhru authored Oct 22, 2024
2 parents 9115253 + 9b85100 commit 6fff6f3
Show file tree
Hide file tree
Showing 34 changed files with 550 additions and 125 deletions.
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ GEM
rake
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.6)
minitest (5.23.0)
msgpack (1.7.2)
multi_json (1.15.0)
Expand All @@ -479,9 +480,10 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.5-x86_64-darwin)
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux)
nokogiri (1.16.5-x86_64-darwin)
racc (~> 1.4)
openid_connect (2.3.0)
activemodel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
= render partial: "shared/champs/te_fenua/show", locals: { champ: champ, profile: @profile }
- when TypeDeChamp.type_champs.fetch(:numero_dn)
= render partial: "shared/champs/numero_dn/show", locals: { champ: champ, profile: @profile }
- when TypeDeChamp.type_champs.fetch(:table_row_selector)
= render partial: "shared/champs/table_row_selector/show", locals: { champ: champ, profile: @profile }
- when TypeDeChamp.type_champs.fetch(:referentiel_de_polynesie)
= render partial: "shared/champs/referentiel_de_polynesie/show", locals: { champ: champ, profile: @profile }
- when TypeDeChamp.type_champs.fetch(:cojo)
= render partial: "shared/champs/cojo/show", locals: { champ: champ, profile: @profile }
- when TypeDeChamp.type_champs.fetch(:date)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EditableChamp::TableRowSelectorComponent < EditableChamp::ComboSearchComponent
class EditableChamp::ReferentielDePolynesieComponent < EditableChamp::ComboSearchComponent
def dsfr_input_classname
'fr-input'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

= @form.hidden_field :value
= @form.hidden_field :external_id
= react_component("ComboTableRowSelectorSearch",
= react_component("ComboReferentielDePolynesieSearch",
**react_input_opts,
**react_combo_props)
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
.cell.width-100
= form.label :accredited_user_string, "Mails des personnes accréditées", for: dom_id(type_de_champ, :accredited_user_string)
= form.text_area :accredited_user_string, class: 'fr-input small-margin small', rows: 7, id: dom_id(type_de_champ, :accredited_user_string), placeholder: 'Ecrire un email par ligne'
- if type_de_champ.table_row_selector?
- if type_de_champ.referentiel_de_polynesie?
.flex.width-33
.flex.column.flex-grow.justify-start
.cell.width-100
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

class Champs::TableRowSelectorController < ApplicationController
class Champs::ReferentielDePolynesieController < ApplicationController
before_action :authenticate_logged_user!

def search
@params = search_params
if bad_parameters
render json: [], status: 400
else
render json: TableRowSelector::API.search(@params[:domain], @params[:term])
render json: ReferentielDePolynesie::API.search(@params[:domain], @params[:term])
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import { QueryClientProvider } from 'react-query';
import ComboSearch, { ComboSearchProps } from './ComboSearch';
import { queryClient } from './shared/queryClient';

type TableRowSelectorResult = {
type ReferentielDePolynesieResult = {
name: string;
id: string;
domain: string;
};

function transformResults(_: unknown, result: unknown) {
return result as TableRowSelectorResult[];
return result as ReferentielDePolynesieResult[];
}

export default function ComboTableRowSelectorSearch(
props: ComboSearchProps<TableRowSelectorResult>
export default function ComboReferentielDePolynesieResultSearch(
props: ComboSearchProps<ReferentielDePolynesieResult>
) {
return (
<QueryClientProvider client={queryClient}>
<ComboSearch
{...props}
scope="table-row-selector"
scope="referentiel-de-polynesie"
scopeExtra={props.scopeExtra}
minimumInputLength={3}
transformResults={transformResults}
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/components/shared/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function buildURL(scope: string, term: string, extra: string) {
params.set('q', term);
params.set('rows', `${API_EDUCATION_QUERY_LIMIT}`);
params.set('dataset', 'fr-en-annuaire-education');
} else if (scope == 'table-row-selector') {
path = '/champs/table_row_selector/search';
} else if (scope == 'referentiel-de-polynesie') {
path = '/champs/referentiel_de_polynesie/search';
params.set('domain', extra);
params.set('term', term);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class TableRowSelector::API
class ReferentielDePolynesie::API
class << self
def available_tables
engine&.available_tables
Expand All @@ -16,7 +16,7 @@ def fetch_row(external_id)
end

def engine
@engine ||= ENV['API_BASEROW_URL'].present? ? TableRowSelector::BaserowAPI : nil
@engine ||= ENV['API_BASEROW_URL'].present? ? ReferentielDePolynesie::BaserowAPI : nil
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class TableRowSelector::BaserowAPI
class ReferentielDePolynesie::BaserowAPI
class << self
SECRETS = Rails.application.secrets.baserow

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

class Champs::TableRowSelectorChamp < Champs::TextChamp
class Champs::ReferentielDePolynesieChamp < Champs::TextChamp
def fetch_external_data?
true
end

def fetch_external_data
# APIEducation::AnnuaireEducationAdapter.new(external_id).to_params
TableRowSelector::API.fetch_row(external_id)
ReferentielDePolynesie::API.fetch_row(external_id)
end

def update_with_external_data!(data:)
Expand Down
8 changes: 4 additions & 4 deletions app/models/logic/champ_value.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Logic::ChampValue < Logic::Term
INSTANCE_MANAGED_TYPE_DE_CHAMP = [:table_row_selector]
INSTANCE_MANAGED_TYPE_DE_CHAMP = [:referentiel_de_polynesie]

MANAGED_TYPE_DE_CHAMP = TypeDeChamp.type_champs.slice(
*INSTANCE_MANAGED_TYPE_DE_CHAMP,
Expand Down Expand Up @@ -71,7 +71,7 @@ def compute(champs)
code_departement: targeted_champ.code_departement,
code_region: targeted_champ.code_region
}
when "Champs::TableRowSelectorChamp"
when "Champs::ReferentielDePolynesieChamp"
targeted_champ.value
when "Champs::CommuneDePolynesieChamp", "Champs::CodePostalDePolynesieChamp"
{
Expand Down Expand Up @@ -104,7 +104,7 @@ def type(type_de_champs)
CHAMP_VALUE_TYPE.fetch(:departement_enum)
when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list)
CHAMP_VALUE_TYPE.fetch(:enums)
when MANAGED_TYPE_DE_CHAMP.fetch(:table_row_selector)
when MANAGED_TYPE_DE_CHAMP.fetch(:referentiel_de_polynesie)
CHAMP_VALUE_TYPE.fetch(:enum)
else
CHAMP_VALUE_TYPE.fetch(:unmanaged)
Expand Down Expand Up @@ -143,7 +143,7 @@ def options(type_de_champs, operator_name = nil)
APIGeoService.departements.map { ["#{_1[:code]}#{_1[:name]}", _1[:code]] }
elsif operator_name.in?([Logic::InArchipelOperator.name, Logic::NotInArchipelOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:commune_de_polynesie), MANAGED_TYPE_DE_CHAMP.fetch(:code_postal_de_polynesie)])
APIGeo::API.archipels_de_polynesie.map { [_1, _1] }
elsif tdc.type_champ == MANAGED_TYPE_DE_CHAMP.fetch(:table_row_selector)
elsif tdc.type_champ == MANAGED_TYPE_DE_CHAMP.fetch(:referentiel_de_polynesie)
[['Autre', 'Autre']]
else
tdc.drop_down_list_enabled_non_empty_options(other: true).map { _1.is_a?(Array) ? _1 : [_1, _1] }
Expand Down
15 changes: 7 additions & 8 deletions app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ class TypeDeChamp < ApplicationRecord
FILE_MAX_SIZE = 200.megabytes
FEATURE_FLAGS = {
visa: :visa,
table_row_selector: :table_row_selector,
referentiel_de_polynesie: :referentiel_de_polynesie,
tefenua: :tefenua,
engagement_juridique: :engagement_juridique_type_de_champ,

cojo: :cojo_type_de_champ,
expression_reguliere: :expression_reguliere_type_de_champ
}
Expand All @@ -19,7 +18,7 @@ class TypeDeChamp < ApplicationRecord
commune_de_polynesie: 'commune_de_polynesie',
code_postal_de_polynesie: 'code_postal_de_polynesie',
numero_dn: 'numero_dn',
table_row_selector: 'table_row_selector',
referentiel_de_polynesie: 'referentiel_de_polynesie',
te_fenua: 'te_fenua',
visa: 'visa'
}
Expand All @@ -41,7 +40,7 @@ class TypeDeChamp < ApplicationRecord
code_postal_de_polynesie: LOCALISATION,
numero_dn: REFERENTIEL_EXTERNE,
te_fenua: REFERENTIEL_EXTERNE,
table_row_selector: REFERENTIEL_EXTERNE,
referentiel_de_polynesie: REFERENTIEL_EXTERNE,
visa: STRUCTURE
}

Expand Down Expand Up @@ -464,8 +463,8 @@ def visa?
type_champ == TypeDeChamp.type_champs.fetch(:visa)
end

def table_row_selector?
type_champ == TypeDeChamp.type_champs.fetch(:table_row_selector)
def referentiel_de_polynesie?
type_champ == TypeDeChamp.type_champs.fetch(:referentiel_de_polynesie)
end

def te_fenua?
Expand Down Expand Up @@ -671,7 +670,7 @@ def accredited_user_list
end

def available_tables
TableRowSelector::API.available_tables.map { [_1[:name], _1[:id]] }
ReferentielDePolynesie::API.available_tables.map { [_1[:name], _1[:id]] }
end

def to_typed_id
Expand Down Expand Up @@ -733,7 +732,7 @@ def self.refresh_after_update?(type_champ)
type_champs.fetch(:siret),
type_champs.fetch(:numero_dn),
type_champs.fetch(:te_fenua),
type_champs.fetch(:table_row_selector)
type_champs.fetch(:referentiel_de_polynesie)
false
else
true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class TypesDeChamp::ReferentielDePolynesieTypeDeChamp < TypesDeChamp::TypeDeChampBase
end
4 changes: 0 additions & 4 deletions app/models/types_de_champ/table_row_selector_type_de_champ.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/initializers/flipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setup_features(features)
:sva,
:switch_domain,
:visa,
:table_row_selector
:referentiel_de_polynesie
]

def database_exists?
Expand Down
2 changes: 1 addition & 1 deletion config/locales/shared.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ en:
refuse: "Expires on %{date} (%{duree_conservation_totale} months after this file was processed)"
sans_suite: "Expires on %{date} (%{duree_conservation_totale} months after this file was processed)"
champs:
table_row_selector:
referentiel_de_polynesie:
show:
toggle_champ: "Show/hide fields of « %{champ} »"
cnaf:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/shared.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fr:


champs:
table_row_selector:
referentiel_de_polynesie:
show:
toggle_champ: "Afficher/Cacher les champs de « %{champ} »"
cnaf:
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
post ':dossier_id/:stable_id/repetition', to: 'repetition#add', as: :repetition
delete ':dossier_id/:stable_id/repetition', to: 'repetition#remove'

get 'table_row_selector/search', to: 'table_row_selector#search'
get 'referentiel_de_polynesie/search', to: 'referentiel_de_polynesie#search'

get ':dossier_id/:stable_id/siret', to: 'siret#show', as: :siret
get ':dossier_id/:stable_id/rna', to: 'rna#show', as: :rna
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace :after_party do
desc 'Deployment task: Enable feature flag for referentiel_de_polynesie'
task feature_flag_referentiel_de_polynesie: :environment do
puts "Running deploy task 'feature_flag_referentiel_de_polynesie'"

progress = ProgressReport.new(User.count)
User.find_each do |user|
if Flipper.enabled?(:referentiel_de_polynesie, user) && user.administrateur?
user.administrateur.procedures.each do |procedure|
if procedure.types_de_champ_for_tags.where(type_champ: 'referentiel_de_polynesie').any?
Flipper.enable(:referentiel_de_polynesie, procedure)
end
end
Flipper.disable(:referentiel_de_polynesie, user)
end
progress.inc
end

progress.finish

AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end
4 changes: 4 additions & 0 deletions spec/factories/champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@
type_de_champ { association :type_de_champ_annuaire_education, procedure: dossier.procedure }
end

factory :champ_referentiel_de_polynesie, class: 'Champs::ReferentielDePolynesieChamp' do
type_de_champ { association :type_de_champ_referentiel_de_polynesie, procedure: dossier.procedure }
end

factory :champ_visa, class: 'Champs::VisaChamp' do
type_de_champ { association :type_de_champ_visa, procedure: dossier.procedure }
end
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@
factory :type_de_champ_visa do
type_champ { TypeDeChamp.type_champs.fetch(:visa) }
end
factory :type_de_champ_referentiel_de_polynesie do
type_champ { TypeDeChamp.type_champs.fetch(:referentiel_de_polynesie) }
end
factory :type_de_champ_epci do
type_champ { TypeDeChamp.type_champs.fetch(:epci) }
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
describe 'deployment:20241021111111:feature_flag_referentiel_de_polynesie' do
let(:rake_task) { Rake::Task['after_party:feature_flag_referentiel_de_polynesie'] }
let!(:procedure_with_admin_featured) { create(:procedure) }
let!(:types_de_champ_private) { [{ type: :referentiel_de_polynesie }] }
let!(:procedure_with_referentiel_de_polynesie_with_admin_featured) { create(:procedure, types_de_champ_private:, administrateurs: [procedure_with_admin_featured.administrateurs.first]) }
let!(:procedure_without_admin_featured) { create(:procedure) }
let!(:procedure_with_referentiel_de_polynesie_without_admin_featured) { create(:procedure, types_de_champ_private:, administrateurs: [procedure_without_admin_featured.administrateurs.first]) }

subject(:run_task) do
rake_task.invoke
end

before { Flipper.enable(:referentiel_de_polynesie, procedure_with_admin_featured.administrateurs.first.user) }

after { rake_task.reenable }

describe 'feature_flag_referentiel_de_polynesie' do
it "with bad champs" do
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_admin_featured.administrateurs.first.user)).to eq(true)
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_admin_featured)).to eq(false)
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_with_admin_featured)).to eq(false)
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_without_admin_featured)).to eq(false)
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_without_admin_featured)).to eq(false)

run_task

procedure_with_admin_featured.reload
procedure_with_referentiel_de_polynesie_with_admin_featured.reload
procedure_without_admin_featured.reload
procedure_with_referentiel_de_polynesie_without_admin_featured.reload

expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_admin_featured.administrateurs.first.user)).to eq(false)
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_admin_featured)).to eq(false)
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_with_admin_featured)).to eq(true)
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_without_admin_featured)).to eq(false)
expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_without_admin_featured)).to eq(false)
end
end
end
Loading

0 comments on commit 6fff6f3

Please sign in to comment.