MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / HeaderItem

Function HeaderItem

data-browser/src/components/Table.tsx:81–138  ·  view source on GitHub ↗
({ subject }: HeaderItemProps)

Source from the content-addressed store, hash-verified

79};
80
81function HeaderItem({ subject }: HeaderItemProps) {
82 const [sortBy, setSortBy] = useSubjectParam('sort_by');
83 const [sortDesc, setSortDesc] = useSubjectParam('sort_desc');
84 const property = useProperty(subject);
85
86 function handleToggleSort() {
87 if (sortBy == subject) {
88 if (sortDesc == 'true') {
89 setSortDesc(null);
90 } else {
91 setSortDesc('true');
92 }
93 } else {
94 setSortBy(subject);
95 }
96 }
97
98 const thisPropIsSorted = sortBy == subject;
99
100 let minWidth = '6rem';
101 switch (property.datatype) {
102 case Datatype.STRING:
103 case Datatype.RESOURCEARRAY:
104 minWidth = '15rem';
105 break;
106 case Datatype.MARKDOWN:
107 minWidth = '25rem';
108 break;
109 case Datatype.BOOLEAN:
110 case Datatype.INTEGER:
111 minWidth = '6rem';
112 break;
113 default:
114 break;
115 }
116
117 return (
118 <CellHeaderStyled style={{ minWidth }}>
119 <ResourceInline subject={subject} />{' '}
120 <Button
121 onClick={handleToggleSort}
122 subtle={!thisPropIsSorted}
123 icon
124 data-test={`sort-${subject}`}
125 >
126 {thisPropIsSorted ? (
127 sortDesc == 'true' ? (
128 <FaSortDown />
129 ) : (
130 <FaSortUp />
131 )
132 ) : (
133 <FaSort />
134 )}
135 </Button>
136 </CellHeaderStyled>
137 );
138}

Callers

nothing calls this directly

Calls 2

useSubjectParamFunction · 0.90
usePropertyFunction · 0.90

Tested by

no test coverage detected