mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
console: Only use json string editor for jsonb columns DSF-211
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8396 Co-authored-by: Julian <843342+okjulian@users.noreply.github.com> GitOrigin-RevId: bce8e6483bf163aecfdc54dfe23c91439dafaf59
This commit is contained in:
parent
bf5f5a0e30
commit
e501b60a82
@ -6,6 +6,7 @@ import { within } from '@testing-library/dom';
|
||||
import {
|
||||
fireEvent,
|
||||
userEvent,
|
||||
waitFor,
|
||||
waitForElementToBeRemoved,
|
||||
} from '@storybook/testing-library';
|
||||
import { expect } from '@storybook/jest';
|
||||
@ -16,6 +17,8 @@ import { usePermissionComparators } from '../hooks/usePermissionComparators';
|
||||
import { handlers } from './__tests__/fixtures/jsonb/handlers';
|
||||
import { ReactQueryDecorator } from '../../../../../../storybook/decorators/react-query';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useState } from 'react';
|
||||
import { Permissions } from './types';
|
||||
|
||||
export default {
|
||||
title: 'Features/Permissions/Form/Row Permissions Input',
|
||||
@ -611,7 +614,7 @@ export const JsonbColumns: ComponentStory<
|
||||
|
||||
JsonbColumns.play = async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
// Wait unti Loading is gone
|
||||
// Wait until Loading is gone
|
||||
await waitForElementToBeRemoved(() => canvas.getByText('Loading'), {
|
||||
timeout: 50000,
|
||||
});
|
||||
@ -645,3 +648,106 @@ export const JsonbColumnsHasKeys: ComponentStory<
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const StringColumns: ComponentStory<
|
||||
typeof RowPermissionsInput
|
||||
> = args => {
|
||||
const [permissions, setPermissions] = useState<Permissions>({
|
||||
name: { _eq: '' },
|
||||
});
|
||||
const tables = usePermissionTables({
|
||||
dataSourceName: 'default',
|
||||
});
|
||||
|
||||
const comparators = usePermissionComparators();
|
||||
|
||||
if (!tables || isEmpty(comparators)) return <>Loading</>;
|
||||
return (
|
||||
<>
|
||||
<RowPermissionsInput
|
||||
onPermissionsChange={p => {
|
||||
setPermissions(p);
|
||||
}}
|
||||
table={{ schema: 'public', name: 'Stuff' }}
|
||||
tables={tables}
|
||||
comparators={comparators}
|
||||
permissions={{ name: { _eq: '' } }}
|
||||
/>
|
||||
{/* State debugger. Used to test the current permissions value */}
|
||||
<div className="invisible" data-testid="permissions-state">
|
||||
{JSON.stringify(permissions)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
// Play function testing that string column with numbers inside are represented as text on the UI
|
||||
// Prevents regression where they were treated as numbers
|
||||
StringColumns.play = async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
// Wait until Loading is gone
|
||||
await waitForElementToBeRemoved(() => canvas.getByText('Loading'), {
|
||||
timeout: 50000,
|
||||
});
|
||||
|
||||
// // Write a number in the input
|
||||
await userEvent.type(canvas.getByTestId('name._eq-value-input'), '1337');
|
||||
|
||||
// Expect the input to have the number as text
|
||||
await waitFor(async () => {
|
||||
expect(await canvas.findByTestId('permissions-state')).toHaveTextContent(
|
||||
'{"name":{"_eq":"1337"}}'
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export const NumberColumns: ComponentStory<
|
||||
typeof RowPermissionsInput
|
||||
> = args => {
|
||||
const [permissions, setPermissions] = useState<Permissions>({
|
||||
id: { _eq: '' },
|
||||
});
|
||||
const tables = usePermissionTables({
|
||||
dataSourceName: 'default',
|
||||
});
|
||||
|
||||
const comparators = usePermissionComparators();
|
||||
|
||||
if (!tables || isEmpty(comparators)) return <>Loading</>;
|
||||
return (
|
||||
<>
|
||||
<RowPermissionsInput
|
||||
onPermissionsChange={p => {
|
||||
setPermissions(p);
|
||||
}}
|
||||
table={{ schema: 'public', name: 'Stuff' }}
|
||||
tables={tables}
|
||||
comparators={comparators}
|
||||
permissions={{ id: { _eq: '1234' } }}
|
||||
/>
|
||||
{/* State debugger. Used to test the current permissions value */}
|
||||
<div className="invisible" data-testid="permissions-state">
|
||||
{JSON.stringify(permissions)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
NumberColumns.play = async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
// Wait until Loading is gone
|
||||
await waitForElementToBeRemoved(() => canvas.getByText('Loading'), {
|
||||
timeout: 50000,
|
||||
});
|
||||
|
||||
// // Write a number in the input
|
||||
await userEvent.type(canvas.getByTestId('id._eq-value-input'), '1337');
|
||||
|
||||
// Expect the input to have the number as text
|
||||
// Note it's not a number but a string
|
||||
await waitFor(async () => {
|
||||
expect(await canvas.findByTestId('permissions-state')).toHaveTextContent(
|
||||
'{"id":{"_eq":"12341337"}}'
|
||||
);
|
||||
});
|
||||
};
|
||||
|
@ -31,8 +31,7 @@ export const ValueInputType = ({
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (operator?.inputStructure === 'object') {
|
||||
if (operator?.type === 'jsonb' && operator?.inputStructure === 'object') {
|
||||
return (
|
||||
<ObjectValueInput
|
||||
componentLevelId={componentLevelId}
|
||||
|
Loading…
Reference in New Issue
Block a user