Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide stub properties in model explorer #1417

Merged
merged 1 commit into from
Apr 2, 2024
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
5 changes: 5 additions & 0 deletions docs/src/components/explorer/PropertyIndicator.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const CONTENTS = {
title: 'Hidden property',
text: 'This property should not be displayed in user interfaces.',
},
stub: {
icon: 'arrow-uturn-left',
title: 'Stub property',
text: 'When a property points to another schema, a stub property is added to the target schema for the reverse direction. Stub properties are read-only.',
},
};

const { type } = Astro.props;
Expand Down
59 changes: 46 additions & 13 deletions docs/src/components/explorer/SchemaProperties.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const isRequired = (property) =>
const isHidden = (property) => property.hidden;
const isInherited = (property) => property.schema.name !== schema.name;
const isDeprecated = (property) => property.deprecated;
const isStub = (property) => property.stub;

const properties = Array.from(schema.getProperties().values())
.sort((a, b) => a.name.localeCompare(b.name))
Expand All @@ -24,17 +25,24 @@ const properties = Array.from(schema.getProperties().values())
<style>
.SchemaProperties__header {
display: flex;
flex-wrap: wrap;
width: 100%;
align-items: center;
justify-content: space-between;
margin-bottom: var(--space-sm);
}

.SchemaProperties__toggles {
display: flex;
gap: var(--space-sm);
}

.SchemaProperties__schema {
opacity: 66%;
}

[data-show-inherited='false'] [data-is-inherited] {
[data-show-inherited='false'] [data-is-inherited]:not(:has(:target)),
[data-show-stubs='false'] [data-is-stub]:not(:has(:target)) {
display: none;
}

Expand Down Expand Up @@ -80,24 +88,48 @@ const properties = Array.from(schema.getProperties().values())
<script>
window.addEventListener('DOMContentLoaded', () => {
const container = document.querySelector('.SchemaProperties');
const toggle = document.querySelector('.SchemaProperties__toggle');
const toggles = document.querySelectorAll('.SchemaProperties__toggle');

for (const toggle of toggles) {
const setting = toggle.dataset.toggleSetting;

toggle.checked = true;
if (!setting) {
return;
}

toggle.addEventListener('change', () => {
container.dataset.showInherited = toggle.checked ? 'true' : 'false';
});
container.dataset[setting] = toggle.checked ? 'true' : 'false';

toggle.addEventListener('change', () => {
container.dataset[setting] = toggle.checked ? 'true' : 'false';
});
}
});
</script>

<section class="SchemaProperties" data-show-inherited="true" {...rest}>
<div class="SchemaProperties__header">
<h2 class="beta">Properties</h2>

<label>
<input type="checkbox" class="SchemaProperties__toggle" checked />
Show inherited
</label>
<h2 class="SchemaProperties__heading beta">Properties</h2>

<div class="SchemaProperties__toggles">
<label>
<input
type="checkbox"
class="SchemaProperties__toggle"
checked
data-toggle-setting="showInherited"
/>
Show inherited
</label>

<label>
<input
type="checkbox"
class="SchemaProperties__toggle"
data-toggle-setting="showStubs"
/>
Show stubs
</label>
</div>
</div>

<IndexTable>
Expand All @@ -109,7 +141,7 @@ const properties = Array.from(schema.getProperties().values())

{
properties.map((prop) => (
<tr data-is-inherited={isInherited(prop)}>
<tr data-is-inherited={isInherited(prop)} data-is-stub={isStub(prop)}>
<td>
<span
id={`property-${prop.name}`}
Expand All @@ -123,6 +155,7 @@ const properties = Array.from(schema.getProperties().values())
{isFeatured(prop) && <PropertyIndicator type="featured" />}
{isRequired(prop) && <PropertyIndicator type="required" />}
{isHidden(prop) && <PropertyIndicator type="hidden" />}
{isStub(prop) && <PropertyIndicator type="stub" />}
{isDeprecated(prop) && (
<DeprecatedIndicator message="This property is deprecated and will be removed in a future version of the FollowTheMoney model." />
)}
Expand Down
Loading