Skip to content

Commit

Permalink
Merge pull request #1919 from cardstack/cs-7664-use-dashes-instead-of…
Browse files Browse the repository at this point in the history
…-underscores-in-suggested-files-names

Use dashes instead of underscores in suggested filenames/workspaces and elide apostrophes
  • Loading branch information
habdelra authored Dec 11, 2024
2 parents a7655fd + 1fc47b8 commit ea44dff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class AddWorkspace extends Component<Signature> {
this.displayName = value;
// if the user starts typing in the endpoint field, then stop helping them
if (!this.hasUserEditedEndpoint) {
this.endpoint = cleanseString(value, '-');
this.endpoint = cleanseString(value);
}
};
private closeModal = () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/host/app/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export function stringToColor(string: string | null) {
return color;
}

export function cleanseString(value: string, separator = '_') {
export function cleanseString(value: string) {
return deburr(value.toLocaleLowerCase())
.replace(/[^a-z0-9-_]+/g, separator)
.replace(/'/g, '')
.replace(/[^a-z0-9-_]+/g, '-')
.replace(/^[^a-z0-9]/, '')
.replace(/[^a-z0-9]$/, '');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ module('Acceptance | code submode | create-file tests', function (hooks) {
test('filename is auto-populated from display name', async function (assert) {
await visitOperatorMode();
await openNewFileModal('Card Definition');
await fillIn('[data-test-display-name-field]', 'Très test card 😀');
assert.dom('[data-test-file-name-field]').hasValue('tres_test_card');
await fillIn('[data-test-display-name-field]', `Très test's card 😀`);
assert.dom('[data-test-file-name-field]').hasValue('tres-tests-card');
});

test('filename stops auto-populating after user edits it', async function (assert) {
Expand Down

0 comments on commit ea44dff

Please sign in to comment.