Skip to content

Commit ec4bef2

Browse files
authored
Merge pull request #223 from devtron-labs/feat/lock-profiles
fix: add suffix support to resource and policy url getters
2 parents 7d6cc6f + 2003b9b commit ec4bef2

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
7575
tabSize = 2,
7676
lineDecorationsWidth = 0,
7777
height = 450,
78+
width = '100%',
7879
inline = false,
7980
shebang = '',
8081
onChange,
@@ -98,7 +99,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
9899

99100
const editorRef = useRef(null)
100101
const monacoRef = useRef(null)
101-
const { width, height: windowHeight } = useWindowSize()
102+
const { width: windowWidth, height: windowHeight } = useWindowSize()
102103
const memoisedReducer = React.useCallback(CodeEditorReducer, [])
103104
const [state, dispatch] = useReducer(memoisedReducer, initialState({mode, theme, value, diffView, noParsing}))
104105
const [, json, yamlCode, error] = useJsonYaml(state.code, tabSize, state.mode, !state.noParsing)
@@ -191,7 +192,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
191192
return
192193
}
193194
editorRef.current.layout()
194-
}, [width, windowHeight])
195+
}, [windowWidth, windowHeight])
195196

196197
useEffect(() => {
197198
if (onChange) {
@@ -267,7 +268,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
267268
}
268269

269270
return (
270-
<CodeEditorContext.Provider value={{ dispatch, state, handleLanguageChange, error, defaultValue, height }}>
271+
<CodeEditorContext.Provider value={{ dispatch, state, handleLanguageChange, error, defaultValue, height, width }}>
271272
{children}
272273
{loading ? (
273274
<CodeEditorPlaceholder customLoader={customLoader} />
@@ -286,7 +287,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
286287
theme={state.theme.toLowerCase().split(' ').join('-')}
287288
editorDidMount={editorDidMount}
288289
height={height}
289-
width="100%"
290+
width={width}
290291
/>
291292
) : (
292293
<MonacoEditor
@@ -297,7 +298,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
297298
onChange={handleOnChange}
298299
editorDidMount={editorDidMount}
299300
height={height}
300-
width="100%"
301+
width={width}
301302
/>
302303
)}
303304
</>

src/Common/CodeEditor/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface CodeEditorInterface {
3737
noParsing?: boolean
3838
inline?: boolean
3939
height?: number | string
40+
width?: number | string
4041
shebang?: string | JSX.Element
4142
diffView?: boolean
4243
loading?: boolean

src/Shared/Services/common.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import { getUrlWithSearchParams } from '../../Common'
1818
import { GetPolicyApiUrlProps, GetResourceApiUrlProps } from './types'
1919

20-
export const getResourceApiUrl = <T>({ baseUrl, kind, version, queryParams }: GetResourceApiUrlProps<T>) =>
21-
getUrlWithSearchParams(`${baseUrl}/${kind}/${version}`, queryParams)
20+
export const getResourceApiUrl = <T>({ baseUrl, kind, version, suffix, queryParams }: GetResourceApiUrlProps<T>) =>
21+
getUrlWithSearchParams(`${baseUrl}/${kind}/${version}${suffix ? `/${suffix}` : ''}`, queryParams)
2222

23-
export const getPolicyApiUrl = <T>({ kind, version, queryParams }: GetPolicyApiUrlProps<T>) =>
24-
getUrlWithSearchParams(`global/policy/${version}/${kind}`, queryParams)
23+
export const getPolicyApiUrl = <T>({ kind, version, queryParams, suffix }: GetPolicyApiUrlProps<T>) =>
24+
getUrlWithSearchParams(`global/policy/${kind}/${version}${suffix ? `/${suffix}` : ''}`, queryParams)

src/Shared/Services/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface BaseGetApiUrlProps<T, K extends ResourceKindType | PolicyKindType, P e
3535
baseUrl: string
3636
kind: K
3737
version: P
38+
suffix?: string
3839
queryParams?: T extends Parameters<typeof getUrlWithSearchParams>[1] ? T : never
3940
}
4041

0 commit comments

Comments
 (0)