Skip to content

Commit ded05da

Browse files
authored
feat(openfga): remove almost all DSL/JSON tabs with 1 exception (#1038)
1 parent b7fb31c commit ded05da

File tree

5 files changed

+28
-84
lines changed

5 files changed

+28
-84
lines changed

docs/content/configuration-language.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Please familiarize yourself with basic <ProductConcept /> and [How to get starte
3434
Below is a sample authorization model. The next sections discuss the basics of the <ProductName format={ProductNameFormat.ShortForm}/> configuration language.
3535

3636
<AuthzModelSnippetViewer
37+
syntaxesToShow={[SyntaxFormat.Dsl, SyntaxFormat.Json]}
3738
configuration={{
3839
schema_version: '1.1',
3940
type_definitions: [
@@ -978,7 +979,6 @@ relation {
978979
In the <ProductName format={ProductNameFormat.ShortForm}/> DSL, it becomes:
979980

980981
<AuthzModelSnippetViewer
981-
onlyShow={SyntaxFormat.Friendly2}
982982
configuration={{
983983
schema_version: '1.1',
984984
type_definitions: [
@@ -1042,7 +1042,7 @@ In the <ProductName format={ProductNameFormat.ShortForm}/> DSL, it becomes:
10421042
In the <ProductName format={ProductNameFormat.ShortForm}/> JSON, it becomes:
10431043

10441044
<AuthzModelSnippetViewer
1045-
onlyShow={SyntaxFormat.Api}
1045+
syntaxesToShow={[SyntaxFormat.Json]}
10461046
configuration={{
10471047
schema_version: '1.1',
10481048
type_definitions: [

docs/content/modeling/getting-started.mdx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ We will also need to add "User" to the list as it establishes the type of user w
331331
Now that we have a list of object types we can start defining them using the <UpdateProductNameInLinks link="../configuration-language" name="{ProductName} Configuration Language" />:
332332

333333
<AuthzModelSnippetViewer
334-
onlyShow={SyntaxFormat.Friendly2}
335334
configuration={{
336335
schema_version: '1.1',
337336
type_definitions: [
@@ -554,7 +553,6 @@ Relation names in <ProductName format={ProductNameFormat.ShortForm}/> are arbitr
554553
Remember _"How a user is added as a member to an organization is beyond the scope of this feature."_ For the purposes of this model the relation definition should be:
555554

556555
<AuthzModelSnippetViewer
557-
onlyShow={SyntaxFormat.Friendly2}
558556
configuration={{
559557
schema_version: '1.1',
560558
type_definitions: [
@@ -611,7 +609,6 @@ If you want to learn more, you can read further about this in [Modeling User Gro
611609
The complete <ProductConcept section="what-is-a-type-definition" linkName="type definition" /> for the **organization** type is:
612610

613611
<AuthzModelSnippetViewer
614-
onlyShow={SyntaxFormat.Friendly2}
615612
configuration={{
616613
schema_version: '1.1',
617614
type_definitions: [
@@ -659,7 +656,6 @@ When a document is created, a relationship tuple will be stored in <ProductName
659656
The relation definition then should be:
660657

661658
<AuthzModelSnippetViewer
662-
onlyShow={SyntaxFormat.Friendly2}
663659
configuration={{
664660
schema_version: '1.1',
665661
type_definitions: [
@@ -694,7 +690,6 @@ When a user shares a document with another user or set of users as editor, a rel
694690
The relation definition then should be:
695691

696692
<AuthzModelSnippetViewer
697-
onlyShow={SyntaxFormat.Friendly2}
698693
configuration={{
699694
schema_version: '1.1',
700695
type_definitions: [
@@ -739,7 +734,6 @@ You can learn more about this in [Modeling User Groups](./user-groups.mdx).
739734
The viewer relation is similar to the document's [editor relation](#relation-editor). It will be defined like this:
740735

741736
<AuthzModelSnippetViewer
742-
onlyShow={SyntaxFormat.Friendly2}
743737
configuration={{
744738
schema_version: '1.1',
745739
type_definitions: [
@@ -772,7 +766,6 @@ This relation is different from the others we have seen so far, as it is a relat
772766
When a document is created a relationship tuple will be stored in <ProductName format={ProductNameFormat.ShortForm}/> to represent this relationship between parent and document. The relation definition then should be:
773767

774768
<AuthzModelSnippetViewer
775-
onlyShow={SyntaxFormat.Friendly2}
776769
configuration={
777770
{
778771
type: 'document',
@@ -811,7 +804,6 @@ _A user can share a document with another user or an organization as either edit
811804
We can achieve that with the following definition using <UpdateProductNameInLinks link="../configuration-language" name="{ProductName} Configuration Language" />:
812805

813806
<AuthzModelSnippetViewer
814-
onlyShow={SyntaxFormat.Friendly2}
815807
skipVersion={true}
816808
configuration={
817809
{
@@ -870,7 +862,6 @@ _A user can view a document if they are an owner, viewer or editor of a document
870862
Similar to the [can_share relation](#relation-can_share), we can achieve that with the following definition using <UpdateProductNameInLinks link="../configuration-language" name="{ProductName} Configuration Language" />:
871863

872864
<AuthzModelSnippetViewer
873-
onlyShow={SyntaxFormat.Friendly2}
874865
skipVersion={true}
875866
configuration={{
876867
type: 'document',
@@ -937,7 +928,6 @@ _A user can write a document if they are an owner or editor of a document or if
937928
Similar to the [can_share relation](#relation-can_share), we can achieve that with the following definition using <UpdateProductNameInLinks link="../configuration-language" name="{ProductName} Configuration Language" />:
938929

939930
<AuthzModelSnippetViewer
940-
onlyShow={SyntaxFormat.Friendly2}
941931
skipVersion={true}
942932
configuration={{
943933
type: 'document',
@@ -986,7 +976,6 @@ _A user can change the owner of a document if they are an owner of the document.
986976
Similar to the [can_share relation](#relation-can_share), we can achieve that with the following definition using <UpdateProductNameInLinks link="../configuration-language" name="{ProductName} Configuration Language" />:
987977

988978
<AuthzModelSnippetViewer
989-
onlyShow={SyntaxFormat.Friendly2}
990979
skipVersion={true}
991980
configuration={{
992981
type: 'document',
@@ -1007,7 +996,6 @@ Similar to the [can_share relation](#relation-can_share), we can achieve that wi
1007996
The complete <ProductConcept section="what-is-a-type-definition" linkName="type definition" /> for the document type is:
1008997

1009998
<AuthzModelSnippetViewer
1010-
onlyShow={SyntaxFormat.Friendly2}
1011999
configuration={{
10121000
schema_version: '1.1',
10131001
type_definitions: [
@@ -1169,7 +1157,6 @@ The complete <ProductConcept section="what-is-a-type-definition" linkName="type
11691157
Combining the type definitions for document and organization, we have
11701158

11711159
<AuthzModelSnippetViewer
1172-
onlyShow={SyntaxFormat.Friendly2}
11731160
configuration={{
11741161
schema_version: '1.1',
11751162
type_definitions: [

src/components/Docs/AuthorizationModel/AuthzModelCodeBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type AuthzModelCodeBlockProps = {
1313
const AuthzModelCodeBlock: React.FC<AuthzModelCodeBlockProps> = ({ configuration, syntaxFormat, skipVersion }) => {
1414
return (
1515
<CodeBlock
16-
className={`language-${syntaxFormat === SyntaxFormat.Api ? 'json' : tools.PrismExtensions.LANGUAGE_NAME}`}
16+
className={`language-${syntaxFormat === SyntaxFormat.Json ? 'json' : tools.PrismExtensions.LANGUAGE_NAME}`}
1717
>
1818
{loadSyntax(configuration, syntaxFormat, skipVersion)}
1919
</CodeBlock>

src/components/Docs/AuthorizationModel/AuthzModelSnippetViewer.tsx

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,116 +8,73 @@ import Admonition from '@theme/Admonition';
88

99
import { SyntaxFormat, WriteAuthzModelViewer } from '@components/Docs';
1010
import { AuthzModelCodeBlock } from './AuthzModelCodeBlock';
11-
import { constants } from '@openfga/frontend-utils';
1211

1312
type AuthzModelSnippetViewerProps = {
1413
// Authorization Model in api syntax
1514
configuration: WriteAuthorizationModelRequest & Required<Pick<WriteAuthorizationModelRequest, 'schema_version'>>;
16-
// optional description
17-
description?: string;
18-
onlyShow?: SyntaxFormat;
1915
showWrite?: boolean;
16+
syntaxesToShow?: SyntaxFormat[];
2017
// do not display the model schema in DSL and JSON
2118
skipVersion?: boolean;
22-
// Display a roughly equivalent v1.0 schema
23-
showSchemaOneDotZero?: boolean;
2419
};
2520

2621
const BaseAuthzModelSnippetViewer: React.FC<AuthzModelSnippetViewerProps> = ({
27-
onlyShow,
22+
syntaxesToShow = [],
2823
configuration,
2924
skipVersion,
30-
showSchemaOneDotZero,
3125
}) => {
32-
if (onlyShow) {
33-
return (
34-
<AuthzModelCodeBlock
35-
configuration={{ ...configuration, id: '' }}
36-
syntaxFormat={onlyShow}
37-
skipVersion={skipVersion}
38-
/>
39-
);
40-
}
26+
const showTabs: boolean = Array.isArray(syntaxesToShow) && syntaxesToShow.length > 1;
4127

42-
if (!showSchemaOneDotZero) {
28+
if (showTabs) {
4329
return (
4430
<>
4531
<Tabs groupId="dsl">
46-
<TabItem value="dsl" label="DSL">
47-
<AuthzModelCodeBlock
48-
configuration={{ ...configuration, id: '' }}
49-
syntaxFormat={SyntaxFormat.Friendly2}
50-
skipVersion={skipVersion}
51-
/>
52-
</TabItem>
53-
<TabItem value="json" label="JSON">
54-
<AuthzModelCodeBlock
55-
configuration={{ ...configuration, id: '' }}
56-
syntaxFormat={SyntaxFormat.Api}
57-
skipVersion={skipVersion}
58-
/>
59-
</TabItem>
32+
{syntaxesToShow.map((syntax, index) => (
33+
<TabItem value={syntax} label={syntax.toUpperCase()} key={index}>
34+
<AuthzModelCodeBlock
35+
configuration={{ ...configuration, id: '' }}
36+
syntaxFormat={syntax}
37+
skipVersion={skipVersion}
38+
/>
39+
</TabItem>
40+
))}
6041
</Tabs>
6142
</>
6243
);
6344
}
6445

6546
return (
66-
<>
67-
<Tabs groupId="dsl">
68-
<TabItem value="dsl" label="DSL">
69-
<AuthzModelCodeBlock
70-
configuration={{ ...configuration, id: '' }}
71-
syntaxFormat={SyntaxFormat.Friendly2}
72-
skipVersion={skipVersion}
73-
/>
74-
</TabItem>
75-
<TabItem value="dsl-onedotzero" label="DSL (Version 1.0)">
76-
<AuthzModelCodeBlock
77-
configuration={{ ...configuration, schema_version: constants.enums.SchemaVersion.OneDotZero, id: '' }}
78-
syntaxFormat={SyntaxFormat.Friendly2}
79-
skipVersion={skipVersion}
80-
/>
81-
</TabItem>
82-
<TabItem value="json" label="JSON">
83-
<AuthzModelCodeBlock
84-
configuration={{ ...configuration, id: '' }}
85-
syntaxFormat={SyntaxFormat.Api}
86-
skipVersion={skipVersion}
87-
/>
88-
</TabItem>
89-
</Tabs>
90-
</>
47+
<AuthzModelCodeBlock
48+
configuration={{ ...configuration, id: '' }}
49+
syntaxFormat={syntaxesToShow[0] || SyntaxFormat.Dsl}
50+
skipVersion={skipVersion}
51+
/>
9152
);
9253
};
9354

9455
const AuthzModelSnippetViewer: React.FC<AuthzModelSnippetViewerProps> = ({
9556
configuration,
96-
onlyShow,
9757
showWrite,
9858
skipVersion,
99-
showSchemaOneDotZero,
59+
syntaxesToShow,
10060
}) => {
10161
return (
10262
<>
10363
<BaseAuthzModelSnippetViewer
64+
syntaxesToShow={syntaxesToShow}
10465
configuration={configuration}
10566
skipVersion={skipVersion}
106-
onlyShow={onlyShow}
107-
showSchemaOneDotZero={showSchemaOneDotZero}
10867
/>
10968
{showWrite ? (
11069
<details>
11170
<summary>Write the Authorization Model</summary>
112-
11371
<Admonition type="note">
11472
<div>The OpenFGA API only accepts an authorization model in the API&#39;s JSON syntax.</div>
11573
<div>
11674
To convert between the API Syntax and the friendly DSL, you can use the{' '}
11775
<Link href={'https://github.com/openfga/cli/'}>FGA CLI</Link>.
11876
</div>
11977
</Admonition>
120-
12178
<WriteAuthzModelViewer authorizationModel={{ ...configuration, id: '' }} skipSetup={true} />
12279
</details>
12380
) : undefined}

src/components/Docs/AuthorizationModel/SyntaxTransformer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import { constants } from '@openfga/frontend-utils';
77
const { SchemaVersion } = constants.enums;
88

99
export enum SyntaxFormat {
10-
Api = 'api',
11-
Friendly2 = 'friendly_v2',
10+
Json = 'json',
11+
Dsl = 'dsl',
1212
}
1313

1414
export const loadSyntax = (
1515
configuration: AuthorizationModel,
16-
format: SyntaxFormat = SyntaxFormat.Api,
16+
format: SyntaxFormat = SyntaxFormat.Json,
1717
skipVersion?: boolean,
1818
) => {
1919
let config = configuration;
2020
switch (format) {
21-
case SyntaxFormat.Friendly2:
21+
case SyntaxFormat.Dsl:
2222
if (!config.type_definitions && (config as unknown as TypeDefinition).type) {
2323
config = {
2424
schema_version: SchemaVersion.OneDotOne,
@@ -32,7 +32,7 @@ export const loadSyntax = (
3232
return skipVersion
3333
? transformer.transformJSONToDSL(config).replace('model\n schema 1.1\n', '')
3434
: transformer.transformJSONToDSL(config);
35-
case SyntaxFormat.Api:
35+
case SyntaxFormat.Json:
3636
default: {
3737
return skipVersion
3838
? JSON.stringify(config, null, ' ').replace(' "schema_version": "1.1",\n', '').replace(',\n "id": ""', '')

0 commit comments

Comments
 (0)