Skip to content

Commit

Permalink
Allow disabled projects
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed May 6, 2024
1 parent a320a76 commit cc624fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export class ProjectAutocompleterComponent extends OpAutocompleterComponent<IPro

@Input() public isInlineContext = false;

@Input() public disabledProjects:{ [key:string]:string|boolean } = {};

// This function allows mapping of the results before they are fed to the tree
// structuring and destructuring algorithms used internally the this component
// to show the tree structure. By default it does not do much, but it is
Expand Down Expand Up @@ -140,9 +142,12 @@ export class ProjectAutocompleterComponent extends OpAutocompleterComponent<IPro
const arrayedValue = (Array.isArray(normalizedValue) ? normalizedValue : [normalizedValue]).map((p) => p.href || p.id);
return projects.map((project) => {
const isSelected = !!arrayedValue.find((selected) => selected === this.projectTracker(project));
const id = project.id.toString();
const disabled = isSelected || project.disabled || !!this.disabledProjects[id];
return {
...project,
disabled: isSelected || project.disabled,
disabled,
disabledReason: (typeof this.disabledProjects[id] === 'string') ? this.disabledProjects[id] as string : '',
};
});
}
Expand Down Expand Up @@ -176,14 +181,20 @@ export class ProjectAutocompleterComponent extends OpAutocompleterComponent<IPro
},
)
.pipe(
map((projects) => projects.map((project) => ({
id: project.id,
href: project._links.self.href,
name: project.name,
disabled: false,
ancestors: project._links.ancestors,
children: [],
}))),
map((projects) => projects.map((project) => {
const id = project.id.toString();
const disabled = !!this.disabledProjects[id];

return {
id: project.id,
href: project._links.self.href,
name: project.name,
disabled,
disabledReason: (typeof this.disabledProjects[id] === 'string') ? this.disabledProjects[id] as string : '',
ancestors: project._links.ancestors,
children: [],
};
})),
map(this.mapResultsFn),
map((projects) => {
this.dataLoaded = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ module Forms
module Dsl
class ProjectAutocompleterInput < AutocompleterInput
def derive_autocompleter_options(options)
options.reverse_merge(
options.reverse_merge!(
component: "opce-project-autocompleter",
defaultData: false,
filters: [{ name: 'active', operator: '=', values: ['t'] }],
)

if options[:disabledProjects]
options[:disabledProjects].stringify_keys!
end

options
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
autocomplete_options: {
openDirectly: false,
focusDirectly: false,
dropdownPosition: 'bottom'
dropdownPosition: 'bottom',
disabledProjects: Project.visible.take(10).pluck(:id).to_h { |id| [id, "Disabled reason!"] }
}
)
end
Expand Down

0 comments on commit cc624fe

Please sign in to comment.