Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"TITLE_APPS": "Apps - {{role}}",
"TITLE_DASHBOARD": "Dashboard - {{role}}",
"TITLE_POLICIES": "Policies",
"TITLE_POLICY": "Policy {{policyId}}",
"TITLE_POLICY": "Policy {{policyName}}",
"TITLE_SECRET": "Secret {{secretId}} - {{role}}",
"TITLE_SEALEDSECRET": "Sealed Secret {{secretId}} - {{role}}",
"TITLE_NETPOL": "Network Policy {{secretId}} - {{role}}",
Expand Down
9 changes: 7 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ function App() {
<PrivateRoute path='/create-team' component={Team} platformAdminRoute exact />
<PrivateRoute path='/netpols' component={Netpols} platformAdminRoute exact />
<PrivateRoute path='/policies' component={Policies} platformAdminRoute exact />
<PrivateRoute path='/policies/:policyId' component={Policy} platformAdminRoute exact />
<PrivateRoute
path='/policies/:policyName'
component={Policy}
platformAdminRoute
exact
/>
<PrivateRoute path='/catalogs/:teamId' component={Catalogs} exact />
<PrivateRoute path='/catalogs/:teamId/:catalogName' component={Catalog} exact />
<PrivateRoute
Expand Down Expand Up @@ -176,7 +181,7 @@ function App() {
<PrivateRoute exact path='/teams/:teamId/builds' component={Builds} />
<PrivateRoute path='/teams/:teamId/builds/:buildName' component={Build} exact />
<PrivateRoute path='/teams/:teamId/policies' component={Policies} exact />
<PrivateRoute path='/teams/:teamId/policies/:policyId' component={Policy} exact />
<PrivateRoute path='/teams/:teamId/policies/:policyName' component={Policy} exact />
<PrivateRoute path='/teams/:teamId/workloads' component={Workloads} exact />
<PrivateRoute path='/teams/:teamId/services' component={Services} exact />
<PrivateRoute path='/teams/:teamId/services/:serviceName' component={Service} exact />
Expand Down
12 changes: 6 additions & 6 deletions src/components/Policy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { GetPolicyApiResponse, GetSessionApiResponse } from 'redux/otomiApi'
import { Box, Button } from '@mui/material'
import Form from './rjsf/Form'

export const getPolicySchema = (policyId): any => {
const schema = cloneDeep(getSpec().components.schemas.Policies.properties[policyId])
export const getPolicySchema = (policyName): any => {
const schema = cloneDeep(getSpec().components.schemas.Policies.properties[policyName])
return schema
}

Expand All @@ -23,25 +23,25 @@ interface Props extends CrudProps {
policy?: GetPolicyApiResponse
onSubmit: (formData: any) => void
editPolicies: boolean
policyId?: string
policyName?: string
}

export default function ({ policy, teamId, onSubmit, editPolicies, policyId, ...other }: Props): React.ReactElement {
export default function ({ policy, teamId, onSubmit, editPolicies, policyName, ...other }: Props): React.ReactElement {
const { user } = useSession()
const [data, setData] = useState<GetPolicyApiResponse>(policy)
useEffect(() => {
setData(policy)
}, [policy])
// END HOOKS
const formData = cloneDeep(data)
const schema = getPolicySchema(policyId)
const schema = getPolicySchema(policyName)
const uiSchema = getPolicyUiSchema(user, teamId)
return (
<Box>
<Form
schema={schema}
uiSchema={uiSchema}
data={{ ...formData, id: policyId, name: policyId }}
data={{ ...formData, id: policyName, name: policyName }}
onChange={setData}
resourceType='Policy'
children
Expand Down
15 changes: 9 additions & 6 deletions src/pages/Policy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ import { GetPolicyApiResponse, useEditPolicyMutation, useGetPolicyQuery, useGetT

interface Params {
teamId: string
policyId?: string
policyName?: string
}

export default function ({
match: {
params: { teamId, policyId },
params: { teamId, policyName },
},
}: RouteComponentProps<Params>): React.ReactElement {
const {
user: { isPlatformAdmin },
} = useAuthzSession(teamId)
const [update, { isLoading: isLoadingUpdate, isSuccess: isSuccessUpdate }] = useEditPolicyMutation()
const { data, isLoading, isFetching, isError, refetch } = useGetPolicyQuery({ teamId, policyId }, { skip: !policyId })
const { data, isLoading, isFetching, isError, refetch } = useGetPolicyQuery(
{ teamId, policyName },
{ skip: !policyName },
)
const {
data: teams,
isLoading: isLoadingTeams,
Expand All @@ -45,7 +48,7 @@ export default function ({
if (!mutating && isSuccessUpdate) return <Redirect to={`/teams/${teamId}/policies`} />
const handleSubmit = (formData) => {
if (!editPolicies) return
if (policyId) update({ teamId, policyId, body: omit(formData, ['id', 'name']) as GetPolicyApiResponse })
if (policyName) update({ teamId, policyName, body: omit(formData, ['id', 'name']) as GetPolicyApiResponse })
}
const comp = teams && !isError && (
<Policy
Expand All @@ -54,8 +57,8 @@ export default function ({
policy={data}
teamId={teamId}
mutating={mutating}
policyId={policyId}
policyName={policyName}
/>
)
return <PaperLayout loading={loading} comp={comp} title={t('TITLE_BUILD', { policyId, role: 'team' })} />
return <PaperLayout loading={loading} comp={comp} title={t('TITLE_BUILD', { policyName, role: 'team' })} />
}
2 changes: 1 addition & 1 deletion src/redux/emptyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
const headers = []

const baseQuery = fetchBaseQuery({
baseUrl: '/api/v1/',
baseUrl: '/api/',
prepareHeaders: (h) => {
headers.map(([idx, val]: [string, string]) => h.set(idx, val))
return h
Expand Down
Loading