-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use project display names in DW, move related utils from ~/pages/proj…
…ects to ~/concepts/projects and ~/concepts/k8s Signed-off-by: Mike Turley <[email protected]>
- Loading branch information
Showing
51 changed files
with
238 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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,63 @@ | ||
import { mockProjectK8sResource } from '~/__mocks__'; | ||
import { | ||
getDescriptionFromK8sResource, | ||
getDisplayNameFromK8sResource, | ||
isValidK8sName, | ||
translateDisplayNameForK8s, | ||
} from '~/concepts/k8s/utils'; | ||
|
||
describe('getDisplayNameFromK8sResource', () => { | ||
it('gets the display name when present', () => { | ||
const mockProject = mockProjectK8sResource({ | ||
k8sName: 'my-project', | ||
displayName: 'My Project', | ||
}); | ||
expect(getDisplayNameFromK8sResource(mockProject)).toBe('My Project'); | ||
}); | ||
|
||
it('uses the resource name if no display name is present', () => { | ||
const mockProject = mockProjectK8sResource({ | ||
k8sName: 'my-project', | ||
displayName: '', | ||
}); | ||
expect(getDisplayNameFromK8sResource(mockProject)).toBe('my-project'); | ||
}); | ||
}); | ||
|
||
describe('getDescriptionFromK8sResource', () => { | ||
it('gets the description', () => { | ||
const mockProject = mockProjectK8sResource({ description: 'This is a test project' }); | ||
expect(getDescriptionFromK8sResource(mockProject)).toBe('This is a test project'); | ||
}); | ||
|
||
it('returns empty string if no description', () => { | ||
const mockProject = mockProjectK8sResource({ description: '' }); | ||
expect(getDescriptionFromK8sResource(mockProject)).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('translateDisplayNameForK8s', () => { | ||
it('translates a string into a valid k8s name', () => { | ||
expect(translateDisplayNameForK8s('Test Project 1')).toBe('test-project-1'); | ||
expect(translateDisplayNameForK8s("John Doe's Cool Project!")).toBe('john-does-cool-project'); | ||
expect(translateDisplayNameForK8s('$ymbols & Capitals and Spaces! (These are invalid!)')).toBe( | ||
'ymbols--capitals-and-spaces-these-are-invalid', | ||
); | ||
}); | ||
}); | ||
|
||
describe('isValidK8sName', () => { | ||
it('identifies invalid names', () => { | ||
expect(isValidK8sName('')).toBe(false); | ||
expect(isValidK8sName('Test Project 1')).toBe(false); | ||
expect(isValidK8sName("John Doe's Cool Project!")).toBe(false); | ||
expect(isValidK8sName('$ymbols & Capitals and Spaces! (These are invalid!)')).toBe(false); | ||
}); | ||
|
||
it('identifies valid names', () => { | ||
expect(isValidK8sName(undefined)).toBe(true); | ||
expect(isValidK8sName('test-project-1')).toBe(true); | ||
expect(isValidK8sName('john-does-cool-project')).toBe(true); | ||
expect(isValidK8sName('ymbols--capitals-and-spaces-these-are-invalid')).toBe(true); | ||
}); | ||
}); |
This file contains 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,16 @@ | ||
import { K8sDSGResource } from '~/k8sTypes'; | ||
|
||
export const getDisplayNameFromK8sResource = (resource: K8sDSGResource): string => | ||
resource.metadata.annotations?.['openshift.io/display-name'] || resource.metadata.name; | ||
export const getDescriptionFromK8sResource = (resource: K8sDSGResource): string => | ||
resource.metadata.annotations?.['openshift.io/description'] || ''; | ||
|
||
export const translateDisplayNameForK8s = (name: string): string => | ||
name | ||
.trim() | ||
.toLowerCase() | ||
.replace(/\s/g, '-') | ||
.replace(/[^A-Za-z0-9-]/g, ''); | ||
|
||
export const isValidK8sName = (name?: string): boolean => | ||
name === undefined || (name.length > 0 && /^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/.test(name)); |
2 changes: 1 addition & 1 deletion
2
frontend/src/concepts/pipelines/content/DeletePipelineServerModal.tsx
This file contains 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 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 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 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 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 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 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 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.