Skip to content

Commit

Permalink
Merge pull request #944 from factly/fix-942
Browse files Browse the repository at this point in the history
Check entity create permission in selector component while creating a…
  • Loading branch information
shreeharsha-factly authored Jun 20, 2024
2 parents e68adc3 + a854e10 commit b7137df
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions studio/src/components/Selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Select, Empty, Button } from 'antd';
import deepEqual from 'deep-equal';

import getUserPermission from '../../utils/getUserPermission';
function Selector({
invalidOptions = [],
setLoading = true,
Expand All @@ -16,6 +16,9 @@ function Selector({
style,
}) {
const entity = action.toLowerCase();
const spaces = useSelector(({ spaces }) => spaces);
const actions = getUserPermission({ resource: createEntity, action: 'create', spaces });

const selectorType = require(`../../actions/${entity}`);
const [entityCreatedFlag, setEntityCreatedFlag] = React.useState(false);
const [query, setQuery] = React.useState({
Expand Down Expand Up @@ -133,7 +136,7 @@ function Selector({
}
}}
notFoundContent={
query.q?.trim() && createEntity ? (
actions.includes('admin') || actions.includes('create') ? (
<Button
block
type="dashed"
Expand All @@ -152,12 +155,12 @@ function Selector({
>
Create a {createEntity} '{query.q}'
</Button>
) : createEntity ? (
) : (
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={`No ${entity} available. Type something to create new ${createEntity}`}
description="No results found"
/>
) : null
)
}
getPopupContainer={(trigger) => trigger.parentNode}
autoClearSearchValue={true}
Expand Down

0 comments on commit b7137df

Please sign in to comment.