console: Support X-Hasura-User-Id for number inputs DSF-162

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8261
Co-authored-by: Julian <843342+okjulian@users.noreply.github.com>
GitOrigin-RevId: 118bdb9261f92f6829ea19633de660388ff7db82
This commit is contained in:
Julian@Hasura 2023-03-14 21:23:16 -03:00 committed by hasura-bot
parent cd18fd0762
commit 472fc45239
4 changed files with 56 additions and 16 deletions

View File

@ -345,6 +345,49 @@ BooleanArrayTypeRoot.play = async ({ canvasElement }) => {
).toBeInTheDocument(); ).toBeInTheDocument();
}; };
export const NumericValue: ComponentStory<
typeof RowPermissionsInput
> = args => (
<RowPermissionsInput
onPermissionsChange={action('onPermissionsChange')}
table={['Album']}
tables={tables}
comparators={comparators}
permissions={{ id: { _eq: '' } }}
/>
);
NumericValue.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
expect(
canvas.getByTestId('id._eq-value-input-x-hasura-user-id')
).toBeInTheDocument();
};
export const NumericIntValue: ComponentStory<
typeof RowPermissionsInput
> = args => (
<RowPermissionsInput
onPermissionsChange={action('onPermissionsChange')}
table={['Album']}
tables={tables}
comparators={comparators}
permissions={{ id: { _eq: 0 } }}
/>
);
export const NumericFloatValue: ComponentStory<
typeof RowPermissionsInput
> = args => (
<RowPermissionsInput
onPermissionsChange={action('onPermissionsChange')}
table={['Album']}
tables={tables}
comparators={comparators}
permissions={{ id: { _eq: 0.9 } }}
/>
);
SetRootLevelPermission.play = async ({ canvasElement }) => { SetRootLevelPermission.play = async ({ canvasElement }) => {
const canvas = within(canvasElement); const canvas = within(canvasElement);
await userEvent.click(canvas.getByTestId('-operator')); await userEvent.click(canvas.getByTestId('-operator'));

View File

@ -70,15 +70,17 @@ export const ValueInput = ({ value, path }: { value: any; path: string[] }) => {
value={value} value={value}
comparatorType={comparator?.type} comparatorType={comparator?.type}
/> />
{inputType === 'text' && isComparator(comparatorName) && ( {(inputType === 'text' || inputType === 'number') &&
<Button isComparator(comparatorName) && (
disabled={comparatorName === '_where' && isEmpty(table)} <Button
onClick={() => setValue(path, 'X-Hasura-User-Id')} disabled={comparatorName === '_where' && isEmpty(table)}
mode="default" onClick={() => setValue(path, 'X-Hasura-User-Id')}
> data-testid={`${componentLevelId}-x-hasura-user-id`}
[x-hasura-user-id] mode="default"
</Button> >
)} [x-hasura-user-id]
</Button>
)}
</> </>
); );
}; };

View File

@ -23,9 +23,6 @@ export const ValueInputType = ({
const { setValue } = useContext(rowPermissionsContext); const { setValue } = useContext(rowPermissionsContext);
const { table } = useContext(tableContext); const { table } = useContext(tableContext);
const inputType =
jsType === 'boolean' ? 'checkbox' : jsType === 'string' ? 'text' : 'number';
switch (jsType) { switch (jsType) {
case 'boolean': case 'boolean':
return ( return (
@ -55,7 +52,7 @@ export const ValueInputType = ({
data-testid={componentLevelId} data-testid={componentLevelId}
disabled={comparatorName === '_where' && isEmpty(table)} disabled={comparatorName === '_where' && isEmpty(table)}
className="border border-gray-200 rounded-md p-2 !mr-4" className="border border-gray-200 rounded-md p-2 !mr-4"
type={inputType} type="text"
value={value} value={value}
onChange={e => { onChange={e => {
setValue(path, graphQLTypeToJsType(e.target.value, comparatorType)); setValue(path, graphQLTypeToJsType(e.target.value, comparatorType));

View File

@ -120,9 +120,7 @@ export function graphQLTypeToJsType(
if (!isScalarType(type)) { if (!isScalarType(type)) {
return value; return value;
} }
if (type.name === 'Int' || type.name === 'ID' || type.name === 'Float') { if (type.name === 'Boolean') {
return Number(value);
} else if (type.name === 'Boolean') {
return Boolean(value); return Boolean(value);
} }