-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[#72855] Add semantic identifier support to "Add Project" #22330
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
Merged
thykel
merged 18 commits into
feature/71896-change-identifier-with-semantic-identifiers
from
feature/72855-new-project-with-semantic-identifiers
Mar 19, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a30973c
[#72855] Add semantic identifier support to "Add Project"
thykel 67630c5
Merge branch 'feature/71896-change-identifier-with-semantic-identifie…
thykel 7bf353c
add a missing permitted param
thykel 5a8f3fc
Merge branch 'feature/71896-change-identifier-with-semantic-identifie…
thykel 5e332d6
enable the auto-suggest for legacy IDs as well
thykel 9d36c83
remove the copy component
thykel fa19340
Merge branch 'feature/71896-change-identifier-with-semantic-identifie…
thykel 72fa065
switch to the new method
thykel 740459a
remove feature flags from the tests
thykel b1fff98
EditableIdentifierForm => IdentifierForm
thykel 734becc
ditch feature flag & unify error message format
thykel cfaa279
get rid of the broken i8n message upon refresh
thykel 6956104
add more tests
thykel 4bbd4ff
fix a feature test
thykel b5e4f3a
lint
thykel b2055c2
fix the test that includes delay
thykel 8f1f56d
Revert "EditableIdentifierForm => IdentifierForm"
thykel 19ae970
Merge branch 'feature/71896-change-identifier-with-semantic-identifie…
thykel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/controllers/projects/identifier_suggestions_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| module Projects | ||
| class IdentifierSuggestionsController < ApplicationController | ||
| before_action :require_login | ||
| no_authorization_required! :show | ||
|
|
||
| def show | ||
| name = params[:name].to_s.strip | ||
| return render json: {}, status: :unprocessable_entity if name.blank? | ||
|
|
||
| identifier = Project.suggest_identifier(name) | ||
| render json: { identifier: } | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
frontend/src/stimulus/controllers/dynamic/projects/identifier-suggestion.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| * -- copyright | ||
| * OpenProject is an open source project management software. | ||
| * Copyright (C) the OpenProject GmbH | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License version 3. | ||
| * | ||
| * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| * Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| * Copyright (C) 2010-2013 the ChiliProject Team | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License | ||
| * as published by the Free Software Foundation; either version 2 | ||
| * of the License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| * | ||
| * See COPYRIGHT and LICENSE files for more details. | ||
| * ++ | ||
| */ | ||
|
|
||
| import {Controller} from '@hotwired/stimulus'; | ||
| import {debounce, DebouncedFunc} from 'lodash'; | ||
|
thykel marked this conversation as resolved.
|
||
|
|
||
| const ALLOWED_CHARS:Record<string, RegExp> = { | ||
| semantic: /[^A-Z0-9_]/g, | ||
| legacy: /[^a-z0-9\-_]/g, | ||
| }; | ||
|
|
||
| export default class extends Controller { | ||
| static values = { | ||
| url: String, | ||
| debounce: {type: Number, default: 300}, | ||
| mode: {type: String, default: 'legacy'}, | ||
| setNameFirst: {type: String, default: ''}, | ||
| }; | ||
|
|
||
| declare urlValue:string; | ||
| declare debounceValue:number; | ||
| declare modeValue:string; | ||
| declare setNameFirstValue:string; | ||
|
|
||
| private nameInput:HTMLInputElement | null = null; | ||
| private identifierInput:HTMLInputElement | null = null; | ||
| private debouncedSuggest:DebouncedFunc<(name:string) => Promise<void>> | null = null; | ||
| private handleBlur:((event:Event) => void) | null = null; | ||
| private handleInput:((event:Event) => void) | null = null; | ||
|
|
||
| connect():void { | ||
| this.nameInput = this.element.querySelector<HTMLInputElement>('[name="project[name]"]'); | ||
| this.identifierInput = this.element.querySelector<HTMLInputElement>('[name="project[identifier]"]'); | ||
|
thykel marked this conversation as resolved.
|
||
|
|
||
| if (!this.nameInput || !this.identifierInput) return; | ||
|
thykel marked this conversation as resolved.
|
||
|
|
||
| this.handleInput = () => this.filterInput(); | ||
| this.identifierInput.addEventListener('input', this.handleInput); | ||
|
thykel marked this conversation as resolved.
|
||
|
|
||
| if (this.urlValue) { | ||
| if (!this.identifierInput.value) { | ||
| this.identifierInput.placeholder = this.setNameFirstValue; | ||
| this.identifierInput.readOnly = true; | ||
| } | ||
|
|
||
| this.debouncedSuggest = debounce( | ||
| (name:string) => this.fetchSuggestion(name), | ||
| this.debounceValue, | ||
| ); | ||
|
|
||
| this.handleBlur = () => { | ||
| const name = this.nameInput!.value.trim(); | ||
| if (name) void this.debouncedSuggest!(name); | ||
| }; | ||
|
|
||
| this.nameInput.addEventListener('blur', this.handleBlur); | ||
| } | ||
| } | ||
|
|
||
| disconnect():void { | ||
| this.debouncedSuggest?.cancel(); | ||
| if (this.nameInput && this.handleBlur) { | ||
| this.nameInput.removeEventListener('blur', this.handleBlur); | ||
| } | ||
| if (this.identifierInput && this.handleInput) { | ||
| this.identifierInput.removeEventListener('input', this.handleInput); | ||
| } | ||
|
thykel marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private filterInput():void { | ||
| if (!this.identifierInput) return; | ||
|
thykel marked this conversation as resolved.
|
||
|
|
||
| const pattern = ALLOWED_CHARS[this.modeValue] ?? ALLOWED_CHARS.legacy; | ||
| const current = this.identifierInput.value; | ||
| const filtered = current.replace(pattern, ''); | ||
|
|
||
| if (filtered !== current) { | ||
| const pos = this.identifierInput.selectionStart ?? filtered.length; | ||
| this.identifierInput.value = filtered; | ||
| const newPos = Math.min(pos, filtered.length); | ||
| this.identifierInput.setSelectionRange(newPos, newPos); | ||
| } | ||
| } | ||
|
|
||
| private async fetchSuggestion(name:string):Promise<void> { | ||
| if (!this.urlValue) return; | ||
|
|
||
| if (this.identifierInput) { | ||
| this.identifierInput.readOnly = true; | ||
| this.identifierInput.placeholder = I18n.t('js.projects.identifier_suggestion.loading'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍊 For loading state- you might want to consider: https://primer.style/product/components/text-input/#in-a-loading-state due to a11ly |
||
| } | ||
|
|
||
| try { | ||
| const url = `${this.urlValue}?name=${encodeURIComponent(name)}`; | ||
| const response = await fetch(url, {headers: {Accept: 'application/json'}}); | ||
|
thykel marked this conversation as resolved.
|
||
|
|
||
| if (!response.ok) return; | ||
|
|
||
| const data = await response.json() as { identifier:string }; | ||
| if (this.identifierInput) { | ||
| this.identifierInput.value = data.identifier; | ||
| } | ||
| } finally { | ||
| if (this.identifierInput) { | ||
| this.identifierInput.readOnly = false; | ||
| this.identifierInput.placeholder = ''; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.